I created a Jenkins job to run Protractor tests at midnight.
For headless testing, I'm using PhantomJS browser because I can't install Xvfb (don't have the rights).
I'm running the Protractor tests through a Grunt task.
On my local machine (windows), the grunt job works fine, and the tests pass.
On the server, I'm getting
Failed: waiting for page to load for 10000ms
...
Failed: Error while waiting for Protractor to sync with the page: "window.angular is undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"
My protractor-headless.conf:
exports.config = {
directConnect: false,
capabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': require('phantomjs').path,
'phantomjs.cli.args': []
},
seleniumServerJar: require('selenium-server-standalone-jar').path,
framework: 'jasmine2',
specs: [
'./e2e/**/**.spec.js'
],
allScriptsTimeout: 30000,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 200000,
isVerbose: true//,
//includeStackTrace : false
},
onPrepare: function() {
'use strict';
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'test-results',
filePrefix: 'xmloutput'
}));
}
};
And the Grunt Job:
protractor: {
options: {
configFile: 'src/test/javascript/protractor.conf.js',
keepAlive: true,
noColor: false,
verbose: true,
args: {
// Arguments passed to the command
}
},
headless: {
options: {
keepAlive: false,
configFile: 'src/test/javascript/protractor-headless.conf.js'
}
}
}
...
grunt.registerTask('e2e-test-headless', [
'protractor:headless'
]);
The test have access to the testing environment.
Any idea what can be the problem?
Related
As Angular team plans to stop development of Protractor soon, I am looking for alternatives for our protractor test suite. As we don't really use a lot of protractor specific stuff, i just looking to remove the wrapper around webdriver, and just use webdriverjs instead. Any suggestions for a test runner that i can use to run the protractor config file, which looks something like this.
var { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 40000,
specs: [
'./src/tests/*/*.e2e-spec.ts',
],
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
args: ['--headless', '--disable-gpu', '--window-size=2880,2000', '--no-sandbox', '--test-type=browser', '--disable-dev-shm-usage'],
// args: ['--no-sandbox', '--test-type=browser', '--window-size=2880,1800'],
// Set download path and avoid prompting for download even though
// this is already the default on Chrome but for completeness
prefs: {
'download': {
'prompt_for_download': false,
'directory_upgrade': true,
'default_directory': 'C:\\downloadtemp'
}
}
}
},
directConnect: true,
// Used for running against development server baseUrl: 'http://localhost:4200/',
// Used for running against an env - replaced now as jenkins job specifies the baseUrl as part of protractor command
framework: 'jasmine',
//to run the e2e tests,from the app root run the command ng e2e
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 240000,
print: function () {
}
},
onPrepare: function () {
//browser.driver.manage().window().maximize();
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.e2e.json')
});
//clear down the previous test run downloads
var fs = require('fs');
function rmDir(dirPath) {
try {
var files = fs.readdirSync(dirPath);
} catch (e) {
return;
}
if (files.length > 0)
for (var i = 0; i < files.length; i++) {
var filePath = dirPath + '/' + files[i];
if (fs.statSync(filePath).isFile())
fs.unlinkSync(filePath);
else rmDir(filePath);
}
fs.rmdirSync(dirPath);
}
rmDir('C:\\downloadtemp');
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: 'none' } }));
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'testresults/xmltestresults',
filePrefix: 'xmloutput'
}));
var HtmlReporter = require('protractor-beautiful-reporter');
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'testresults/htmltestreport',
takeScreenShotsOnlyForFailedSpecs: true,
gatherBrowserLogs: true,
docTitle: 'Freecon Test Report',
preserveDirectory: false,
}).getJasmine2Reporter());
}
};
My tests are passing reliably without shardTestFiles, but with shardTestFiles true I am getting intermittent in different places. The error message is the following:
Failed: Error while waiting for Protractor to sync with the page: "Cannot read property '$$testability' of undefined"
This is from my config file:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs : ['tests/e2e/**/*.js'],
rootElement: 'body#rootElement',
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstances:11
},
allScriptsTimeout: 500000,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 500000,
isVerbose: true
}
};
How do I get my reliable tests to run reliably with shardTestFiles on?
I have tried this in my config file*
var reporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'my-report.html'
});
exports.config = {
directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['Enter-description-in-resources-spec.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 1100000
}
onPrepare: function() {
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: '/tmp/screenshots'
}));
}
};
but I got a error and I'm unable to understand it
throw new exitCodes_1.ConfigError(logger, 'failed loading configuration file ' + filename);
You are missing a comma after JasmineNodeOpts, please correct and pass your reporter in onPrepare function:
var reporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'my-report.html'
});
exports.config = {
directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['Enter-description-in-resources-spec.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 1100000
},
onPrepare: function() {
jasmine.getEnv().addReporter(reporter); // Pass the reporter here which you have defined earlier.
}
};
I am writing e2e test cases for my Angular application using protractor.I am trying to generate HTML Reports and multiuser testing. This is my
conf.js :
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter=new HtmlReporter({
baseDirectory: '/test/e2e/JasmineReporter', // a location to store screen shots.
docTitle: 'Report',
docName: 'protractor-demo-tests-report.html'
});
exports.config = {
seleniumAddress: 'http://localhost:4441/wd/hub',
multiCapabilities: [{
browserName: 'chrome',
acceptSslCerts: true,
trustAllSSLCertificates: true,
specs: ['first_spec.js']
}, {
browserName: 'chrome',
acceptSslCerts: true,
trustAllSSLCertificates: true,
specs: ['second_spec.js']
}],
maxSessions: 1, //Limits max number of instances
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
},
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 50000
}
};
Now, it is working fine. It is generating HTML Reports for two specs.
But when I limit the instances using maxSessions: 1 (It opens one browser at a time). It is generating report for last spec. And what is the max number of instances we can run.
I'm trying to get my config file to the point where I don't have to go to the mac terminal and type webdriver-manager start. Is it possible to have the config file do that? I have listed my code below to give you idea what I have set up. I just don't know if it is possible. Let me know. I am on a macbook pro.
exports.config = {
seleniumServerJar: './selenium/selenium-server-standalone-2.45.1.jar',
seleniumPort: null,
chromeDriver: './selenium/chromedriver.exe',
chromeDriver: null,
seleniumAddress: 'http://localhost:4444/wd/hub',
// ----- What tests to run -----
suites: {
CSRSmokeTest: '../smoke/deskTop/CSR.js'
DesktopSmokeTest: '../smoke/deskTop/**.js'
},
chromeOnly: false,
multiCapabilities: [
{
'browserName': 'chrome',
'chromeOptions': {
args: ['--lang=en',
'--window-size=1900,1200']
}
},
],
baseUrl: location + '/login/#/login',
rootElement: 'body',
onPrepare: function () {
browser.ignoreSynchronization = true;
browser.get(location + '/login/#/login');
},
params: {
user: {
//TEST******************************************
},
url: {
//some code
}
},
jasmineNodeOpts: {
// onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: true,
// If true, print colors to the terminal.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 6000000
}
};
If you just do not want to type in terminal you have several options:
Leave only seleniumServerJar option, and remove seleniumAddress. But starting Selenium everytime takes additionally 5-20 sec (depending on the hardware).
Use directConnect: true for Chrome. And then you do not need Selenium server at all. It works for me, but it is not fully portable solution.
Install Selenium somewhere on your server and leave it running forever. In this case your application should have publically accessible URL, so not just localhost.