Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor: get url of not angular page

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!

like image 747
paka Avatar asked Apr 29 '15 19:04

paka


People also ask

How does a protractor handle non-Angular pages?

Protractor works well on non-AngularJS pages as well. The first step is to set browser. ignoreSynchronization = true; inside the beforeEach() block in the spec file, to signal Protractor not to wait for Angular components to load.

How do you use a protractor to find a URL?

If you want to just check the current URL, then use browser. getCurrentUrl() : expect(browser. getCurrentUrl()).

Can I use protractor without Angular?

Protractor is a test framework for web applications. Even though its primary use is for performing end-to-end testing in Angular and AngularJS applications, you can also use it for regular, non-Angular websites.

Does protractor support Angular?

Now protractor supports both angular and Non-Angular applications. The protractor is wrapper written on top of Webdriver. js, all the features which are supported in Selenium Webdriver are supported by it, in addition to angular specific features. WebDriverJs is the Official javascript implementation of selenium.


1 Answers

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;
});
like image 125
Michal Charemza Avatar answered Oct 15 '22 13:10

Michal Charemza