A page without angular opens after clicking

I am trying to implement the following test case:

  • click on the logo on the page
  • claim that a new browser window has opened (tab in Chrome) and check the current URL

The problem is that the page opened in a new browser window is not an angular page, but the main page I click on is the angular page.

Here is my first attempt:

it("should show logo", function () { var logo = scope.page.logo; expect(logo.isDisplayed()).toEqual(true); // opens a new page on click logo.click().then(function () { browser.getAllWindowHandles().then(function (handles) { browser.switchTo().window(handles[1]).then(function () { expect(browser.getCurrentUrl()).toEqual('http://myurl.com/'); }); // switch back to the main window browser.switchTo().window(handles[0]); }); }); }); 

which fails:

Error: Error while trying to synchronize the tracer with the page: "angular could not be found in the window"

which is understandable.

My second attempt was to play with the ignoreSynchronization boolean flag:

 browser.ignoreSynchronization = true; logo.click().then(function () { browser.getAllWindowHandles().then(function (handles) { browser.switchTo().window(handles[1]).then(function () { expect(browser.getCurrentUrl()).toEqual('http://myurl.com/'); }); // switch back to the main window browser.switchTo().window(handles[0]); }); 

This actually makes this particular test pass without any errors, but it affects every test that runs after that because the browser is a global object and is shared between the tests. The transcavator is no longer synchronized with angular on the page, which results in all kinds of errors.

How do I perform a test?




As a workaround, I can change the restartBrowserBetweenTests parameter to true and change the ignoreSynchronization value without any problems - but this slows down the tests significantly.

+10
javascript angularjs testing protractor end-to-end
Feb 14 '15 at 0:29
source share
2 answers

You can set ignoreSynchronization to false as soon as your check is complete. However, note that ignoreSynchronization is synchronous, and everything else (click / get / etc) is asynchronous, so you need to be careful with this. Probably the safest way is to set true to beforeEach and false to afterEach and just check that one logo clicked in this test.

+10
Feb 14 '15 at 1:45
source share

Another solution: I used sleep , since getWindowHandles was returning only one window name (parent / angular). Let me know if this is the best way.

 this.validateProductPageInfo = function (productTitle) { browser.sleep(5000); browser.getAllWindowHandles().then(function (handles) { if (handles.length === 2) { browser.switchTo().window(handles[1]).then(function () { var prodTitle = by.xpath('//h1[@id="fw-pagetitle"]'); browser.driver.findElement(prodTitle).getText().then(function (text) { expect(text).toBe(productTitle); }); }); browser.switchTo().window(handles[0]); } else { console.log("Error in switching to non angular window"); } }); }; 
+1
Nov 12 '15 at 15:57
source share



All Articles