0

I have an application where it navigates away to an Non-Angular app for login. The basic login is like this. First, loads the angular app, then click on a button on the page. Then navigates away to a non angular app (STS implemented with IdentityServer) and logs in, Then navigates back to the angular app.

Here is the code i wrote to handle this.

this.login = function (userId) { 
    browser.driver.get(browser.params.host.hostname);  
    browser.driver.findElement(by.id('continuebutton')).click();
    browser.driver.wait(function () {               
        browser.driver.findElement(by.xpath("//*[@id=\"body\"]/section/div[2]/div[3]/a")).click();
        browser.driver.findElement(by.id("UserName")).sendKeys(userId);
        browser.driver.findElement(by.id("Password")).sendKeys("flisdev");
        browser.driver.findElement(by.tagName("button")).click(); 
    }, 10000);
};

But this throws 'Angular not found on page" error and sometimes randomly element not found error for the link referenced by the XPath. basic flow of the login is like

Angular App --> Non-Angualr App --> Angular App

How can i handle this kind of login?

pbaris
  • 4,525
  • 5
  • 37
  • 61
Kasun Kodagoda
  • 3,956
  • 5
  • 31
  • 54

2 Answers2

1

Whenever you shift to Non-Angular App, use:

browser.ignoreSynchronization = true 

code in the beforeAll() or beforeEach() functions, so that protractor gets to know that it shouldn't check for Angular on the page and will not wait for Angular to settle down. If this still doesn't fix your issue, then try giving browser.ignoreSynchronization = false in your Angular App along with the above line. Along with that its best practice to wait for element to appear before performing actions on it to avoid errors related to element presence. Hope this helps.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
giri-sh
  • 6,934
  • 2
  • 25
  • 50
  • I tried with this too before i posted the question. This will still give the angular not found error when running the tests. – Kasun Kodagoda Sep 01 '15 at 03:40
  • @KasunKodagoda Did you try adding the line in `beforeAll()` or `beforeEach()` functions? or in `onPrepare()` function? – giri-sh Sep 01 '15 at 07:54
1

In my protractor_example github repo, I use browser.ignoreSynchronization = true at the page level; ie. at the top of my page object (which it looks like you're using. This made the most sense to me and should work for your situation as well, as my example also contains a non-angular login page (very common it seems).

Also, when using browser.ignoreSynchronization = true, you don't want to use browser.driver. Use just browser.

Brine
  • 3,733
  • 1
  • 21
  • 38