protractor icon indicating copy to clipboard operation
protractor copied to clipboard

How to check the redirect url ?

Open jasonnjit opened this issue 12 years ago • 5 comments

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.

jasonnjit avatar Jul 31 '14 03:07 jasonnjit

Hi @stickel , could you give me some advice?

jasonnjit avatar Jul 31 '14 03:07 jasonnjit

Use this instead - browser.driver.getCurrentUrl() it works for Non-angular pages like login page.

smahalingam avatar Jul 31 '14 10:07 smahalingam

@smahalingam Thank you, it worked for me. Thanks a lot.

jasonnjit avatar Jul 31 '14 17:07 jasonnjit

@jasonnjit - Glad it worked

smahalingam avatar Jul 31 '14 22:07 smahalingam

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");
       });

skullz03 avatar Apr 14 '18 22:04 skullz03