6

Case I try to test: On Angular app page press button, that redirects you to some other site (not an Angular app).

it('should go to 3d party  service when i click "auth" button' , function() {

    browser.driver.sleep(3000);
    element(by.id('files-services-icon')).click();
    element(by.id('box-vendor-menu-item')).click();
    browser.driver.sleep(2000);

    expect( browser.driver.getLocationAbsUrl()).toContain('https://app.box.com/api/oauth2/authorize');
});

but I get:

UnknownError: unknown error: angular is not defined

How that can be achived? Thanks!

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
paka
  • 1,601
  • 22
  • 35

2 Answers2

8

You need to do 2 things

  • Set browser.ignoreSynchronization = true; before trying to read the URL of the 3rd party page, so the browser doesn't wait for (and so require) Angular promises to resolve in the page (and set it to false afterwards);
  • Use browser.getCurrentUrl() as opposed to browser.getLocationAbsUrl(), as the former just uses the plain webdriver method of reading the URL, rather than accesing it via Angular.

The following should work:

it('should go to 3d party  service when i click "auth" button' , function() {    
  element(by.id('files-services-icon')).click();
  element(by.id('box-vendor-menu-item')).click();
  browser.ignoreSynchronization = true;
  expect(browser.getCurrentUrl()).toContain('https://app.box.com/api/oauth2/authorize');
  browser.ignoreSynchronization = false;
});
Michal Charemza
  • 25,940
  • 14
  • 98
  • 165
2

You need to tweak ignoreSynchronization flag - set it to true before clicking on the link and set back to false in afterEach():

afterEach(function () {
    browser.ignoreSynchronization = false;
});

it('should go to 3d party  service when i click "auth" button' , function() {    
    element(by.id('files-services-icon')).click();

    browser.ignoreSynchronization = true;
    element(by.id('box-vendor-menu-item')).click();

    expect(browser.getLocationAbsUrl()).toContain('https://app.box.com/api/oauth2/authorize');
});

See also:

You may also need to wait for URL to change, example here.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • thank you for explanation, but this also return the same error `UnknownError: unknown error: angular is not defined` – paka Apr 30 '15 at 06:24