How to check the redirect url ?
Hi, I've just started looking at protractor for our single page angularjs app. I met a problem now. In our login page, we have a logo, and when you click it, it will redirect you to the homepage of the company, it's not the same url as the app's.
My code in it:
element(by.id('Home')).click();
ptor.sleep(10000);
var expectedUrl = ptor.getCurrentUrl();
expect(expectedUrl).toEqual('www.globalpaymentsinc.com');
I believe it's about the promise in Angular, sounds like getCurrentUrl will always get the promise Url, but not the redirect url, but I'm not sure how to fix it. I got the error from this code:
Failures:
1) Login Page English Page should redirect to GPN worldwide homepage when clic
k the GPN logo
Message:
Error: Error while waiting for Protractor to sync with the page: {"message"
:"angular is not defined","stackTrace":[{"fileName":"https://www.globalpaymentsi
nc.com/worldwide.html line 68 > Function:4","lineNumber":5,"methodName":"anonymo
us/<"},{"fileName":"https://www.globalpaymentsinc.com/worldwide.html line 68 > F
unction:9","lineNumber":1,"methodName":"anonymous"},{"fileName":"https://www.glo
balpaymentsinc.com/worldwide.html:68","lineNumber":11,"methodName":"handleEvalua
teEvent"}]}
Stacktrace:
Error: Error while waiting for Protractor to sync with the page: {"message"
:"angular is not defined","stackTrace":[{"fileName":"https://www.globalpaymentsi
nc.com/worldwide.html line 68 > Function:4","lineNumber":5,"methodName":"anonymo
us/<"},{"fileName":"https://www.globalpaymentsinc.com/worldwide.html line 68 > F
unction:9","lineNumber":1,"methodName":"anonymous"},{"fileName":"https://www.glo
balpaymentsinc.com/worldwide.html:68","lineNumber":11,"methodName":"handleEvalua
teEvent"}]}
Could anyone help? Thank you in advance.
Hi @stickel , could you give me some advice?
Use this instead - browser.driver.getCurrentUrl() it works for Non-angular pages like login page.
@smahalingam Thank you, it worked for me. Thanks a lot.
@jasonnjit - Glad it worked
What if this was not the login page and just another angular page? What would be the implementation to check if the user has landed on the correct page or not if I wanted use the URL to do this validation. Like say for example : user is on page 1, clicks on a link and lands on page 2- use the URL to validate if he has landed on page 2 or not. Here is the code, I but doesn't seem to be working
let exURL = http://angularjs.org
Then(/^the user should have landed on the Financial Advisors site$/, function(){
return browser.driver.getCurrentUrl().then(function (actualUrl) {
return this.chai.expect(actualURL).equal(exURL, "Error: Navigated to Incorrect URL");
});