I am using browser.wait to handle spinner on login page but it actually waiting for the whole time which i have passed as a third parameter.
It should move on to next test case when home page appears after 15min as i have provided the 20mins wait. could anyone please help here.
it('test case', function () {
loginPage.login(browser.params.Login.username, browser.params.Login.password);
browser.wait(function() {
loginPage.Spinner().then(function(presenceOfElement) {
logger.info('App is waiting for spinner to complete'+ presenceOfElement);
return !presenceOfElement
}, 20*60*1000);
});
});
I would suggest rewriting the page object and the test to make it more clear what is going on in the test. Try this:
// loginPage page object
this.getSpinner = function () {
return element(by.tagName('a'));
};
// test
browser.wait(function () {
return loginPage.getSpinner().isPresent().then(function (isSpinnerPresent) {
return !isSpinnerPresent;
)};
}, 20*60*1000);
Related
Have anyone found fix for this. I am new to protractor and got some script running. I have a login page and once logged in search for a user. My spec.js has the following structure.
describe('Smoke', function() {
//sum stuff
beforeEach(function () {
browser.get('https://login/');
});
it('should have a title', function() {
expect(browser.getTitle()).toEqual('title');
browser.pause()
});
it('and Login to MSIX', function () {
login.login(username);
});
it('search for a user', function () {
searchUser.searchForUser();
});
it ('print test result', function () {
var userN = loginName.getText().then((text) => {
return text;
})
// at this point data is still a managed promise!
userN.then((text) => {
console.log("Logged in user is: "+text);
console.log("User " +username+" logged in successfully"); // your text would be printed!
})
})
});
For every "it" statement the page reloads and I am losing the content on the page. Also if you notice the last "it" statement to print test result I am noticing "." before the output in console
**..**[12:55:55] W/element - more than one element found for locator by.model("query.identifier") - the first result will be used
**.**Logged in user is: sample user
User abc logged in successfully
**.**
You are telling it to reload the page for every it by using beforeEach:
beforeEach(function () {
browser.get('https://login/');
});
Use beforeAll instead:
beforeAll(function () {
browser.get('https://login/');
});
I have unpredictable behavior page that depends on changes that create developers. And sometimes my tests failed, because page wasn't load. My test scenario structure looks like:
describe('0. first actions', function () {
var lib = require("../../common.js");
var config = browser.params;
var url = config.listOfReferencesUrl, toolbar;
load(url, "list-of-references");
beforeAll(function () {
// some actions on the page
});
it('test0', function () {
since('test0 failed').
expect(toolbar.isPresent()).toBe(true);
});
describe('1.actions1', function () {
beforeAll(function () {
// some actions on the page
});
it('test1', function () {
since('test1 failed').
expect(table.getRow(clientNameNum).getRowInput().isEnabled()).toBe(true);
});
// ... another invested describes
});
Where load function is:
global.load = function (url, pageType) {
browser.get(url);
if (pageType == 'list-of-references'){
browser.executeScript("icms.go('WEB_INQ_PROC', 'InquiryList', null, 0)");
}
browser.waitForAngular();
};
I wonder if I can create structure to stop my tests if page isn't load. But I don't want to use 'jasmine-bail-fast', because I want to see another failures if page will load.
I tried to write something like:
if (this.results_.failedCount > 0) {
// Hack: Quit by filtering upcoming tests
this.env.specFilter = function(spec) {
return false;
};
}
But it isn't working. I use jasmine2.
Maybe somebody know how I can organize it?
You can define a wrapper
var filter = function (fn) {
if (!condition)
throw new Error('skipped');
return fn;
}
and use it on all relevant describe/it blocks:
describe('...', filter(function () {
...
}));
My application taking some to page the login page.So protractor trying to enter the user name before page loads.So i need to say protractor to wait till the login page loads.
Could you please help me what command I need to use for this and where I need to use?(Please modify my code to add the wait command)
PFB for my onPrepare and beforeeach function
onPrepare: function() {
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(new HtmlReporter({
})
}
beforeEach(function() {
browser.get('https://accounts.google.com/');
//browser.manage().timeouts().pageLoadTimeout(30000);
//browser.manage().timeouts().implicitlyWait(5000);
//browser.sleep( 10000 );
//browser.waitForAngular();
});
I used those commented functions,but it didn't work for me.
Please guide me.thanks in advance.
Assuming you want to click the Get Started button, wait for the button to become clickable:
var EC = protractor.ExpectedConditions;
var getStarted = element(by.css('button[title="Get started"]'));
browser.wait(EC.elementToBeClickable(getStarted), 5000);
getStarted.click();
Use the wait command: browser.driver.wait(condition, timeout);
onPrepare: function() {
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(new HtmlReporter({
});
}
beforeEach(function() {
browser.driver.get('https://accounts.google.com/');
return browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function (url) {
return url.indexOf('https://accounts.google.com/') > -1;
});
}, 5000);
//whatever you want after
});
you can wait for any condition like that.
Also, google f.e is not an angular page, so you should use:
browser.driver.get instead of protractors browser.get,
or it will wait for angular on the page.
I am trying to increase the timeout for mocha tests as they are web requests that form part of an automated UI test suite and therefore can take longer than the default 2000ms.
The code itself works great if I call mocha with the --timeout set to 5000ms or so but the default 2000ms is not enough.
I want to be able to set the timeout per test suite so that the timeout becomes part of the success criteria which might be different on a case by case basis.
before(()=>{
var sw = require('selenium-webdriver');
this.driver = new sw.Builder().withCapabilities(sw.Capabilities.chrome()).build();
var c = require('chai');
c.use(require('chai-webdriver')(this.driver));
this.expect = c.expect;
return this.driver.getWindowHandle();
})
after(() => {
return this.driver.quit();
})
describe('Looking at github', () => {
beforeEach(() => {
this.driver.get('http://stackoverflow.com/');
})
describe('When we take a look at the stack overflow home page', () => {
return it('It does not have crazy cat text in it!', () => {
return this.expect('#h-top-questions').dom.to.not.contain.text("Just cats here!");
});
});
})
Use function intead of an arrow and then just call this.timeout(5000); e.g.
describe('When we take a look at the stack overflow home page', () => {
return it('It does not have crazy cat text in it!', function() {
this.timeout(5000);
return this.expect('#h-top-questions').dom.to.not.contain.text("Just cats here!");
});
});
This is because ()=> captures the surrounding this. More http://basarat.gitbooks.io/typescript/content/docs/arrow-functions.html
An alternative to basarat's answer, along similar lines that uses different syntax (that is effectively confusing in a different way!):
describe('When we take a look at the stack overflow home page', () => {
it('does not have crazy cat text in it!', () => {
expect('#h-top-questions').dom.to.not.contain.text("Just cats here!");
}).timeout(5000);
});
We want to use protractor to visit a page, run some tests, and then go to another page for more tests. But the later navigation appears to interfere the tests on the previous page.
Here is the structure:
describe('When user is an admin', function () {
browser.get(browser.baseUrl + 'login');
loginAs(roles.admin);
wait();
describe('After log in', function () {
it('should redirect to the home page', function () {
expect(browser.getCurrentUrl()).toBe(browser.baseUrl + 'home');
expect(true).toBeTruthy();
});
it('should contain a "Locations" tab', function () {
var tabLocations = element(by.id('tabLocations'));
expect(tabLocations.isPresent()).toBeTruthy();
});
it('should contain a link to location list', function () {
var linkLocation = element(by.linkText('Manage Locations'));
expect(linkLocation.isPresent()).toBeTruthy();
});
});
});
Pasted above is the tests on the first page.
Then we want to run the tests on another page: (full coded pasted below)
describe('When user is an admin', function () {
browser.get(browser.baseUrl + 'login');
loginAs(roles.admin);
wait();
describe('After log in', function () {
it('should redirect to the home page', function () {
expect(browser.getCurrentUrl()).toBe(browser.baseUrl + 'home');
expect(true).toBeTruthy();
});
it('should contain a "Locations" tab', function () {
var tabLocations = element(by.id('tabLocations'));
expect(tabLocations.isPresent()).toBeTruthy();
});
it('should contain a link to location list', function () {
var linkLocation = element(by.linkText('Manage Locations'));
expect(linkLocation.isPresent()).toBeTruthy();
});
});
describe('at location manage page', function () {
var listPage = new ListPage();
listPage.visit('Manage Locations');
wait();
it('should be at the location list page', function () {
expect(browser.getCurrentUrl()).toBe(browser.baseUrl + 'locations/list');
expect(true).toBeTruthy();
});
});
});
It appears the navigation in my second describe runs before the execution of it statements in the first describe, therefore my tests on the first page failed.
I've tried placing the second describe ("at location manage page") inside the first describe ("After log in"), but still got the same problem.
So my question is, what is the correct way to arrange the tests in protractor, so as the navigation in later tests will be held until the previous tests are completed?
Do not put code inside a describe. Put it inside a beforeAll(function(){}) (jasmine 2) or a beforeEach(function() {})
That should fix your problem.