Reputation: 13
We are in process of implementing BDD approach and use protractor for testing. The application under test has both Angular and Non Angular pages. The login page is non angular and home page is angular. The script runs fine on Login page and when it lands to non angular nothing happens (no action performed).
What could be the issue?
StepDefinition.js
Given(/^User lands on Login$/, function () {
var appUrl = properties.get('appUrl');
return browser.driver.get('appUrl');
browser.ignoreSynchronization = true;
});
When(/^User enters Username and Password$/, function () {
xph.get('Username').sendKeys(username);
return xph.get('Password').sendKeys('password');;
});
When(/^User Clicks Submit$/, function(){
browser.executeScript("arguments[0].click();",xph.get('Login'))
//return browser.sleep(7000);
browser.ignoreSynchronization = false;
browser.waitForAngular();
});
Then(/^User successfully logs$/, function() {
var hString= xph.get('LogOut');
hString.getText().then(function(text){expect(text).to.equal('LogOut');});
});
Then(/^User clicks Create Account$/, function () {
browser.executeScript("arguments[0].click();",xph.get('CreateAcct'))
});
Upvotes: 1
Views: 132
Reputation: 13712
Two issue in your code, try again after fix them as following:
1) you put browser.ignoreSynchronization = true
behindreturn
, it make no sense.
Inside browser.get()
, it will detect the opening page is angular, except to put browser.ignoreSynchronization = true
before browser.get()
to tell protractor the opening page is non angular page.
Given(/^User lands on Login$/, function () {
var appUrl = properties.get('appUrl');
browser.ignoreSynchronization = true;
return browser.driver.get('appUrl');
});
2) You have to return a promise like object for each step definition, otherwise the runner will pause at that step definition until timeout.
waitForAngular()
equivalent to browser.ignoreSynchronization = false;
, The former is introduced in protractor higher version, the later can work protractor lower and higher version.
Why you not use the Protractor API xph.get('Login').click()
, but using Javascript DOM API
to click the Submit
button.
When(/^User Clicks Submit$/, function(){
return element(<locator of Submit button>).click().then(function(){
return browser.ignoreSynchronization = false;
})
});
Upvotes: 1