Which test runner would be ideal to run webdriverjs test suite - selenium-webdriver

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());
}
};

Related

Protractor e2e test case for downloading csv file without prompt

Protractor e2e test case for downloading csv file without prompt is not working with the following code. Please help me on this. I have gone through all the stuff already available in stackoverflow. Nothing worked for me...
var q = require("q");
var FirefoxProfile = require("firefox-profile");
var makeFirefoxProfile = function(preferenceMap, specs) {
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",
acceptInsecureCerts: true,
"moz:webdriverClick": false,
firefox_profile: encodedProfile,
};
deferred.resolve(capabilities);
});
return deferred.promise;
};
exports.config = {
getMultiCapabilities: function() {
return q.all([
makeFirefoxProfile(
{
"browser.download.dir": "./",
"browser.helperApps.neverAsk.saveToDisk": "text/commaseparated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel, text/anytext"
},
)
]);
},
// NOTE: this will need changing if a new version of selenium
// standalone server is released --->
seleniumServerJar: 'node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.5.0.jar',
specs: [
'test/e2e/app.e2e_spec.js',
'test/e2e/**/*.e2e_spec.js',
],
capabilities: {
browserName: 'firefox',
acceptInsecureCerts: true,
firefox_profile: makeFirefoxProfile,
"moz:webdriverClick": false
},
jasmineNodeOpts: {
defaultTimeoutInterval: 240000
},
baseUrl: 'https://localhost:3030/',
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine'
};
With the above is my protractor.conf file not working, Prompt pop-up is coming for file download.
Do you have any ideas? Thanks.

jasmineReporters.JUnitXmlReporter doesn't generate XML Report

I have problem with JunitXML reporter. It doesn't generate xml file.
I open test by: protractor example-test.js. I haven't any errors, but file doesn't generate. Please help.
local.ts file
import { Config } from 'protractor';
var jasmineReporters = require('jasmine-reporters');
export const ENV: Config = {
capabilities: {
'browserName': 'chrome',
'version': 'ANY'
},
onPrepare: function() {
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: '/Users/test/Desktop/test2/automatic_tests/raports',
filePrefix: 'xmloutput'
}));
}
local.ts file
import { Config } from 'protractor';
import { ENV } from './local';
export const TestConfig: Config = {
framework: 'jasmine2',
untrackOutstandingTimeouts: true,
jasmineNodeOpts: {
showColors: true
},
allScriptsTimeout: 20000,
noGlobals: true,
capabilities: ENV.capabilities,
seleniumAddress: ENV.seleniumAddress,
baseUrl: ENV.baseUrl,
params: ENV.params
};
test-runner.ts
import { Config } from 'protractor';
import { TestConfig } from '../../test';
export let config: Config = TestConfig;
config.specs = ['example-test.js'];
Help please
Report will be generated. There is one small catch you are missing :)
Your savePath is configured incorrectly. The reporter determines absolute path from the relative path you provide here. You incorrectly have an / at zero index of your path
savePath: '/testresults/results/blah', will create a report in C:\testresults\results\blah
You also must have a report generated in C: Check once
savePath: 'testresults/results/blah', will create a report in <<projectLocation>>\testresults\results\blah

angularjs - e2e mocked backend

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

How to generate a html report in Protractror,

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.
}
};

Protractor timeout on Jenkins with PhantomJS

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?

Resources