Protractor, login to asp,net MVC login page, wait for default page then , redirect to angular page and do tests....how?

848 views Asked by At

I'm trying to implement Protractor test on my MVC Project that we are slowly converting to Angular

I login on a MVC login page, enter the login and password, Click login, then I need to wait for the login to go through several pages, and get to the default screen.

Then I need to redirect to one of my Angular pages and run a simple test (button = enabled).

I think this is what I need to do, and if Im correct, I failing at the wait for several redirects to end up at default page. I'm redirecting to my page before the whole login process is finished.

Here is what I have:

// spec.js
//ptor = protractor.getInstance();
describe('ScoutAngular Protractor Tests', function () {

    beforeEach(function () {
        browser.ignoreSynchronization = true;
        browser.get('http://localhost/Scout3G/Account/LogOn');
        browser.driver.findElement(by.id('UserName')).sendKeys('oster.robert');
        browser.driver.findElement(by.id('Password')).sendKeys('H0gw1ld!');

    });

    it('should login and goto the angular page', function () {

        var submit = browser.driver.findElement(protractor.By.tagName('input'));
        browser.ignoreSynchronization = false;
        submit.click().then
        (
            function () 
            {
                console.log("===================== 1");

              //<<<<<--------I think i need to wait for login to finish several page redirects here

                browser.get('http://localhost/Scout3G/Maintenance/TestAngularEWB')
                .then(function () {
                        browser.driver.sleep(1);
                        browser.waitForAngular();
                        console.log("===================== about to expect");
                        element(by.Css("button").isEnabled());
                    }
                );
            }
        );
        console.log("===================== 4");
    });


});

When I get to my TestAngularEWB page I'm getting a user not logged in error...

How can I make it wait for the default page, before redirecting to TestAngulareEWB?

Am I making any other total noob protractor mistakes?

2

There are 2 answers

1
alecxe On BEST ANSWER

If you know which URL ends the redirect chain, you can use browser.wait() to wait for current URL to become equal to an expected one:

var urlChanged = function(expectedUrl) {
  return function () {
    return browser.getCurrentUrl().then(function(actualUrl) {
      return expectedUrl === actualUrl;
    });
  };
};

browser.wait(urlChanged("http://url.to/wait/for"), 5000); 
0
Dziamid On
it('should login and goto the angular page', function () {
  browser.ignoreSynchronization = true;
  element(by.tagName('input')).click();
  browser.wait(protractor.until.elementLocated(by.partialLinkText('Hello, non-angular!'))) //wait until user is redirected to non-angular page
  browser.get('http://localhost/Scout3G/Maintenance/TestAngularEWB');
  browser.wait(protractor.until.elementLocated(by.partialLinkText('Hello, angular'))) //wait until user is redirected to angular page
  browser.ignoreSynchronization = false;
});