protractor instance does not do anything - angularjs

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

Related

Protractor allScriptsTimeout seems not working while loading the application in AngularJS

My scripts are failing due to timeout as my page some times takes more than 30 secs to load. by browsing online I found few options that could be used but none of them are working correctly. I used getPageTimeout, allScriptsTimeout, defaultTimeoutInterval (in JasminNodeOpts)
and
beforeEach(function () {
originalTimeout = jasmine.defaultTimeoutInterval;
jasmine.defaultTimeoutInterval = 50000;
});
None of them are working for me. Every time I get the following error.
Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds
Any help would be greatly appreciated as I am stuck with this issue.
my conf.js file
//conf.js
exports.config = {
framework: 'jasmine',
specs: ['./e2e/spec.js'],
seleniumServerJar: "../bin/selenium-server-standalone-3.9.1.jar",
chromeDriver: "../bin/chromedriver.exe",
seleniumPort: 4444,
resultJsonOutputFile:'./tests/protractorResults.json',
onPrepare: function () {
var SpecReporter = require('jasmine-spec-reporter').SpecReporter
jasmine.getEnv().addReporter(new SpecReporter({
displayStacktrace: 'all'
}));
},
capabilities: {
'browserName': 'chrome',
// getPageTimeout : 100000,
chromeOptions: {
args: ['start-maximized','show-fps-counter=true']
}
},
// getPageTimeout: 100000,
// allScriptsTimeout: 100000,
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
}
Based on your error, it appears the issue is due to lack of allScriptsTimeout. In my conf.js, I have the timeouts setup like:
jasmineNodeOpts:{
defaultTimeoutInterval:150000,
},
allScriptsTimeout: 50000,
However, it appears you have tried this unsuccessfully. A way to get around this is to use browser.wait with Expected Conditions. Using browser.wait() will use its own timeout that you provide.
Find an element that is only visible after your page is done loading, and do something like:
let EC = protractor.ExpectedConditions;
let loaded = element(by.css('div.finallyLoaded')); //put element here
let waitTime = 50000; //in ms
browser.wait(EC.presenceOf(loaded),waitTime);

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: how to Force secuential execution of describe?

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

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 - 'Async callback was not invoked' errors on Jenkins while passing locally

I'm consistently getting the following error when running Protractor end to end UI tests on Jenkins. (OS on the boxes are CentOS 6.7). Firefox browser is used. Xvfb server is started before the build.
Error: Timeout - Async callback was not invoked within timeout by jasmine.DEFAULT_TIMEOUT_INTERVAL.
The same tests consistently pass locally on Windows 10 machine with Firefox 38. I deliberately chose 10-15 already stabilized tests to fix this but no luck. From the logs it seems like the tests go through with every assertion successfully and hang after that.
I use 'done' param in every test and call it after assertion to finish the test. Here is an example of a single test in one of my 2 specs:
page.getWaitForRows(function () {
expect(browser.getCurrentUrl()).toContain(HISOTRY_PATH);
commons.verifyElementDisplayed(commonPage.getNewNumberMenuItem());
commonPage.clickNumberMenuItem().then(function () {
commonPage.clickOnOrderMenuLabel();
commons.waitForUrlToChangeTo(new RegExp(ORDER_MENU)).then(function () {
done();
});
});
});
The time of running is 100 seconds for most of them.
Here is most of my config file (ignoreSynchronization=true is used since synchronization fails for our Angular app because it uses $timeout):
exports.config = {
allScriptsTimeout: 30000,
getPageTimeout: 30000,
troubleshoot: true,
capabilities: {
'browserName': 'firefox'
},
baseUrl: 'http://admin.localhost:9002',
framework: 'jasmine2',
jasmineNodeOpts: {
defaultTimeoutInterval: 50000,
showColors: true
},
onPrepare: function () {
browser.ignoreSynchronization = true;
browser.driver.manage().window().maximize();
var disableNgAnimate = function () {
angular.module('disableNgAnimate', []).run(['$animate', function ($animate) {
$animate.enabled(false);
}]);
};
browser.addMockModule('disableNgAnimate', disableNgAnimate);
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
jasmine.getEnv().addReporter(new HtmlScreenshotReporter({
captureOnlyFailedSpecs: true,
filename: 'failure-report.html',
dest: '.test-results/html',
pathBuilder: function (currentSpec, suites, browserCapabilities) {
return 'chrome/' + currentSpec.fullName;
}
}));
var jasmineReporters = require('jasmine-reporters');
return browser.getProcessedConfig().then(function (config) {
var cap = config.capabilities;
var prePendStr = cap.browserName.toUpperCase() + '-';
if (cap.version) {
prePendStr += 'v' + cap.version + '-';
}
var junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: false,
savePath: '.test-results/protractor',
modifySuiteName: function (generatedSuiteName, suite) {
return generatedSuiteName;
}
});
jasmine.getEnv().addReporter(junitReporter);
});
Please note that synchronization is enabled for some time later in the tests to do the log in, but after that it is once again set to false. Here is the beforeAll method for my tests:
beforeAll(function (done) {
commons.loginAndChooseAccount().then(function () {
browser.ignoreSynchronization = true;
done();
});
});
What I tried:
Connecting directly to Firefox using directConnect: true,
Updating protractor version to 3.1.1
Specifically setting
browser.ignoreSynchronization to "true" in each 'it' test or in
'beforeEach'
and a lot other stuff.
Nothing worked. Each 'it' in the 2 specs I run fail with this error. And there are consistently 0 failures locally for the same tests. I tried switching to Chrome but is does not officially support CentOS 6.7 so I'm stuck with Firefox and have been battling with this issue for more than a week now. Will appreciate any help greatly!

Resources