Error while using "Protractor jasmine 2 screen shot reporter" - node.js

I am trying to take the "Screen shot" of the web page when the "test case fails".
I installed "protractor-jasmine2-screenshot-reporter" using "npm".
I am using below data.
1.Node -- v6.11.4
2.NPM -- 3.10.10
3.Protractor -- 5.1.2
My "Protractor.conf.js" file code below.
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: 'C:/Users/agudla/Desktop/VSCodeWorkSpace/my-app/screenshots',
filename: 'my-report.html'
});
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
multiCapabilities: [{
'browserName': 'chrome',
'seleniumAddress':'http://localhost:4444/wd/hub'
},
{'browserName': 'firefox',
'marionette': 'false',
'seleniumAddress':'http://localhost:4444/wd/hub'
}
],
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
beforeLaunch: function() {
return new Promise(function(resolve){
reporter.beforeLaunch(resolve);
});
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(reporter);
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
I am getting below error message while running the test script.
ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444
Can any one help me to solve this issue.

It is working now , i run "Selenium server" and i changed the var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter'); as
var Jasmine2HtmlReporter = require('C:/Users/agudla/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
Should have to provide complete "path" for the "protractor jasmine2 html reporter".
To know the "protractor jasmine2 html reporter" path in your system , type below command in command prompt.
npm link protractor-jasmine2-html-reporter
It will print the complete path .

Related

protractor-jasmine2-screenshot-reporter not generating screenshots in the required folder

My protractor.conf.js has the following content. I was unable to find out whats wrong here. I have manually created target/screenshots in my root folder of angular-cli. When i run protractor conf.js the protractor tests in browser window but the screenshots aren't being generated. Can anyone help me resolve this?
// Protractor configuration file
const { SpecReporter } = require('jasmine-spec-reporter');
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var fs = require('fs');
var reporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'my-report.html',
cleanDestination: false,
showSummary: true,
showConfiguration: false,
reportTitle: null,
ignoreSkippedSpecs: false,
captureOnlyFailedSpecs: false,
reportOnlyFailedSpecs: false
});
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: false,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
chromeOnly: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(reporter);
},
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
Thanks in Advance!
You can check by adding the 'protractor-screenshoter-plugin'
plugins: [{
package: 'protractor-screenshoter-plugin',
screenshotPath: <specify the path>,
screenshotOnExpect: 'failure',
screenshotOnSpec: 'failure+success',
withLogs: 'true',
writeReportFreq: 'asap',
imageToAscii: 'failure',
htmlReport:'true',
verbose:'info',
clearFoldersBeforeTest: true,
failTestOnErrorLog: {
failTestOnErrorLogLevel: 900
}
},
Can also check https://www.npmjs.com/package/protractor-screenshoter-plugin
protractor-jasmine2-screenshot-reporter compatible with jasmine2, so change to framework: 'jasmine2' in your conf.js
And you need to use higher version of Protractor which includes jasmine2
I did a quick test with your conf(did little changes) and it worked.
conf.js
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
// var fs = require('fs');
var reporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'my-report.html',
cleanDestination: false,
showSummary: true,
showConfiguration: false,
reportTitle: null,
ignoreSkippedSpecs: false,
captureOnlyFailedSpecs: false,
reportOnlyFailedSpecs: false
});
exports.config = {
allScriptsTimeout: 11000,
// specs: [
// './e2e/**/*.e2e-spec.ts'
// ],
capabilities: {
'browserName': 'chrome'
},
directConnect: false,
// baseUrl: 'http://localhost:4200/',
framework: 'jasmine2',
// chromeOnly: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
jasmine.getEnv().addReporter(reporter);
},
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
spec.js
describe('xxx', function(){
it('yyy', function(){
browser.get('https://angular.io/');
});
});
target/screenshots folder and HTML report,
(I run for twice, so there are two screenshots.)
click the yyy will open the screenshot
protractor-jasmine2-screenshot-reporter will create target/screenshots folder if not exist, no need to create in advance.
Version I used:
protractor 5.3.0
protractor-jasmine2-screenshot-reporter 0.5.0

Error cannot find the specified path while executing protractor

Hi I have write a nodejs application that contains some tests written in jasmine.I am trying to get the test results published in TFS using CLI.
I have installed the following packages
"jasmine-spec-reporter": "^4.1.1",
"jasmine-tfs-reporter": "^1.0.0",
"phantomjs-prebuilt": "^2.1.14",
"ts-node": "^3.2.0"
Following is the protractor.conf
/*global jasmine */
var SpecReporter = require('jasmine-spec-reporter');
var TfsReporter = require('jasmine-tfs-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/tests/*spec.js'
],
capabilities: {
'browserName': 'phantomjs',
'phantomjs.binary.path': require('phantomjs-prebuilt').path,
'phantomjs.ghostdriver.cli.args': ['--loglevel=DEBUG']
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
useAllAngular2AppRoots: false,
beforeLaunch: function() {
require('ts-node').register({
project: 'PartyAndIndustryDataMigration'
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(new SpecReporter());
jasmine.getEnv().addReporter(new TfsReporter());
}
};
When i try and execute protractor from the command prompt i get error
the specified path does not exist PartyAndIndustryDataMigration
It was a minor fix. It had to just correct the path
useAllAngular2AppRoots: false,
beforeLaunch: function() {
require('ts-node').register({
project: '../PartyAndIndustryDataMigration'
});
},

Reports 'protractor-jasmine2-screenshot-reporter' and 'jasmine-reporters' in a single config file but Jasmine2-Screenshot reporter not working

Below is the config file which contains both 'protractor-jasmine2-screenshot-reporter' and 'jasmine-reporter'
It works fine individually but if i combine both the protractor-jasmine2-screenshot-reporter' is not working ,is it because i have two 'onPrepare' functions
var HtmlScreenshotReporter = require('C:/Protractor_Scripts/node_modules/protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: 'C:/Protractor_Scripts/Screenshots',
filename: 'Report.html'
});
exports.config = {
directConnect: false,
multiCapabilities: [
{'browserName': 'chrome'},
{'browserName': 'firefox'}
],
allScriptsTimeout: 1200000,
framework: 'jasmine2',
specs: ['C:/Protractor_Scripts/Protractor/Driver/Driver.js'],
// Setup the report before any tests start
beforeLaunch: function() {
return new Promise(function(resolve){
reporter.beforeLaunch(resolve);
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
},
Jasmine Reporter which is used to generate xml reports
onPrepare: function() {
var jasmineReporters = require('C:/Protractor_Scripts/node_modules/jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'C:/Protractor_Scripts/Results',
filePrefix: 'xmloutput'
}));
},
// ----- Options to be passed to minijasminenode -----
jasmineNodeOpts: {
// onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: false,
// 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: 1200000
}
};
Don't define two onPrepare functions, put everything into a single one:
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
var jasmineReporters = require('C:/Protractor_Scripts/node_modules/jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'C:/Protractor_Scripts/Results',
filePrefix: 'xmloutput'
}));
},

Protractor + RequireJS

Please, show me how to use Protractor with RequireJS.
code works
var dentalConfig = require('./conf/dentalConfig.js');
var login = require('./pages/login.js');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: dentalConfig.baseUrl,
specs: [
'pages/company.js'
],
onPrepare: function () {
login();
}
};
but if i put exports.config inside of requirejs()
protractor throw error:
c:\Users\UserName\AppData\Roaming\npm\node_modules\protractor\lib\configParser.js:184
fileConfig.configDir = path.dirname(filePath);
TypeError: Cannot set property 'configDir' of undefined.
this doesn't work
var requirejs = require('requirejs');
requirejs.config({
baseUrl: './',
nodeRequire: require
});
requirejs([
'conf/dentalConfig',
'pages/login'
],
function (dentalConfig, login) {
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: dentalConfig.baseUrl,
specs: [
'pages/company.js'
],
onPrepare: function () {
login();
}
};
}
);
Your config file should look something like this..
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect: true,
framework: 'jasmine',
specs: ['TestScript name that has to be executed.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose:true,
includeStackTrace:true
},
capabilities: {
'browserName': 'chrome',
},
}

angular-phonecat tutorial: protractor.js unexpected behavior under Chrome Canary

I’m setting things up in order to run the angular-phonecat tutorial using Chrome Canary under OS X as a testing browser.
I got everything working, except when I input npm run protractor the e2e test runs on SAFARI of all browsers, despite the fact that I’ve specified Chrome Canary as the browser name in the protractor-conf.js file. Here’s the code:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/*.js'
],
capabilities: {
'browserName': 'ChromeCanary',
'ChromeOptions': {
'binary': '/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary'
}
},
chromeOnly: false,
baseUrl: 'http://localhost:8000/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
When I set chromeOnly: true, the test returns an ELIFECYCLE error. I find this very awkward since the same browser name is specified in the Karma configuration file and the unit test runs on Canary as expected. Here’s the karma.conf.js code:
module.exports = function(config){
config.set({
basePath : '../',
files : [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-resource/angular-resource.js',
'app/bower_components/angular-animate/angular-animate.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/js/**/*.js',
'test/unit/**/*.js'
],
autoWatch : true,
frameworks: ['jasmine'],
browsers : ['ChromeCanary'],
plugins : [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine'
],
junitReporter : {
outputFile: 'test_out/unit.xml',
suite: 'unit'
}
});
};
Two questions:
What could be causing this behavior?
What else could I tinker with to get the e2e test to run on Canary?
I was able to get this working with Chrome Canary by simply reusing the Chrome browserName but providing an alternate binary path. Here's the snippet that will work for your example above.
capabilities: {
'browserName': 'Chrome',
'ChromeOptions': {
'binary': '/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary'
}
Probably easier to abstract this into a separate browsers.js file so you can use both canary and chrome like this.
exports.chrome = {
name: 'Chrome',
browserName: 'chrome',
chromeOptions: {
'args': [
'incognito',
'disable-extensions',
'start-maximized',
'enable-crash-reporter-for-testing'
]
}
};
exports.chromeCanary = {
name: 'ChromeCanary',
browserName: 'chrome',
chromeOptions: {
'binary': 'C:/Users/gattridg/AppData/Local/Google/Chrome SxS/Application/chrome.exe',
'args': [
'incognito',
'disable-extensions',
'start-maximized',
'enable-crash-reporter-for-testing'
]
}
};
Then in your protractor.conf.js
var browsers = require('./browsers'),
multiCapabilities: [
browsers.chrome
browsers.chromeCanary
],

Resources