how to get E2E Testing in Protractor results - angularjs

I setup some tests in protractor for my angular app and i wanted to run a nightly batch and see next day some reports of the tests passed or failed .. . I tried without success protractor-html-screenshot-reporter so now i want to see how to save a log . Is this save a log file?
How i could see second day the result of the tests runner ?
My current protractor conf file :
exports.config = {
seleniumAddress: 'http://imptest2:80/wd/hub',
specs: [
'../E2E/**/*.spec.js'
],
multiCapabilities: [
{
'browserName' : 'chrome',
'ensureCleanSession': 'false',
'shardTestFiles': 'true',
maxInstances:8
}
],
params: {
global: {
url: 'http://impiis/TestsServices/Client',
concern: '01'
}
},
baseUrl: 'http://impiis/TestsServices/Client',
allScriptsTimeout: 500000
};
Thank you

With this simple protractor config file, you should have protractor-html-screenshot-reporter working
var HtmlReporter = require('protractor-html-screenshot-reporter');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['Exova.LIMS.UI.Testing/e2e/pages/**/*_spec.js'],
baseUrl: 'http://localhost:51494',
onPrepare: function() {
// Add a screenshot reporter and store screenshots to `/tmp/screnshots`:
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'tmp/screnshots'
}));
}
};

It was a reporter bug it was solved : https://github.com/jintoppy/protractor-html-screenshot-reporter/pull/38

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.

Electron: Run end to end tests with protractor

We are making a desktop app with Electron using AngularJS, we want to make end-to-end tests using Protractor, the problem is that we got issues on running it, we don't really know what is the problem but looks like there is some synchronization problems, like it's not waiting for the page to load, not closing the app after the test is finished.
Here is the protractor configuration file:
const ELECTRON_PATH = '/usr/bin/electron';
const APP_PATH = '/home/me/project/myapp';
exports.config = {
directConnect: true,
framework: 'mocha',
specs: [
'test.js'
],
capabilities: {
browserName: 'chrome',
platform: 'LINUX',
chromeOptions: {
binary: ELECTRON_PATH,
args: ['app=' + APP_PATH, '--e2e-testing']
}
},
onPrepare: function() {
browser.ignoreSynchronization = true;
browser.resetUrl = 'file://';
}
};

Protractor e2e test case for download file work fine on chrome but not with firefox and vice versa?

I have a scenario where I need to click on a link which will trigger .CSV file download to a default location(/tmp)and it is working fine on both chrome and firefox browsers but based on multiCapabilities configuration in conf.js, at times it work only on single browser(means one set of configuration helps in chrome working fine but not the firefox and the other set results in firefox to work but not the chrome).And I used the following stackoverflow post as the reference : Protractor e2e test case for downloading pdf file. And my attempt worked fine someway but then script hits only on chrome or firefox based on multiCapabilities configuration I used.
Please note that chrome will work with following config and in this I haven't added the firefox profile setup . So file download part in firefox wont work with the following configuration.
multiCapabilities: [
{
'browserName': 'chrome',
'platform': 'ANY',
'chromeOptions': {
args: ['--no-sandbox', '--test-type=browser'],
prefs: {
download: {
'prompt_for_download': false,
'directory_upgrade': true,
'default_directory': '/tmp'
}
}
}
},
{
'browserName': 'firefox',
}
],
Based on the above mentioned url(Protractor e2e test case for downloading pdf file) I added the function getFirefoxProfile() in my util file : common.js
var getFirefoxProfile = function() {
var deferred = q.defer();
var firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.dir", '/tmp');
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel, text/anytext");
firefoxProfile.encoded(function(encodedProfile) {
var multiCapabilities = [{
browserName: 'firefox',
firefox_profile : encodedProfile
}];
deferred.resolve(multiCapabilities);
});
return deferred.promise;
}
exports.getFirefoxProfile = getFirefoxProfile;
And then I updated the conf.js as follows:
getMultiCapabilities: com.getFirefoxProfile,
multiCapabilities: [
{
'browserName': 'chrome',
'platform': 'ANY',
'chromeOptions': {
args: ['--no-sandbox', '--test-type=browser'],
prefs: {
download: {
'prompt_for_download': false,
'directory_upgrade': true,
'default_directory': '/tmp'
}
}
}
},
{
'browserName': 'firefox',
}
],
And getMultiCapabilities: com.getFirefoxProfile when used in conf.js will override both capabilities and multiCapabilities mentioned in the conf.js and when I run my script, it executes the script only on firefox and not in chrome.
Any idea on how to fix this? And my requirement is to login to chrome, perform the csv download, logout from chrome, then login to firefox and do the same.
Any help would be greatly appreciated..
For adding capabilities to multiple browser(chrome and firefox), we need to use multiCapabilities, and add capabilities of each browser(firefox and chrome) as follows.
Note : Here I configured multi capabilities with promises.
var q = require("q");
var FirefoxProfile = require("firefox-profile");
exports.config = {
directConnect: true,
onPrepare: function () {
browser.driver.getCapabilities().then(function(caps){
browser.browserName = caps.get('browserName');
});
},
maxSessions: 1,
getPageTimeout: 150000,
allScriptsTimeout: 150000,
params: require('../testdata/data.json'),
framework: 'jasmine2',
specs: ['../unit_test/*_spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 150000
},
//seleniumAddress: "http://127.0.0.1:4444/wd/hub",
getMultiCapabilities: function() {
var deferred = q.defer();
var multiCapabilities = [
{
'browserName': 'chrome',
'platform': 'ANY',
'chromeOptions': {
args: ['--no-sandbox', '--test-type=browser'],
prefs: {
download: {
'prompt_for_download': false,
'directory_upgrade': true,
'default_directory': '/tmp'
}
}
}
},
];
// Wait for a server to be ready or get capabilities asynchronously.
setTimeout(function() {
var firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("javascript.enabled", false);
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.dir", '/tmp');
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel, text/anytext");
firefoxProfile.encoded(function (encodedProfile) {
var capabilities = {
"browserName": "firefox",
"firefox_profile": encodedProfile
};
multiCapabilities.push(capabilities);
deferred.resolve(multiCapabilities);
});
}, 1000);
return deferred.promise;
}
};
The default download location is set as /tmp for both browsers and for firefox to set capabilities, we need create a firefox profile and set preference.
Note :
"browser.download.folderList", 2 ==> set the download location as user defined. passing value 0 set download to desktop and 1 will download to default download location.
Also "browser.helperApps.neverAsk.saveToDisk", "text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel, text/anytext" ==> mime type used is csv mime type.
If your download file is pdf or some other, replace the csv mime type with your files mime type.

how to run end to end test in Protractor?

I am new to angularjs ,trying to test my app with karma,jasmine and protractor.
here is my conf.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
specs: ['spec.js'],
jasmineNodeOpts: {
showColors: true,
}
};
here is my spec.js
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://localhost/First-angular-App/source/');
expect(browser.getTitle()).toEqual('Firstangular app');
});
});
after running protractor conf.js I get this:
but can't run my test how can i do this??
As noted above:
The error message tells exactly why your tests are not running. This option specifies a path to your specs: ['spec.js']. Modify conf.js and set a path to a folder with your specs relative to conf.js: specs: ['tests/spec.js'] or even better specs: ['tests/**/*.js'] (will take all files in tests/ directory as test files).
Upgrading my node version to LTS(Node Website), I fixed this problem.

Phantomjs fails when Protractor is run with selenium hub

I have a protractor config file as follows and i use phantomjs to run the tests. It works when i use seleniumServerJar but fails when i use seleniumAddress (pointing to a hub) with a 'The driver executable does not exist' message! Is there any specific config to run phantomjs with selenium-hub?
exports.config = {
//Fails when i use this
//seleniumAddress:"http://selenium-hub.com:4659/wd/hub",
//Works when i use this selenium-standalone jar
seleniumServerJar: '../../../node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar',
framework: 'cucumber',
specs: [
'features/*.feature'
],
capabilities: {
"browserName": "phantomjs",
"phantomjs.binary.path": require("phantomjs").path,
"phantomjs.ghostdriver.cli.args": ["--loglevel=DEBUG"]
},
baseUrl: '',
rootElement: 'body',
resultJsonOutputFile: 'src/test/report.json',
cucumberOpts: {
require: 'features/steps/*_steps.js',
}
};

Resources