Set up Protractor tests with Jenkins - jenkins

I need to get my protractor tests to run using Jenkins. I know this has been asked before, and this seems like a really good answer. But I'm confused about where the bash script comes from and how to move forward. Here's what I've got:
Protractor config file:
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
require('jasmine-reporters');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine2',
suites: {...},
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 10000
},
onPrepare: function() {
global.isAngularSite = function(flag) {
browser.ignoreSynchronization = !flag;
};
browser.manage().window().setPosition(0,0);
browser.manage().window().setSize(1280, 1024);
}
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('protractor_output', true, true)
);
}
How can I get my tests to run with Jenkins? Please help

Related

Headless Cypress in docker container resolution always 1280x1024

When I run my tests in the official docker container (image cypress/included:7.5.0) the browser is always just 1280x1024.
When running the same config, same spec etc on host, I get desired 1920x1080.
My cypress.json:
{
"viewportHeight": 1080,
"viewportWidth": 1920,
"chromeWebSecurity": false,
"baseUrl": "http://phoenix:4000",
"watchForFileChanges": false,
"requestTimeout": 40000,
"defaultCommandTimeout": 40000,
"pageLoadTimeout": 80000,
"video": false,
"env": {
"codeCoverage": {
"url": "http://phoenix:4000/__coverage__",
"expectBackendCoverageOnly": false
}
}
In addition, I added some config like it you can find it explained here: https://docs.cypress.io/api/plugins/browser-launch-api#See-all-Chrome-browser-switches
My plugin/index.js:
module.exports = (on, config) => {
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome' && browser.isHeadless) {
launchOptions.args.push('--window-size=1920,1080');
launchOptions.args.push('--force-device-scale-factor=1');
launchOptions.args.push('--start-fullscreen');
}
return launchOptions;
});
require('#cypress/code-coverage/task')(on, config);
return config;
};
Why do I still get 1280x1024 resolution when running from within docker container (./node_modules/.bin/cypress run --browser chrome)?
I got it, I need to start my own Xvfb server first:
Xvfb -screen 0 1920x1080x24 :99 & export DISPLAY=:99 && ./node_modules/.bin/cypress run --browser chrome && pkill Xvfb
Source: https://docs.cypress.io/guides/continuous-integration/introduction#Xvfb

Run a long-running command and do a background check in the meanwhile - in Jenkins pipeline

I need to run a long-running command and interrupt it if some background check fails.
More specifically: tail aws logs while the task is running - and stop after the task finished.
My current approach is:
while(checkRunning(task)) {
sh("timeout 10 ${command} || true")
}
where:
command:
awslogs get ...
checkRunning:
aws ecs describe-tasks ... -query 'tasks[0].lastStatus'
But this creates small fragments from the whole output.
Is there a better way to do this?
e.g. parallel steps and interrupting one from the other
UPDATE: Now I see two possibilities:
1. implement in bash or other shell
2. create a custom wrapper (e.g. checking this: https://github.com/jenkinsci/pipeline-aws-plugin/blob/master/src/main/java/de/taimos/pipeline/aws/WithAWSStep.java)
I also tried with implementing a groovy lib to do the job:
* Usage:
* <pre><code>
* doUntil task: {
* sh 'awslogs get ...'
* }, until: {
* runMyCheck()
* }
*
* #params params [task: {}, until: {}]
*/
def call (params) {
parallel ( "main": {(params.task)()},
"background": {
timeout(60) {
waitUntil {
sleep 10
if( (params.until)() ) error "Stopping background check"
}
}
},
failFast: true
)
}
...which should work but behaves weirdly

How to re-write a Jenkins DSL file as a Jenkins pipeline jenkinsfile?

I have the following Jenkins DSL file:
if (params["BUILD_SNAPSHOT"] == "true") {
parallel(
{
build("company-main-build-snapshot")
},
{
build("1-company-worker-build-snaphsot", WORKER_NAME: "sharding-worker")
}
)
}
parallel (
{
build("company-deployment-info",
API_KEY: "aaaaa5dd4cd58b94215f9cddd4441c391b4ddde226ede98",
APP: "company-Staging-App")
},
{
build("company-salt-role-deploy",
ENV: "staging",
ROLE: "app")
},
{
build("company-deployment-info",
API_KEY: "aaaaa5dd4cd58b94215f9cddd4441c391b4ddde226ede98",
APP: "company-Staging-Shardwork")
},
{
build("company-salt-workers-deploy",
ENVIRONMENT: "staging",
WORKER_TYPE: "shardwork")
}
)
if (params["REST_TEST"] == "true") {
build("company_STAGING_python_rest_test")
}
My task is to convert/rewrite this workflow file content to Jenkins pipeline Jenkinsfile.
I have some example files for reference but I'm having a hard time understanding how I should even begin...
Can anyone please shed some light on this subject?
First, have a good look at Jenkins pipeline documentation, it is a great start and it is providing a whole bunch of information such as Build Parameters usage or parallel steps.
Here are a few more hints for you to explore :
Parameters
Just use the parameter name as a variable such as :
if (BUILD_SNAPSHOT) {
...
}
Call other jobs
You can also use build step such as :
build job: '1-company-worker-build-snaphsot', parameters: [stringParam(name: 'WORKER_NAME', value: "sharding-worker")]
Use functions
Instead of calling downstream jobs using build steps each time, you might want to consider using pipeline functions from another Groovy script, either from your current project or even from an external, checked out Groovy script.
As an example, you could replace your second job call from :
build("1-company-worker-build-snaphsot", WORKER_NAME: "sharding-worker")
to :
git 'http://urlToYourGit/projectContainingYourScript'
pipeline = load 'global-functions.groovy'
pipeline.buildSnapshot("sharding-worker")
...of course the init phase (Git checkout and pipeline loading) is only needed once before you can call all your external scripts functions.
In short
To sum it up a little bit, your code could be converted to something along these lines :
node {
git 'http://urlToYourGit/projectContainingYourScript'
pipeline = load 'global-functions.groovy'
if(BUILD_SNAPSHOT) {
parallel (
phase1: { pipeline.buildMainSnapshot() },
phase2: { pipeline.buildWorkerSnapshot("sharding-worker") }
)
}
parallel (
phase1: { pipeline.phase1(params...) },
phase2: { pipeline.phase2(params...) },
phase3: { pipeline.phase3(params...) },
phase4: { pipeline.phase4(params...) }
)
if (REST_TEST) {
pipeline.finalStep()
}
}

Running protractor on Jenkins doesn't fail the build when there is an error

I have set up Jenkins Slave on Windows VM. when there are failures in my tests , the build status always shows succeeded.
Here is how I run protractor tests on jenkins
Windows PowerShell command :
cd conf
protractor ConfProd.js
My Conf file:
var HtmlReporter = require('protractor-html-screenshot-reporter');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub', //desktop
allScriptsTimeout: 60000,
baseUrl: 'https://myTest.com',
params: {
empUrl: 'https://employeeurl.com/',
},
// frameworks to use
frameworks: 'jasmine2',
directConnect: 'true',
//Capabilities to be passed to the webdriver instance.
multiCapabilities: [{
'browserName': 'chrome',
'chromeOptions' : {
args: ['--window-size=1200,1200']
},
specs: [
'../tests/*.spec.js'
],
},
{
'browserName': 'firefox',
'firefoxOptions' : {
args: ['--window-size=900,900']
},
specs: [
'../tests/*.spec.js'
],
exclude: ['../tests/EmployeeTests.spec.js'],
}],
onPrepare: function () {
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: '/tmp/screenshots',
docTitle: 'TestReports',
takeScreenShotsOnlyForFailedSpecs: true
}));
},
jasmineNodeOpts: {
showColors: true,
isVerbose: true,
includeStackTrace: true,
}
};
This is the message from console output on Jenkins:
[launcher] chrome #1 failed 4 test(s)
[launcher] firefox #2 failed 4 test(s)
[launcher] overall: 8 failed spec(s)
Checking for post-build
Performing post-build step
Checking if email needs to be generated
No emails were triggered.
Finished: SUCCESS

Protractor tests hung up after finishing tests

I have configured grunt tasks to start the protractor webdriver and then run the protractor tests with protractor-runner, grunt config is like
.....
protractor_webdriver: {
start: {
options: {
path: 'node_modules/protractor/bin/',
command: 'webdriver-manager start --standalone'
}
}
},
protractor: {
options: {
configFile: proctatorConf,
noColor: false,
args: {
}
},
auto: {
options: {
keepAlive: true,
args: {
}
}
},
singlerun: {
options: {
keepAlive: false,
args: {
}
}
}
}
....
grunt.registerTask('test:e2e', [
'shell:update_webdriver',
'protractor_webdriver:start',
'protractor:singlerun'
]);
and in Jenkins i installed xvfb-plugin and said on the job configuration to startup Xvfb screen and shutdown after job finish,
And what is the problem is that when jenkins execute grunt test:e2e command, it executes all test, give me failure information like
Finished in 16.455 seconds
[31m4 tests, 6 assertions, 4 failures
and jenkins job hungs on that, what could be the problem for this?

Resources