Report accessibility plugin results - plugins

The protractor.conf file is configured to report the jasmine test results in junit format according to https://github.com/larrymyers/jasmine-reporters#protractor
// An example configuration file.
// https://raw.github.com/angular/protractor/master/example/conf.js
exports.config = {
// The address of a running selenium server.
// seleniumServerJar: './node_modules/protractor/selenium/selenium-server-standalone-2.41.0.jar', // Make use you check the version in the folder
//seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
framework: "jasmine2",
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
filePrefix: 'xmloutput',
savePath: 'testresults'
}));
},
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
},
plugins: [{
chromeA11YDevTools: true,
path: 'node_modules/protractor/plugins/accessibility'
}]
};
Unfortunately it does not report the results from the accessibility plugin.
In the terminal i see:
Pass: Chrome A11Y - Audio elements should have controls
Pass: Chrome A11Y - ARIA state and property values must be valid
Pass: Chrome A11Y - Elements with ARIA roles must use a valid, non-abstract ARIA role
Fail: Chrome A11Y - Controls and media elements should have labels
2 elements failed:
<input type="checkbox" ng-model="todo.done" class="ng-pristine ng-untouched ng-valid">
<input type="checkbox" ng-model="todo.done" class="ng-pristine ng-untouched ng-valid">
https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#-ax_text_01--controls-and-media-elements-should-have-labels
How may this be achieved?

This is not possible with the plugin framework. The problem is that plugins are agnostic to the test framework being used, so they do not emit test results in a way specific to jasmine-reporters.
You can get all test and plugin results in JSON format using resultJsonOutputFile in the config. I'd suggest doing that, and then processing it in any way you need.

Related

How can I email reports generated from 'protractor-jasmine2-html-reporter' to stakeholders after successful test execution.

I have a config file as below:
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
directConnect: true,
onPrepare: function() {
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: './test/reports/',
screenshotsFolder: 'images',
})
);
},
multiCapabilities: [
{
'browserName': 'chrome',
}],
framework: 'jasmine',
specs: ['zoo_spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
My question is is there any code i can write in order to send the report generated from jasmine2-html-reporter as soon as test execution is complete.
Did you try using onComplete instead? Please refer below previous answer
Unable to send Email using nodemailer in protractor.conf.js onComplete: function()
In the config onComplete:function(){} you can write custom code to send email. There are many nodejs email clients that you can reuse to send emails without reinventing. Here is the example client you can use https://nodemailer.com/about/ and also review SMTP section to for configuration;

ScriptTimeoutError: Timed out - From: Task: Protractor.waitForAngular()

I am trying to run basic end to end tests written using protractor. I always get this error.
ScriptTimeoutError: Timed out
I checked this link https://github.com/angular/protractor/blob/master/docs/timeouts.md and increased the default timeout, but still I get the same error. I am not able to figure out from where this error pops out. The browser loads the base Url, later it will not perform any action as mentioned in the test. The test is very simple , open the browser and click on the menu and verify if the URL is matched.
Node Version: v7.5.0
Protractor Version: 5.1.2
Angular Version: 2.4.10
Browser(s): firefox
Operating System and Version ubuntu
typescript: 2.2.2
Config file
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['test/e2e/menu.js'],
capabilities: {
'browserName': 'firefox',
},
baseUrl: 'http://localhost:8100/#/',
//allScriptsTimeout: 360000,
jasmineNodeOpts: {
showColors: true,
// defaultTimeoutInterval: 360000
},
//useAllAngular2AppRoots:true,
//menu.js
describe('menu check', function () {
beforeEach(function () {
browser.get('http://localhost:8100/#/');
browser.waitForAngular();
// browser.driver.manage().timeouts().setScriptTimeout(60000);
});
it('Should route to the operationalView page from menu', function () {
element(by.css('[href="#/operationalView"]')).click();
expect(browser.getCurrentUrl()).toMatch('http://localhost:8100/#/operationalView');
});
it('Should route to the worldlview page from menu', function () {
element(by.css('[href="#/worldView"]')).click();
expect(browser.getCurrentUrl()).toMatch('http://localhost:8100/#/worldView');
});
});
I have had this issue once, which I resolved using
browser.ignoreSynchronization=true
before the beforeEach() method in your Protractor spec files. This makes Protractor not wait for Angular promises, such as those from $http or $timeout to resolve. You can try this in your script.
Edit : As of today, 08/16/19, this solution has been deprecated. Use waitForAngularEnabled to be false instead.

Unable to produce HTML reports in protractor 3.3.0 with protractor-html-screenshot-reporter

i am new to protractor testing.
i was using protractor with protractor-html-screenshot-reporter and i used to generate html reports.
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: '/protractor-result', // a location to store screen shots.
docTitle: 'Protractor Demo Reporter',
docName: 'protractor-demo-tests-report.html'
but when i upgraded my protractor version to 3.3.0, i am unable to produce these reports anymore by using protractor-html-screenshot-reporter module.
i may be missing some or the other configurations or is it not compatible with the protractor 3.3.0 version
any response would be highly appreciated.
protractor-html-screenshot-reporter is not compatible with jasmine 2. Latest versions of protractor come with Jasmine2 by default.You can use -
protractor-jasmine2-html-reporter
for Json report you need to add resultJsonOutputFile in your config file.
resultJsonOutputFile: 'Path to your Report.json'
Code Snippet of conf.js
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
directConnect: true, //seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://juliemr.github.io/protractor-demo/',
framework: 'jasmine2',
specs: ['*spec.js '],
allScriptsTimeout: 180000,
getPageTimeout: 180000,
jasmineNodeOpts: {
defaultTimeoutInterval: 180000
},
resultJsonOutputFile: './Report.json', // here you need to put the json option
onPrepare: function () {
var width = 1300;
var height = 1200;
browser.driver.manage().window().setSize(width, height);
browser.ignoreSynchronization = true;
jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
savePath: './test/reports/'
}));
}
};
NOTE: First install protractor-jasmine2-html-reporter package by running '_npm install protractor-jasmine2-html-reporter' from command prompt. Otherwise it will give error 'protractor-jasmine2-html-reporter' Not found

Running protractor tests on multiple browsers with browser stack

I am trying to run E2E tests on multiple browsers on browser stack, I took the reference from
E2E testing on multiple/parallel browsers in Protractor?
and
Internet Explorer Selenium protractor e2e tests
but the error I get every time I try to run the tests -
ERROR - Unable to start a WebDriver session.
C:\MrWhiteMVP\whitemvp-integrationtests_develop\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113
var template = new Error(this.message);
^
UnknownError: Authorization required
at new bot.Error (C:\MrWhiteMVP\whitemvp-integrationtests_develop\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113:18)
at Object.bot.response.checkResponse (C:\MrWhiteMVP\whitemvp-integrationtests_develop\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:103:11)
But if I run the tests on 1 browser, then it works perfectly fine. this is how my conf file looks like
'use strict';
exports.config = {
seleniumAddress: 'http://hub.browserstack.com/wd/hub',
multicapabilities: [{
'browserstack.user': 'testuser',
'browserstack.key': 'testkey',
// Needed for testing localhost
// 'browserstack.local': 'true',
// Settings for the browser you want to test
'browserName': 'chrome',
'version': '36.0',
'os': 'OS X',
'os_version': 'Mavericks',
'resolution': '1024x768'
},
{
'browserstack.user': 'testuser',
'browserstack.key': 'testkey',
// Needed for testing localhost - 'browserstack.local': 'true',
// Settings for the browser
'browserName': 'firefox',
'os': 'windows'
}],
baseUrl: 'http://origin-develop.mvp.livebranches.com',
// The require statement must be down here, since jasmine-reporters
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
onPrepare: function()
{
require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('xmloutput', true, true));
},
},
};
could anyone please tell me what am I doing wrong here, also we use gulp ti run specs but my problem is it is saying not even going beyond authentication.
I think that first of all, you have an extra comma on your config.
onPrepare: function()
{
require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('xmloutput', true, true));
},
}, <-----
};

angular/protractor timing out with multiple form fields

This is my first angular/protractor test for a login form. When running the test, it will test one form field at a time with no problem, but when adding the second field to test, it always times out. Is there a secret to testing form fields, I'm unaware of?
'use strict';
describe('Login', function () {
beforeEach(function () {
// URL is relative to baseUrl specified in config/test/protractor-e2e.conf.js
browser.get('');
// browser.get('');
// var account = browser.findElement(by.css('#sign-in-account'));
// var username = browser.findElement(by.css('#sign-in-username'));
// var password = browser.findElement(by.css('#sign-in-password'));
// var submit = browser.findElement(by.css('.button-primary'));
// submit.click();
});
it('should redirect user to first module they have access to after successful login', function () {
// Should successfully register a user
element(by.name('account')).sendKeys('test');
element(by.name('username')).sendKeys('test#testing.com');
// element(by.name('password')).sendKeys('1234');
// element(by.css('.button-primary')).click();
// Should move to register page
// expect(browser.getCurrentUrl()).toContain('silpada.kineticsupply.com/module/analytics');
// Should show the first name where the lock icon was
// expect(element(by.name('account')).getText()).toContain('test');
}, 50000);
});
/*
* config/test/protractor-e2e.conf.js
*
* Protractor end-to-end testing configuration
*/
exports.config = {
// ----- How to setup Selenium -----
//
// There are three ways to specify how to use Selenium. Specify one of the
// following:
//
// 1. seleniumServerJar - to start Selenium Standalone locally.
// 2. seleniumAddress - to connect to a Selenium server which is already
// running.
// 3. sauceUser/sauceKey - to use remote Selenium servers via SauceLabs.
// The location of the selenium standalone server .jar file.
seleniumServerJar: null,
// The port to start the selenium server on, or null if the server should
// find its own unused port.
seleniumPort: null,
// Chromedriver location is used to help the selenium standalone server
// find chromedriver. This will be passed to the selenium jar as
// the system property webdriver.chrome.driver. If null, selenium will
// attempt to find chromedriver using PATH.
chromeDriver: null,
// Additional command line options to pass to selenium. For example,
// if you need to change the browser timeout, use
// seleniumArgs: ['-browserTimeout=60'],
seleniumArgs: [],
// If sauceUser and sauceKey are specified, seleniumServerJar will be ignored.
// The tests will be run remotely using SauceLabs.
sauceUser: null,
sauceKey: null,
// The address of a running selenium server. If specified, Protractor will
// connect to an already running instance of selenium. This usually looks like
seleniumAddress: 'http://localhost:4444/wd/hub',
// ----- What tests to run -----
//
// Spec patterns are relative to the location of this config.
specs: [
'./e2e/**/login.js'
],
// ----- Capabilities to be passed to the webdriver instance ----
//
// For a full list of available capabilities, see
// https://code.google.com/p/selenium/wiki/DesiredCapabilities
// and
// https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js
capabilities: {
'browserName': 'chrome'
},
// A base URL for your application under test. Calls to protractor.get()
// with relative paths will be prepended with this.
//baseUrl: 'http://localhost:8081',
baseUrl: 'http://silpada.kineticsupply.com',
allScriptsTimeout:30000,
// Selector for the element housing the angular app - this defaults to
// body, but is necessary if ng-app is on a descendant of <body>
rootElement: 'body',
// A callback function called once protractor is ready and available, and
// before the specs are executed
// You can specify a file containing code to run by setting onPrepare to
// the filename string.
onPrepare: function () {
// At this point, global 'protractor' object will be set up, and jasmine
// will be available. For example, you can add a Jasmine reporter with:
// jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter(
// 'outputdir/', true, true));
},
// ----- Options to be passed to minijasminenode -----
jasmineNodeOpts: {
// onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: true,
// 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: 30000
}
};
<div id="sign-in-container">
<div id="sign-in">
<div class="logoContainer">
<!-- <img src="/assets/img/silpada_logo.png" style="display:block;padding:2rem 0;margin:auto;" alt=""> -->
<img ng-src="{{clientLogo}}" style="display:block;padding:2rem 0;margin:auto;" alt="">
</div>
<div ng-hide="catchResponses" alerts></div>
<form id="sign-in-form" name="authForm" ng-submit="login(credentials)">
<input
id="sign-in-account"
name="account"
type="text"
placeholder="Account ID"
ng-model="credentials.account"
required />
<input
id="sign-in-username"
name="username"
type="text"
placeholder="Username"
ng-model="credentials.username"
required />
<input
id="sign-in-password"
name="password"
type="password"
placeholder="Password"
ng-model="credentials.password"
required />
<button ng-disabled="authForm.$invalid || authenticating()" class="button-primary" type="submit">Login <i style="float:right; font-size:1.5rem;" class="fa fa-cog fa-spin" ng-show="authenticating()"></i></button>
<div id="reset-password">Forgot password?</div>
</form>
</div>
Here's my working script, just add ptor.ignoreSynchronization = true;
describe('Login', function () {
ptor = protractor.getInstance();
ptor.ignoreSynchronization = true;
beforeEach(function () {
// URL is relative to baseUrl specified in config/test/protractor-e2e.conf.js
ptor.get('/');
});
it('should redirect user to first module they have access to after successful login', function () {
// Should successfully register a user
ptor.findElement(protractor.By.name('account')).sendKeys('test');
ptor.findElement(protractor.By.name('username')).sendKeys('test#testing.com');
ptor.findElement(protractor.By.name('password')).sendKeys('1234');
ptor.findElement(protractor.By.css('.button-primary')).click();
// Should move to register page
expect(browser.getCurrentUrl()).toContain('silpada.kineticsupply.com/module/analytics');
// Should show the first name where the lock icon was
expect(element(by.name('account')).getText()).toContain('test');
});
});
My Running result
Using the selenium server at http://localhost:4444/wd/hub
Login
should redirect user to first module they have access to after successful lo
gin
Failures:
1) Login should redirect user to first module they have access to after succes
sful login
Message:
Expected 'http://silpada.kineticsupply.com/login' to contain 'silpada.kinet
icsupply.com/module/analytics'.
Stacktrace:
Error: Failed expectation
2) Login should redirect user to first module they have access to after succes
sful login
Message:
Expected '' to contain 'test'.
Stacktrace:
Error: Failed expectation
Finished in 12.697 seconds
1 test, 2 assertions, 2 failures