I have created a customized-jasmin-allure-reporter.js class where I wrote the report configuration methods similar like jasime2Allure reporter module except some minor changes. Now I would like to include this file into protractor configuration.js file from where I want to generate custome allure report using this. But unfortunately I found error all the time Error: Error: Cannot find module 'customized-jasmin-allure-reporter'.
MyCustomized class is
var Allure = require('allure-js-commons');
var path = require('path');
var allure = new Allure();
function CustomizedJasminAllureReporter(userDefinedConfig, allureReporter) {
var Status = {PASSED: 'passed', FAILED: 'failed', BROKEN: 'broken', PENDING: 'pending'};
this.allure = allureReporter || allure;
..................
}
exports.allureReporter = allure;
exports.CustomizedJasminAllureReporter =CustomizedJasminAllureReporter;
My Protractor configuration file is
exports.config = {
troubleshoot: true, // for protractor
allScriptsTimeout: 1500000,
restartBrowserBetweenTests: false,
specs: [
'./e2e/tests/**/*.e2e-spec.ts',
],
capabilities:
{
'browserName' : 'chrome',
'chromeOptions': { 'args' : ['--disable-extensions']},
'shardTestFiles': true,
'maxInstances': 1,
'unexpectedAlertBehaviour' : 'dismiss'
},
..............
onPrepare: function() {
var AllureReporter = require('customized-jasmin-allure-reporter');
// get the browser name
var capsPromise = browser.getCapabilities();
capsPromise.then(function(caps) {
console.log(caps);
var browserName = caps.get('browserName');
var browserVersion = caps.get('version');
browser.browserNameforSpec = browserName + "-" + browserVersion + "-";
console.log(browser.browserNameforSpec);
});
browser.manage().window().maximize();
require('ts-node').register({
project: 'e2e/tsconfig.json'
});
jasmine.getEnv().addReporter(new AllureReporter({
resultsDir: 'allure-results'
}));
jasmine.getEnv().addReporter(reporter);
jasmine.getEnv().afterEach(function (done) {
browser.takeScreenshot().then(function (png) {
allure.createAttachment('Screenshot', function () {
return new Buffer(png, 'base64')
},'image/png')();
done();
})
});
}
};
Your custom reporter is not imported properly.
`var AllureReporter = require('./src/...');` //Provide relative or absolute path of your report file.
Related
Can Some give an elaborate example of using Custom Jasmine Reporter . I would like someone to help me with a sample test with two assertions . how to add the reporter in protractor conf.js and how it can help me . No where in the internet there is a example apart from just the reference .
check the one I use:
First check if all the necessary dependencies are installed (check the begin of the code)
Then copy+paste this to you Conf.js:
//In my case I installed the dependencies locally thats why comes from lib folder
var jasmineReporters = require('./lib/node_modules/jasmine-reporters');
var HTMLReport = require('./lib/node_modules/protractor-html-reporter-2');
var fs = require('./lib/node_modules/fs-extra');
onPrepare: function () {
fs.emptyDir('./Execution_Results/reports/xml/', function (err) {
if (err != ""){
console.log(err);
}
});
fs.emptyDir('./Execution_Results/reports/results/screenshots', function (err) {
if (err != ""){
console.log(err);
}
});
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: './Execution_Results/reports/xml/',
filePrefix: 'xmlresults'
}));
jasmine.getEnv().addReporter({
specDone: function (result) {
//if (result.status == 'failed') {
browser.getCapabilities().then(function (caps)
{
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream('./Execution_Results/reports/results/screenshots/' + browserName + '-' + result.fullName + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
});
});
//}
}
});
},
//HTMLReport called once tests are finished
onComplete: function() {
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function (caps) {
browserName = caps.get('browserName');
browserVersion = caps.get('version');
platform = caps.get('platform');
testConfig = {
reportTitle: 'Protractor Test Execution Report',
outputPath: './',
outputFilename: 'Execution_Results/reports/results/IV2_Test_Results',
screenshotPath: './screenshots/',
testBrowser: browserName,
browserVersion: browserVersion,
modifiedSuiteName: false,
screenshotsOnlyOnFailure: true,
testPlatform: platform
};
new HTMLReport().from('./Execution_Results/reports/xml/xmlresults.xml', testConfig);
});
},
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
// If true, display spec names.
isVerbose: true,
},
the folders will be created automatically inside the folder where your conf.js is located so after the execution just access the 'Execution_Results/reports' and open the html report
OnPrepare will generate the xml file with all the results
OnComplete will transform the xml into html report
I'm using this reporter, Just follow the steps from this link to set the conf.js https://www.npmjs.com/package/protractor-jasmine2-screenshot-reporter
(I'm not using jQuery) Hi! I'm starting with protractor and cucumber and i'm testing a login page.
I'm trying to insert values on a form for the login, but when i lunch the configuration file to lunch the test, Chrome open the login page but don't displays the values that i setted for the required fields.
Clicking on sumbit button, the page should be redirect to another. Can anyone help me? How i have to change my step definition file to make it works? Thank you
I think that there are some problems like in configuration and others.
Here is step definition:
This is my new step definition file:
Given("I'm on site login page", function () {
//return pending;
browser.driver.get('https://www.websiteurl.com/login.html');
browser.sleep(20000);
});
When('I see the submit-button', function () {
// Write code here that turns the phrase above into concrete actions
//var sumbit = browser.executeScript('document.getElementById("submit-//wrap.cf.input-formFields")');
var sumbit = element(by.css('.submit-wrap.cf.input-formFields'));
expect(sumbit).to.not.be.null;
});
When('I filled all the mandatory fields', function () {
// Write code here that turns the phrase above into concrete actions
window.onload = function(){
var bookingNumberField = browser.executeScript('document.getElementById("variation2-bookingNumber").getText()');
var firstNameField = browser.executeScript('document.getElementById("variation2-firstName").getText()');
var lastNameField = browser.executeScript('document.getElementById("variation2-lastNameField").getText()');
var dobMonth = browser.executeScript('document.getElementById("month").getText()');
var dobDay = browser.executeScript('document.getElementById("day").getText()');
var dobYear = browser.executeScript('document.getElementById("year").getText()');
// var firstNameField = document.getElementById("variation2-firstName");
// var lastNameField = document.getElementById("variation2-lastName");
// var dobMonth = document.getElementById("month");
// var dobDay = document.getElementById("day");
// var dobYear = document.getElementById("year");
browser.sleep(1000);
//browser.waitForAngular();
//browser.executeScript to cut eventually
browser.executeScript.bookingNumberField.clear().sendKeys('WJXMHH');
browser.executeScript.firstNameField.clear().sendKeys('Mark');
browser.executeScript.lastNameField.clear().sendKeys('Altria');
element(by.cssContainingText('option', 'March')).click();
element(by.cssContainingText('option', '10')).click();
element(by.cssContainingText('option', '1991')).click();
TermsChkbxLabel = element(by.css("label[for='checkboxb']"));
TermsChkbxLabel.click();
}
}); //loginBtn.click();
Then('I am able to click on it to login', function () {
// var ptor = protractor.getInstance();
// ptor.ignoreSynchronization = true;
// var login_b = browser.executeScript('document.getElementById("login-button").click()');
//var login_b = document.getElementsByClassName("login-button").click();
// ptor.sleep(10000);
// var expectedUrl = ptor.getCurrentUrl();
// //expect(expectedUrl).toEqual('https://www.websiteurl.com/newpage.html');
});
Then('I am able to open the new page', function () {
var login_b = element(by.css('.login-button'));
login_b.click();
// var ptor = protractor.getInstance();
// ptor.ignoreSynchronization = true;
// var login_b = document.getElementsByClassName("login-button").click();
// ptor.sleep(10000);
// var expectedUrl = ptor.getCurrentUrl();
//
});
Here is the protractor conf.js:
var seleniumServer = require('selenium-server')
var nightwatchCucumber = require('nightwatch-cucumber')
require('babel-core/register');
var nightwatchCucumberConf = {
runner: 'nightwatch',
featureFiles: 'features',
stepDefinitions: 'features/step_definitions/testing_1_6.js',
closeSession: 'afterFeature'
};
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
plugins: [{
path: require.resolve('protractor-console'),
logLevels: ['severe']
}],
directConnect: true, //chrome only
jasmineNodeOpts: {},
onPrepare: function() {},
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to this directory.
specs: [
'features/*.feature'
],
baseURL: 'https://www.websiteurl.com/login.html',
cucumberOpts: {
//require: 'features/step_definitions/**/*.js',
require: 'features/step_definitions/testing_1_6.js',
tags: false,
// format: 'pretty',
profile: false,
'no-source': true
}
};
I have this error too:
[12:57:27] E/launcher - Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are 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"
[12:57:27] E/launcher - Error: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are 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.
Step definition file testing_1_6.js:
// chai is an assertion library
var chai = require('chai');
// chai-as-promised is an helper to handle promise
var chaiAsPromised = require('chai-as-promised')
chai.use(chaiAsPromised);
expect = chai.expect;
Given("I'm on site login page", function() {
browser.driver.get('https://www.websiteurl.com/login.html');
return browser.sleep(20000);
});
When('I see the submit-button', function() {
var sumbitBtn = element(by.css('.submit-wrap.cf.input-formFields'));
return expect(sumbitBtn.isDisplayed()).to.eventually.be.true;
});
When('I filled all the mandatory fields', function() {
element(by.id('variation2-bookingNumber')).sendKeys('WJXMHH');
element(by.id('variation2-firstName')).sendKeys('Mark');
element(by.id('variation2-lastNameField')).sendKeys('Altria')
element(by.cssContainingText('#month > option', 'March')).click();
element(by.cssContainingText('#day > option', '10')).click();
element(by.cssContainingText('#year > option', '1991')).click();
return element(by.css("label[for='checkboxb']")).click();
});
Then('I am able to click on it to login', function() {
return element(by.id('login-button')).click();
});
Then('I am able to open the new page', function() {
var newPageUrl = 'https://www.websiteurl.com/newpage.html';
browser.sleep(10000);
return expect(browser.getCurrentUrl()).to.eventually.equal(newPageUrl);
});
protractor conf.js:
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
plugins: [{
path: require.resolve('protractor-console'),
logLevels: ['severe']
}],
directConnect: true, //chrome only
onPrepare: function() {
browser.ignoreSynchronization = true;
},
capabilities: {
browserName: 'chrome'
},
specs: [
'features/*.feature'
],
cucumberOpts: {
require: [
'features/step_definitions/testing_1_6.js'
]
}
};
browser.waitForAngularEnabled(false);
I am using protractor cucumber framework for my test automation. For logging i am using 'Winston'. I have multiple feature files. I want to keep log files in the name of feature file for better tracking.
As of now i hard coded file name as shown below in 'filename' property [filename: 'c:\QAAutomation\info.log'].
Is there any option in Winston to assign dynamic file name ?
var winston = require('winston');
require('winston-daily-rotate-file');
var moment = require('moment-timezone');
winston.emitErrs = true;
var logger = new winston.Logger({
transports: [
new winston.transports.DailyRotateFile({
level: 'info',
name: 'info-file',
filename: 'c:\\QAAutomation\\info.log',
handleExceptions: true,
json: false,
prepend: true,
datePattern: 'yyyyMMdd',
maxsize: 5242880, //5MB
maxFiles: 60,
colorize: false,
formatter: customFileFormatter,
timestamp: function() {
return moment().format("MM-DD-YYYY HH:mm:ss.SSS");
}
})
],
exitOnError: false
});
module.exports = logger;
module.exports.stream = {
write: function(message, encoding) {
logger.verbose(message);
}
};
function customFileFormatter(options) {
// Return string will be passed to logger.
return `{"timestamp": "${options.timestamp()}", "level": "${options.level}", "message": "${(options.message ? options.message : '')
+ (options.meta && Object.keys(options.meta).length ? '\n\t' + JSON.stringify(options.meta) : '')}"}`;
}
I have the following gulp task which inserts .css and .js files in the html file:
gulp.task('inject', function () {
log('Injecting the JS and CSS files into index.html');
var wiredep = require('wiredep').stream;
var options = config.getWiredepDefaultOptions();
return gulp.src(config.index)
.pipe(wiredep(options))
.pipe($.inject(gulp.src(config.customFiles), {ignorePath: options.ignorePath}))
.pipe(gulp.dest(config.client));
});
and my gulp.config.js:
module.exports = function () {
var client = './public';
var config = {
allJS: [
'*.js',
'public/js/*.js',
'public/js/**/*.js'
],
client: client,
index: client + '/index.html',
customFiles: [
'./public/css/*.css',
'./public/js/*.js',
'./public/js/**/*.js'
],
bower: {
json: require('./bower.json'),
directory: './public/lib',
ignorePath: '/public/'
},
};
config.getWiredepDefaultOptions = function () {
var options = {
bowerJson: config.bower.json,
directory: config.bower.directory,
ignorePath: config.bower.ignorePath
};
return options;
};
return config;
};
This works as expected, but when I run the task I get this:
It always says gulp-inject 3 files into index.html, even though no new files was added.
Is there something wrong with my gulp file?
Well if you are using gulp-inject this is what I found.
If you look at the code in gulp-inject you can see it just spits out the file count unless it gets opt.quiet set. I didn't see a option in the docs for this setting but if you look at the tests it shows an example it being used.
Enabling quiet mode link line 505
inject(sources, {quiet: true});
Source where it generates the log statement. link line 109
function getNewContent(target, collection, opt) {
var logger = opt.quiet ? noop : function (filesCount) {
if (filesCount) {
log(cyan(filesCount) + ' files into ' + magenta(target.relative) + '.');
} else {
log('Nothing to inject into ' + magenta(target.relative) + '.');
}
};
var q = require("q");
var FirefoxProfile = require("firefox-profile");
var makeFirefoxProfile = function(preferenceMap) {
var deferred = q.defer();
var firefoxProfile = new FirefoxProfile();
for (var key in preferenceMap) {
firefoxProfile.setPreference(key, preferenceMap[key]);
};
firefoxProfile.encoded(function (encodedProfile) {
var capabilities = {
browserName: "firefox",
directConnect: true,
firefox_profile: encodedProfile
};
deferred.resolve(capabilities);
});
return deferred.promise;
};
exports.config = {
specs:specs,
getMultiCapabilities: function() {
return q.all([
makeFirefoxProfile(
{
"browser.download.folderList": 2,
"browser.download.dir": "/path/to/save/downloads",
"browser.helperApps.neverAsk.saveToDisk": "application/zip"
}
)
]);
},
// ...
}
It throws the following error:
ERROR - failed loading configuration file protractor.conf.js
/usr/local/lib/node_modules/protractor/lib/configParser.js:183
throw e;
^ Error: Cannot find module 'q'
Please share your views to solve this issue.
You need to have q and firefox-profile modules installed:
npm install q firefox-profile --save-dev