Search code examples
javascriptangularprotractor

Trouble getting to Angular app after logging in on non Angular page


I’m trying to create a simple test where I click on a button in my Angular app. However, when I navigate to my Angular app it first redirects me to a non Angular login page.

So a user’s experience is as follows: The user navigates to https://test.com and then is redirected to a login page where they enter a username and password and click the Submit button. Then the app page loads which contains a button which they can click.

I’ve got my code working to the point where when I run protractor, I see a chrome window open, I see the login page appear and I can see text filling into both the ‘Username’ and ‘Password’ fields. However, right after that the chrome browser closes. I do not see my app page loads which contains the button I want to click.

The code I’m using to try and login is as follows (NOTE: username and password text were changed to something fake so I could post my question)

describe('Go to Test site', function() {
  it('and login', function() {
    browser.get('https://test.com');
    browser.ignoreSynchronization=true;
     element(by.name('login')).sendKeys('username');
     element(by.id('cred_password_inputtext')).sendKeys('password');
     element(by.id('cred_sign_in_button')).click();
     //browser.ignoreSynchronization=false;
  });
});

What is the next step? Should I be using “browser.ignoreSynchronization=false;”? Do I need to find the button element on the next page?

At this point I would be happy just to see my app page load so I can even see the button in the test browser. It closes so fast. This is my first question so I apologize if it's confusing. Thank you.


Solution

  • As mentioned by @Batajus you don't have any code, so the test execution has finished.

    If you only need to logon once you can place the code in a beforeAll() and even make a method for it that holds all the logon logic, something like this

    function logon(username, password) {
      var EC = protractor.ExpectedConditions;
    
      browser.get('https://test.contracts365.com');
      browser.ignoreSynchronization = true;
    
      // Wait for the url to be changed to the logon page
      browser.wait(EC.urlContains('login.microsoftonline.com'), 5000);
    
      // Do the logon magic
      element(by.name('login')).sendKeys(username);
      element(by.id('cred_password_inputtext')).sendKeys(password);
      element(by.id('cred_sign_in_button')).click();
      browser.ignoreSynchronization = false;
    
      // Wait till you are back on the page
      browser.wait(EC.urlContains('test.contracts365.com'), 5000);
    }
    
    describe('Go to Test site', function() {
      beforeAll(function() {
        logon('john@doe.com', 'Welcome123')
      });
    
      it('should do some tests', function() {
        // do some tests
      });
    });

    And then add your tests

    Hope it helps