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.
}
};
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());
}
};
I'm trying to mock the backend so that I can write some e2e tests.
I searched online but I can't figure out what i'm doing wrong.
I get this error on the first line of my code:
angular is not defined.
My protractor config file is:
exports.config = {
specs: ['tests/e2e/*.js'],
baseUrl: "http://localhost:8100/#/",
framework: 'jasmine',
allScriptsTimeout: 5000000,
capabilities: {
'browserName': 'chrome'
},
onPrepare: function () {
browser.driver.get(browser.baseUrl);
var SpecReporter = require('jasmine-spec-reporter');
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'}));
},
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 300000,
includeStackTrace: true,
print: function () {
}
}
};
and the very start of my e2e test is:
'use strict';
describe('Page', function() {
var BY, test;
BY = by;
test = angular.module('hgApp', ['ionic', 'ngMockE2E']);
return test.run(function($httpBackend) {
return console.log($httpBackend);
});
});
What am I doing wrong?
Thanks for any help
EDIT
I also added browser.waitForAngular() before trying to do beforeEach module but still nothing, same error as before
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?
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 keep trying to run some E2E tests out of ToT angular-seed master and keep getting the following error when I run ./scripts/e2e-test.sh:
TypeError: Property 'browser' of object #<Object> is not a function
I get this error when trying to run the following piece of code as one of my e2e scenario:
'use strict';
/* https://github.com/angular/protractor/blob/master/docs/getting-started.md */
describe('MyApp', function() {
describe(Index', function() {
beforeEach(function() {
browser().navigateTo('/');
});
it('should render feature specific image', function() {
expect(element('img.featurette-image').length).toBe('4');
});
});
});
I'm wondering if my protractor config is incorrect:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'../test/e2e/*.js'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:3000/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
My unit tests are running just fine. This is the Karma config I have for them (note that this is an angular app within the public director of a sinatra application listening on port 3000:
module.exports = function(config){
config.set({
basePath : '../',
files : [
'https://code.jquery.com/jquery-1.10.2.min.js',
'app/lib/angular/angular.js',
'app/lib/angular/angular-*.js',
'test/lib/angular/angular-mocks.js',
'app/js/**/*.js',
'test/unit/**/*.js'
],
exclude : [
'app/lib/angular/angular-loader.js',
'app/lib/angular/*.min.js',
'app/lib/angular/angular-scenario.js'
],
autoWatch : true,
frameworks: ['jasmine'],
browsers : ['Chrome'],
plugins : [
'karma-junit-reporter',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine'
],
junitReporter : {
outputFile: 'test_out/unit.xml',
suite: 'unit'
}
})}
Thanks for the help!
You need to change this line:
browser().navigateTo('/');
to
browser.navigateTo('/');
That's it.