Protractor: how to Force secuential execution of describe? - angularjs

I'm using protractor to test an webapp, there is a lot of test_.js and it looks like all test are running at the same time. if I set just one test in the export.config.specs it works flawlessly but if I use wildcard or put 2 or more spects it open the browser and try to open all the routes at the same time and fails all test...
So is there a flag or something that I miss to force execute all describes one by one?
An excerpt of my conf file:
exports.config = {
multiCapabilities: [
{'browserName': 'chrome'}
],
seleniumAddress: 'http://localhost:4444/wd/hub',
params: {
domain: 'http://0.0.0.0:3000/'
},
specs: [
'specs/test_login.js',
//'specs/test_*.js'
]
};
an example of one of the many specs:
describe('homepage test', function() {
browser.get(browser.params.domain);
it('should check page title', function() {
return expect(browser.getTitle()).toEqual('The title');
});
});

The browser actions must be allwais within a Jasmin action like
it
before(All/Each)
after(All/Each)
Solution based on example:
describe('homepage test', function() {
beforeAll(function() {
browser.get(browser.params.domain);
});
it('should check page title', function() {
return expect(browser.getTitle()).toEqual('The title');
});
});
source: http://jasmine.github.io/2.4/introduction.html#section-Setup_and_Teardown

If you want all the describes to run sequentially in the same browser window, in exports.config, under multiCapabilities (or capabilities) add shardTestFiles: false
If you want all the describes to run one at a time in separate browser windows, in exports.config, add maxSessions: 1

Related

protractor -errors Message:Expected 0 to equal 5

protractor show me error message
that there are no list item.
conFusion App E2E Testing menu 0 item should show the number of comments
Message:
Expected 0 to equal 5.
Stack:
Error: Failed expectation
at Object. (/Users/fullStock/anglerJs/conFusion/test/e2e/scenarios.js:37:23)
I did e2e test to ensure the number of comment list that will appear on page is 5.I used json server to serve up the data. I think the problem is element have not appeared in the DOM yet.Is there any way to tell protractor to wait until an element finally appears in the DOM?
code e2e test
describe('menu 0 item', function() {
beforeEach(function() {
browser.get('index.html#/menu/0');
});
it('should have a name', function() {
var name = element(by.binding('dish.name'));
expect(name.getText()).
toEqual('Uthapizza Hot $4.99');
});
it('should show the number of comments as', function() {
expect(element.all(by.repeater('comment in dish.comments'))
.count()).toEqual(5);
});
code html for comment
<h4> Customer Comments
<span style="font-size:15px;">sorted by:<input type="text" ng-model="FiltText"></span></h4>
<blockquote ng-repeat="commet in dish.comments |orderBy:FiltText">
<h5>{{commet.rating}} Stars</h5>
<h5>{{commet.comment}}</h5>
<footer>{{commet.author}}, <span>{{commet.date|date}}.</span></footer>
</blockquote>
protractor configuration
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/*.js'
],
capabilities: {
browserName: 'chrome'
},
baseUrl: 'http://localhost:3001/',
framework: 'jasmine',
directConnect: true,
jasmineNodeOpts: {
defaultTimeoutInterval:30000
}
};
Check with this updated test cases. The thing is, you haven't taken the whole repeater.
it('should show the number of comments as', function() {
expect(element.all(by.repeater('commet in dish.comments |orderBy:FiltText'))
.count()).toEqual(5);
});

protractor instance does not do anything

from one to anothet day i cannot interact with the angular page i am testing.
The only result i get:
Started
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
F
the page has this:
<html lang="sv" class="no-js" data-ng-app="app">
So it should work, or not?
I tried checking on iFrames and also enhanced the allScriptTimeout: 360000, but nothing helped.
here is my config:
var TIMEOUT = 360000;
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: 'report/screenshots',
filename: 'my-report.html'
});
exports.config = {
seleniumAddress: 'http://dmc-l01-ap08.dmc.de:4448/wd/hub',
baseUrl: 'https://int.system.com/',
specs: [
'./UseCases/protractorTestcaseNightly.js',
],
Capabilities: [
{
'browserName': 'chrome',
shardTestFiles: false,
maxInstances: 1,
maxSessions: -1,
restartBrowserBetweenTests: true,
},
],
getPageTimeout: TIMEOUT,
allScriptsTimeout: TIMEOUT,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: TIMEOUT,
includeStackTrace : true,
isVerbose : true,
},
framework: "jasmine2",
onPrepare: function () {
browser.driver.manage().window().maximize();
browser.driver.manage().deleteAllCookies();
jasmine.getEnv().addReporter(reporter);
var reporters = require('jasmine-reporters');
var junitReporter = new reporters.JUnitXmlReporter({
savePath: 'report/xml',
consolidateAll: false,
filePrefix: 'xmloutput'
});
jasmine.getEnv().addReporter(junitReporter);
}
};
UPDATE:
I added
rootElement: 'html',
to my config. But nothing changed. I also took a screenshot from the page before clicking the first element. In the screenshot i can see the element i want to click at.
this is my Testspec:
describe('Start testspec | ', function () {
it('opens the start', function () {
browser.get("/de-de/connect/").then(function () {
console.log("1"); //works
browser.executeScript('localStorage.clear();sessionStorage.clear();'); //works (?)
console.log("2"); //works
expect(element(by.xpath('//*[#class="btn-link"]'))).toBeTruthy(); //works
console.log("3"); //works
browser.sleep(3000); //works
element(by.css('.ms-linklist-typ-1 a')).click(); //DOES NOT WORK :(
browser.sleep(3000); //works
});
});
});
I do have to click on the "btn-link" / css element, because this is the cookie layer, which has to be clicked first before i can reach any other element...
any ideas?
Looks like you are using the timeout configuration incorrectly. allScriptTimeout is only for the backend application scripts is not for the overall Jasmine spec
Please take a look at the three timeouts explained below
allScriptsTimeout - This timeout config indicates the time
application needs to finish running back-end scripts
getPageTimeout - This indicates the time to wait for Page
Load
jasmineNodeOpts.defaultTimeoutInterval - This indicates the
time that Jasmine waits for overall spec
So in your case you increase the jasmineNodeOpts.defaultTimeoutInterval to increase the timeout for overall spec
Try making the below change and see if this resolves the issue
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 120000,
includeStackTrace : true,
isVerbose : true,
},
Also, Protractor assumes your angular-app root element to be body. Please see the below extract from the documentation below. Since your ng-app resides on a different element , may be update the config.js accordingly
/** * CSS Selector for the element housing the angular app - this
defaults to * 'body', but is necessary if ng-app is on a descendant
of . */
rootElement?: string;
it looks like i found the fix. My tests are running again by changing the versions of my installation. I looks like there is incompatibility between some version. It now works with:
Node LTS (6.10.0)
Selenium Server Standalone 3.0.1
protractor#5.1.1
npm#4.1.2

Protractor-trx-reporter not creating trx file

I'm working with Protractor for the first time and I've installed some modules with NPM for protractor, protractor-trx-reporter, jasmine-trx-reporter, and webdriver-manager. Selenium server is running at the default 4444 port, and the tests seem to run fine when I run it locally through command line (opens a browser, test passes).
Everything seems to not give any errors, but I can't find the trx file published by the protractor-trx-reporter. When I run protractor conf.js, the test starts, and the command line output says that it's exporting the trx reporter and setting the output file to ProtractorTestResults.trx but a .trx file doesn't show up anywhere so I suspect it's not publishing a file but not throwing errors.
Any ideas if protractor-trx-reporter hasn't exported a trx file?
Here's what my config and spec files look like (both taken as samples from Protractor and protractor-trx-reporter sites)
//conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
onPrepare: function () {
console.log('Adding TRX reporter');
require('protractor-trx-reporter');
jasmine.getEnv().addReporter(new jasmine.TrxReporter('ProtractorTestResults.trx'));
}
}
//spec.js
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('https://angularjs.org');
element(by.model('todoList.todoText')).sendKeys('write first protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write first protractor test');
// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
});
});
I ended up using jasmine-trx-reporter, here's what the conf.js looked like:
// conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect: true,
specs: ['spec.js'],
capabilities: {
'browserName': 'chrome'
},
onPrepare: function () {
var trx = require('jasmine-trx-reporter');
return browser.getCapabilities().then(function (caps) {
var browserName = caps.get('browserName').toUpperCase();
var jasmineTrxConfig = {
reportName: 'Protractor Test Results',
folder: 'testResults',
outputFile: 'Test.trx',
browser: browserName,
groupSuitesIntoSingleFile: false
};
jasmine.getEnv().addReporter(new trx(jasmineTrxConfig));
});
}
};
I think this may be the answer:
"...short term we will not add support for Jasmine 2.0. Later on maybe
yes, but I can't promise you a date."
So that's upsetting. I'm having the same problem. And jasmine-trx-reporter isn't working for me either.
Source: [https://github.com/hatchteam/protractor-trx-reporter/issues/2]

Protractor: Async timing out, I think because it won't find an element

UPDATE #2: Traced back to the web app using $timeout instead of $interval. Explained here http://www.protractortest.org/#/timeouts under waiting for page synchronization
UPDATE: So I threw in browser.ignoreSynchronization=true; browser.sleep(5000);for the second test and it works. Not sure why.... The login page works perfectly without it. Best guess now is that it's a running script so it never finishes synchronizing???? Not really sure why it doesn't synchronize.
So more or less, how come I would need to ignore synchronization knowing that the site is angular???????
I'm using Protractor with the Jasmine framework.
Tests have been working up to this point.
I think Protractor cannot find my element and therefore times out. I can't figure out why it won't find my element as it does perfectly fine in earlier tests.
My conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
allScriptsTimeout: 10000,
onPrepare: function() {
var SpecReporter = require('jasmine-spec-reporter');
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'}));
},
jasmineNodeOpts: {
showColors: true,
isVerbose: true,
realtimeFailure: true,
includeStackTrace: true,
defaultTimeoutInterval: 10000,
print: function() {}
}
};
Current spec.js
describe('Authorizing newly created account', function() {
//This test works fine
it('should navigate back to login and login', function() {
browser.get('website');
element(by.model('$parent.username')).sendKeys('user');
element(by.model('$parent.password')).sendKeys('test');
element(by.buttonText('Login')).click();
});
//This one doesn't
it('should navigate to organizations', function() {
//DOESN'T WORK
var button = element(by.id('btn_organizations'));
button.click();
});
});
The snippet of HTML I'm trying to get ("Organization" link)
<li ng-if="user.administrator || user.organizationAdministrator">
<a ui-sref="organizations" ng-click="closeNav()" id="btn_organizations">
<span class="glyphicons glyphicons-tree-structure"></span>
<span class="hidden-sm"><g:message code="organizations" /></span>
</a>
</li>
I thought since the organizations had a ID I could use it to access it, but Protractor doesn't seem to like it.
I then get the error
-Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL
I really hope this isn't something dumb I'm missing.
Try all those options, it should work with the call back :
describe('Authorizing newly created account', function() {
beforeEach(function(done) {
done();
}, 10000);
//This test works fine
it('should navigate back to login and login', function() {
browser.get('website');
element(by.model('$parent.username')).sendKeys('user');
element(by.model('$parent.password')).sendKeys('test');
element(by.buttonText('Login')).click();
},10000);
//This one doesn't
it('should navigate to organizations', function() {
//DOESN'T WORK
var button = element(by.id('btn_organizations'));
button.click();
},10000);
},10000);
Take a look into this question and how i have resolved it : Time out problem

Protractor: Multiple browser instance tests fail where Single Instance tests pass

I'm testing an Ionic application. When the app is run in the browser, the console does show that cordova.js is missing - which is right, but it doesn't break the application.
As long as I run my tests with a single browser instance, the missing files does not cause my tests to fail. Here is my configuration and spec files:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine2',
suites: {
test: 'e2e/test.spec.js'
},
allScriptsTimeout: 60000,
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
binary: '/Applications/Google\ Chrome\ Stable.app/Contents/MacOS/Google\ Chrome',
args: [],
extensions: [],
}
},
onPrepare: function() {
browser.driver.get('http://localhost:8100');
}
};
Here is the test file:
describe('First test', function(){
it('just verifies that everything loads correctly', function() {
expect(1).toEqual(1);
});
});
The above works without errors. But opening a second browser instance causes a fail:
describe('First test', function(){
var browser2 = browser.forkNewDriverInstance();
browser2.get('http://localhost:8100');
var element2 = browser2.element;
it('just verifies that everything loads correctly', function() {
expect(1).toEqual(1);
});
});
With the error message:
/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:113
var template = new Error(this.message);
^
UnknownError: unknown error: cordova is not defined

Resources