Protractor config file have 2 reporting custom report for logging and other one is protractor-
jasmine2-screenshot-reporter. Screenshot png is generate but blank white screen only dispalyed.
Below code for conf.js.
let HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
let DateFormat = require('../utils/date-format').DateFormat;
let ReportGenerator = require('../utils/customReport').ReportGenerator;
let reportGenerator = new ReportGenerator({
dest: '/../reports/',
filename: 'CoHubReport',
reportTitle: 'CoHub Automation Suite',
cssPath: './../utils/reportUtil/customReport-styles.css',
jsPath: './../utils/reportUtil/reportUtil.js'
});
let reporter = new HtmlScreenshotReporter({
showConfiguration: false,
captureOnlyFailedSpecs: false,
takeScreenshots: true,
userCss: './../../utils/report-styles.css',
dest: './../reports',
filename: 'CoHub_Report_' + DateFormat(new Date(), "yyyymmdd") + '.html',
reportTitle: "Co Hub Report :" + DateFormat(new Date(), "mm-dd-yyyy HH:MM"),
cleanDestination: false,
consolidateAll: false
});
exports.config = {
directConnect: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
// sauceUser: "0000",
// sauceKey: "00000",
restartBrowserBetweenTests: true,
getPageTimeout: 80000,
allScriptsTimeout: 50000000,
specs: [
'./pagecheck/settings/configavo-spec.js',
// './pagecheck/ant/antent-spec.js',
],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 50000000,
isVerbose: true
},
multiCapabilities: [
{
browserName: 'chrome',
version: 'latest',
platform: 'Windows 10',
name: "chrome-tests",
shardTestFiles: true,
sequential: true,
maxInstances: 3
}
],
framework: 'jasmine2',
beforeLaunch: function () {
return new Promise(function (resolve) {
reporter.beforeLaunch(resolve);
});
},
onPrepare: function () {
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(reporter);
beforeEach(function () {
reportGenerator.initiate();
});
afterEach(function () {
reportGenerator.finalize();
});
},
afterLaunch: function (exitCode) {
return new Promise(function (resolve) {
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
Also, can require screenshot to be attached to html report. we have limitation to use other reporting within the project, please dont recommend other reporting to use.
try
exports.config {
...
noGlobals: false,
...
}
Setting it to false allow to use default globals: 'protractor', 'browser', '$', '$$', 'element', 'by'. These also exist as properties of the protractor namespace: 'protractor.browser', 'protractor.$', 'protractor.$$', 'protractor.element', 'protractor.by', and 'protractor.By'.
When no globals is set to true, the only available global variable will be 'protractor' link
Related
For some reason I cannot start my tests written using WebdriverIO together with Mocha + Chai testing frameworks. When I run yarn start command to start them I get such an output with every test:
Execution of 31 spec files started at 2021-07-22T13:36:42.326Z
[0-0] RUNNING in chrome - C:\Users\ADOMAS-PC\Desktop\Automation Projects\driveweb\test\e2e\specs\e2e\cancelDownload.spec.js
[0-0] Error: Failed to create session.
Unable to create session from {
"desiredCapabilities": {
"browserName": "chrome",
"goog:chromeOptions": {
"binary": "C:\u002f\u002fProgram Files\u002f\u002fGoogle\u002f\u002fChrome\u002f\u002fApplication\u002f\u002fchrome.exe",
"prefs": {
"directory_upgrade": true,
"prompt_for_download": false,
"download.default_directory": "C:\\Users\\ADOMAS-PC\\Desktop\\Automation Projects\\driveweb\\test\\data\\downloads",
"download.prompt_for_download": false,
"profile.default_content_setting_values.automatic_downloads": 1
},
"args": [
"--headless",
"--no-sandbox",
"--incognito",
"--disable-gpu",
"--window-size=1600,1000"
]
}
},
"capabilities": {
"firstMatch": [
{
"browserName": "chrome",
"goog:chromeOptions": {
"binary": "C:\u002f\u002fProgram Files\u002f\u002fGoogle\u002f\u002fChrome\u002f\u002fApplication\u002f\u002fchrome.exe",
"prefs": {
"directory_upgrade": true,
"prompt_for_download": false,
"download.default_directory": "C:\\Users\\ADOMAS-PC\\Desktop\\Automation Projects\\driveweb\\test\\data\\downloads",
"download.prompt_for_download": false,
"profile.default_content_setting_values.automatic_downloads": 1
},
"args": [
"--headless",
"--no-sandbox",
"--incognito",
"--disable-gpu",
"--window-size=1600,1000"
]
}
}
]
}
}
Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:58:47'
System info: host: 'DESKTOP-AK6OAUH', ip: '10.18.0.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.1'
Driver info: driver.version: unknown
This is how wdio.webapp.conf.js looks like:
const { createDir, removeDirContents } = require('./test/e2e/helpers/folderHelper');
const { populateData } = require('./test/e2e/helpers/apiHelper');
const { TimelineService } = require('wdio-timeline-reporter/timeline-service');
var mkdirp = require('mkdirp');
const path = require('path');
global.downloadDir = path.join(process.cwd(), 'test/data/downloads');
global.uploadDir = path.join(process.cwd(), 'test/data/uploads');
global.uploadPermDir = path.join(process.cwd(), 'test/data/uploadsPerm');
global.baseUrl = 'https://drive.automation.com/';
exports.config = {
hostname: 'automation-selenium',
port: 4444,
path: '/wd/hub',
specs: [
'./test/e2e/specs/e2e/**/*.spec.js',
'./test/e2e/specs/pages/*.spec.js'
],
maxInstances: 1,
capabilities: [
{
maxInstances: 1,
browserName: 'chrome',
'goog:chromeOptions': {
binary: "C://Program Files//Google//Chrome//Application//chrome.exe",
prefs: {
directory_upgrade: true,
prompt_for_download: false,
'download.default_directory': global.downloadDir,
'download.prompt_for_download': false,
'profile.default_content_setting_values.automatic_downloads': 1
},
args: [
'--headless',
'--no-sandbox',
'--incognito',
'--disable-gpu',
'--window-size=1600,1000']
}
}
],
logLevel: 'debug',
outputDir: './reports/output',
bail: 0,
baseUrl: global.baseUrl,
waitforTimeout: 50000,
connectionRetryTimeout: 60000,
connectionRetryCount: 3,
framework: 'mocha',
mochaOpts: {
ui: 'bdd',
compilers: ['js:#babel/register'],
timeout: 60000,
retries: 1
},
reporters: [
'spec',
[
'allure',
{
outputDir: './reports/allure-results/',
disableWebdriverStepsReporting: true,
disableWebdriverScreenshotsReporting: false
}
]
],
onPrepare: async function(config, capabilities) {
global.baseUrl = config.baseUrl;
createDir(global.downloadDir);
createDir(global.uploadDir);
if (!global.baseUrl.includes('automation.com')) {
await populateData(config.baseUrl);
}
},
afterTest: async function (test, context, { error, result, duration, passed, retries }) {
if (!passed) {
const current_datetime = new Date();
const time = current_datetime.getHours() + "h-" + current_datetime.getMinutes() + "m-" + current_datetime.getSeconds() + "s";
const screenshotDir = path.join(process.cwd(), `screenshots`);
await mkdirp(screenshotDir);
const filename = test.title.replace(/\s+/g, '-');
const screenshotImg = `${screenshotDir}/${time}-${filename}.png`;
browser.saveScreenshot(screenshotImg);
}
},
onComplete: function() {
removeDirContents(global.downloadDir);
removeDirContents(global.uploadDir);
}
};
What I already tried?
Reinstalling chrome browser on my PC.
Installing/reinstalling various libraries like wdio, selenium-standalone and etc.
Run tests from CMD using administrator mode.
Setting binary value to C://Program Files//Google//Chrome//Application//chromedriver.exe
Downgrading node to 12.8.1 version
What else can I try to make them work?
yarn add #wdio/selenium-standalone-service
was a solution to this problem.
I've been trying to update my conf.js file to download files, it should work for firefox and chrome (independent of one another).
I've been following the guides and answers online, (including but not limited to stackoverflow) yet it doesn't fully work for me. Chrome is no problem, firefox is my trouble maker.
On firefox it simply does not download the file, unlike chrome where it downloads the file.
Update: I cannot disable popup from firefox
The relevant info from conf.js
exports.config = {
[...]
multiCapabilities: [
{
browserName: 'chrome',
'goog:chromeOptions': {
w3c: false, // problems with latest chrome driver... browser.actions is causing issues: https://github.com/jan-molak/serenity-js/issues/329
prefs: {
download: {
prompt_for_download: false,
directory_upgrade: true,
default_directory: downloadsPath,
},
},
},
} ,
{
browserName: 'firefox',
'goog:chromeOptions': {
marionette: true,
'moz:firefoxOptions': {
prefs: {
'pdfjs.disabled': true,
'browser.download.folderList': 2,
'browser.download.dir': downloadsPath,
'browser.download.panel.shown': false,
'browser.download.useDownloadDir': true,
'browser.download.manager.useWindow': false,
'browser.helperApps.alwaysAsk.force': false,
'browser.helperApps.neverAsk.openFile': true,
'browser.download.manager.closeWhenDone': false,
'browser.download.manager.alertOnEXEOpen': false,
'browser.download.manager.showWhenStarting': false,
'browser.download.manager.focusWhenStarting': false,
'browser.download.manager.showAlertOnComplete': false,
'browser.helperApps.neverAsk.saveToDisk': 'application/vnd.openxmlformats',
},
},
},
},
],
[...]
};
The relevant code from my dowload-e2e.js spec:
const downloadBtn = manipulations.getDomObject('download-contract-button', 'id');
browser.executeScript('arguments[0].click();', downloadBtn.getWebElement());
try {
await downloads.verifyFileExists(`file-name.docx`);
await downloads.verifyFileSize(`file-name.docx`, 0);
} catch (err) {
throw new Error(`ERROR: ${err.message}`);
}
downloads.removeFile(`file-name.docx`);
Firefox/Chrome try like this:
const multiCapabilities = [
{
browserName: 'chrome',
'goog:chromeOptions': {
w3c: false, // due problems with latest chrome driver
// browser.actions is causing issues: https://github.com/jan-molak/serenity-js/issues/329
prefs: {
download: {
'prompt_for_download': false,
'directory_upgrade': true,
'default_directory': downloadsPath
}
}
}
},
{
browserName: 'firefox',
'goog:chromeOptions': {
marionette: true,
'moz:firefoxOptions': {
prefs: {
'browser.download.folderList': 2,
'browser.download.dir': downloadsPath,
'browser.download.manager.showWhenStarting': false,
'browser.helperApps.alwaysAsk.force': false,
'browser.download.manager.useWindow': false,
'browser.helperApps.neverAsk.saveToDisk': 'application/octet-stream, application/json, ' +
'text/comma-separated-values, text/csv, application/csv, ' +
'application/excel, application/vnd.ms-excel, ' +
'application/vnd.msexcel, text/anytext, text/plaintext, ' +
'image/png, image/pjpeg, image/jpeg, application/zip'
}
}
}
}
];
I'm using cucumber-reporting on jenkins https://github.com/damianszczepanik/cucumber-reporting. I'm running parallel tests with different browsers. How can my report show which browser failed? Can I somehow add in tags like #firefox, #ie, #safari, #chrome to my features and how would I link them?
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 600000,
allScriptsTimeout: 500000,
defaultTimeoutInterval: 30000,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
multiCapabilities:
[
{
'browserName': 'safari'
},
{
'browserName': 'internet explorer'
},
{
'browserName': 'chrome'
},
{
'browserName': 'firefox'
}],
// Spec patterns are relative to this directory.
specs: [
'features/*.feature'
],
baseUrl: 'http://localhost:8080/',
ignoreSynchronization: true,
cucumberOpts: {
strict: true,
require: [
'hooks/reporter/js',
'specs/*Spec.js'
],
tags: ["runThis", "~ignoreThis"],
profile: false,
format: 'json:e2e/reports/cucumber-report.json',
resultJsonOutputFile: 'e2e/reports/cucumber-report.json'
},
onPrepare: function() {
var chai = require('chai');
chai.use(require('chai-as-promised'));
global.expect = chai.expect;
global.baseURL = this.baseURL;
browser.ignoreSynchronization = true;
browser.driver.manage().window().maximize();
browser.waitForAngular();
browser.driver.manage().timeouts().implicitlyWait(30000);
},
onComplete: function() {
const report = require('multiple-cucumber-html-reporter');
report.generate({
jsonDir: 'e2e/reports/',
reportPath: 'e2e/reports/',
});
}
}
I am having issues getting karma-browserify to work with karma-coverage. I have spent a lot of time trying to figure out what is wrong, but I didn't find a solution.
Here is my .js file (the functions don't do anything; they are just mocks to test code coverage):
// src/js/utilities/form-validation.js
let includedInTest = () => true;
let alsoIncludedInTest = () => true;
let notIncludedInTest = () => true;
let alsoNotIncludedInTest = () => true;
export default {
includedInTest,
alsoIncludedInTest
};
This is my test file:
// src/spec/utilities/form-validation.spec.js
import formUtilities from '../../js/utilities/form-validation';
describe('Form validation functions', function () {
it('Should return "true"', function () {
expect(formUtilities.includedInTest()).toBe(true);
});
it('Should return "true"', function () {
expect(formUtilities.alsoIncludedInTest()).toBe(true);
});
});
Finally, this is my karma.conf:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['browserify', 'jasmine-jquery', 'jasmine'],
files: [
'bower_components/jquery/dist/jquery.js',
'bower_components/jquery-validation/dist/jquery.validate.js',
'src/js/**/*.js',
'src/spec/**/*.spec.js'
],
exclude: [
'src/js/index.js'
],
preprocessors: {
'src/js/**/*.js': ['browserify', 'coverage'],
'src/spec/**/*.spec.js': ['browserify']
},
browserify: {
debug: true,
transform: [
['babelify', { presets: ['es2015'] }]
]
},
reporters: ['mocha', 'coverage'],
mochaReporter: {
colors: {
success: 'green',
info: 'bgBlue',
warning: 'cyan',
error: 'bgRed'
},
symbols: {
success: '√',
info: '#',
warning: '!',
error: 'x'
}
},
coverageReporter: {
instrumenters: { isparta: require('isparta') },
instrumenter: {
'src/**/*.js': 'isparta'
},
dir: 'coverage',
subdir: '.',
reporters: [
{ type: 'html', dir: 'coverage' },
{ type: 'text-summary' }
],
check: {
global: {
statements: 90,
branches: 90,
functions: 90,
lines: 90
},
each: {
statements: 90,
branches: 90,
functions: 90,
lines: 90
}
},
watermarks: {
statements: [50, 75],
functions: [50, 75],
branches: [50, 75],
lines: [50, 75]
}
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false,
concurrency: Infinity
});
};
This config yields this result:
==== Coverage summary ====
Statements : 100% ( 1/1 )
Branches : 100% ( 2/2 )
Functions : 100% ( 0/0 )
Lines : 100% ( 1/1 )
=============
This is obviously wrong since I have four functions on "form-validation.js", and I am testing two of them. But according to the summary report, there are no functions to be tested.
This line from coverage/index.html reveals only one line is being parsed by karma-coverage:
I also tried 'browserify-istanbul' in the transform array (and removed instrumenters from "coverageReport"):
transform: [
['babelify', { presets: ['es2015'] }],
'browserify-istanbul'
]
But this generates an error:
18 08 2017 15:50:14.617:ERROR [karma]: TypeError: Cannot read property 'start' of undefined
at /Users/gferraz/Sites/OAA-Refactor/node_modules/istanbul/lib/object-utils.js:59:44
at Array.forEach (native)
at Object.addDerivedInfoForFile (/Users/gferraz/Sites/OAA-Refactor/node_modules/istanbul/lib/object-utils.js:58:37)
at Collector.fileCoverageFor (/Users/gferraz/Sites/OAA-Refactor/node_modules/istanbul/lib/collector.js:94:15)
at /Users/gferraz/Sites/OAA-Refactor/node_modules/istanbul/lib/collector.js:108:30
at Array.forEach (native)
at Collector.getFinalCoverage (/Users/gferraz/Sites/OAA-Refactor/node_modules/istanbul/lib/collector.js:107:22)
at checkCoverage (/Users/gferraz/Sites/OAA-Refactor/node_modules/karma-coverage/lib/reporter.js:148:33)
at /Users/gferraz/Sites/OAA-Refactor/node_modules/karma-coverage/lib/reporter.js:257:32
at Array.forEach (native)
at Collection.forEach (/Users/gferraz/Sites/OAA-Refactor/node_modules/karma/lib/browser_collection.js:93:21)
at /Users/gferraz/Sites/OAA-Refactor/node_modules/karma-coverage/lib/reporter.js:247:16
at Array.forEach (native)
at CoverageReporter.onRunComplete (/Users/gferraz/Sites/OAA-Refactor/node_modules/karma-coverage/lib/reporter.js:246:15)
at Server.<anonymous> (/Users/gferraz/Sites/OAA-Refactor/node_modules/karma/lib/events.js:13:22)
at emitTwo (events.js:111:20)
Any suggestions on how to fix the config file?
The config suggested on the correct answer of this post helped me: Karma/Istanbul Code Coverage does not find functions and always returns 100%
Now I am getting an error on the html report ERROR [coverage]: TypeError: Cannot read property 'text' of undefined (meaning the html file I want to generate for the report is not being generated), which seems to be related to istanbul. However, I am getting the right code coverage report on my terminal window:
Strangely enough, the error doesn't happen every time the tests run, so I am able to get the html file just fine sometimes.
Here is the karma.conf that solved the problem addressed on my question:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['browserify', 'jasmine-jquery', 'jasmine'],
files: [
'bower_components/jquery/dist/jquery.js',
'bower_components/jquery-validation/dist/jquery.validate.js',
'src/js/**/*.js',
'src/spec/**/*.spec.js'
],
exclude: [
'src/js/index.js'
],
preprocessors: {
'src/js/**/*.js': ['browserify'],
'src/spec/**/*.spec.js': ['browserify']
},
browserify: {
debug: true,
extensions: ['.js'],
configure: (bundle) => {
bundle.transform('babelify', { presets: ['es2015'] });
bundle.transform(require('browserify-istanbul')({
ignore: ['**/spec/**']
}));
}
},
reporters: ['mocha', 'coverage'],
coverageReporter: {
dir: 'coverage',
subdir: '.',
reporters: [
{ type: 'html', dir: 'coverage' },
{ type: 'text-summary' }
],
etc...
}
});
};
Here is my problem: I want be abble to set firefox in specific language to run our e2e tests, and be abble to distribute them.
all verions:
Mozilla Firefox 53.0.3
Selenium 3.4.0 (from npm)
geckodriver 0.17.0 (from npm)
nightwatch.conf.js:
const seleniumServer = require('selenium-server');
module.exports = {
"src_folders": [
"test/functional/features"
],
"custom_commands_path": [
"test/functional/commands/commun",
"test/functional/commands/project"
],
"output_folder": false,
"selenium": {
"start_process": true,
"server_path": seleniumServer.path,
"port": 4444,
"cli_args": {
"webdriver.gecko.driver": "./node_modules/.bin/geckodriver"
}
},
"test_settings": {
"default": {
"selenium_port": 4444,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": false
},
"detailed_output": false,
"desiredCapabilities": {
"javascriptEnabled": true,
"acceptSslCerts": true,
"marionette": true,
"browserName": "firefox"
}
}
}
};
In general I tryed two way:
dynamically create a firefox profile, and use it.
In theorie, I can use a before(Each) and use firefox-profile. In practice it create my profile but doesn't use it.
const FirefoxProfile = require('firefox-profile');
function setProfile(browser, profile, callback) {
profile.encoded(function (encodedProfile) {
browser.options.desiredCapabilities['firefox_profile'] = encodedProfile;
callback();
});
}
function setPrefToFrench(browser, done) {
var FFprofile = new FirefoxProfile();
FFprofile.setPreference('general.useragent.locale', 'fr');
FFprofile.setPreference('intl.accept_languages', 'fr');
setProfile(browser, FFprofile, done);
}
module.exports = {
'default' : {
isLocal : true
},
beforeEach: function(browser, done) {
setPrefToFrench(browser, done);
done();
}
};
Save a profile (why not ziped) and include it in project
The same, in theorie, i just have to add it on the nightwatch.conf.js
"selenium": {
"start_process": true,
"server_path": seleniumServer.path,
"port": 4444,
"cli_args": {
"webdriver.gecko.driver": "./node_modules/.bin/geckodriver",
"webdriver.firefox.profile": "path/to/my/profile(or base64 zip)"
}
},
But all time the same, my firefox is still in english.
Does anyone whould have a solution, or maybe I made something wrong?