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);
});
Related
I'm newcomer with protractor and now my work needs is to create testing project for angularjs application.
I've started with guidelines and faced with error on start:
Error: Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.0/$rootScope/infdig?p0=10&p1=%5B%5D
http://localhost/main-f3fbd0c72e8415cd0a449214b66bdacc-cached.js:2140
at window.onerror (http://localhost/main-f3fbd0c72e8415cd0a449214b66bdacc-cached.js:1277:52)
Configuration file
exports.config = {
directConnect: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
specs: ['specs/spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
Test file:
"use strict";
describe('WEB test project', function() {
var wl5StartPage = require('../pages/startPage.js');
it('Its start login page', function() {
wl5StartPage.get();
wl5StartPage.wl5Login();
});
});
startPage.js:
var WL5LoginPage = function() {
this.userName = element(by.model('loginInfo.userId'));
this.loginButton = element(by.css('[ng-click="login()"]'));
this.get = function() {
browser.get('http://localhost/login');
};
this.wl5Login = function() {
this.userName.sendKeys("user1");
this.loginButton.click();
};
}
module.exports = new WL5LoginPage();
Its very simple test, but unfortunatelly it crashed when I entered username and clicked "Login".
Is there some way to ignore such browser errors? Or some way to fix problem?
Thank you in advance.
Basically there is nothing wrong with protractorJS code. Reason why you are seeing this - it is because your angular application throws this error. Protractor is trying to wait for angular on the page - but can't . Seems like your error is similar to this one - Error: 10 $digest() iterations reached. Aborting! with dynamic sortby predicate
I would suggest only as a temporary solution to disable protractor's waitForAngular just to debug your test:
browser.waitForAngularEnabled(false)
http://www.protractortest.org/#/api?view=ProtractorBrowser.prototype.waitForAngularEnabled
But i am 99% sure that this is something that must be fixed on frontend side to allow smooth test automation with automatic waiting for angular.
UPDATE: Also you might try to turn on this property in your protractor config - https://github.com/angular/protractor/blob/master/lib/config.ts#L485
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
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
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
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