Protractor: get the url of the angular page

The case I'm trying to verify: On the Angular application page, click the button that redirects you to another site (and not the Angular application).

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 can this be achieved? Thanks!

+6
source share
2 answers

You need to do 2 things

  • Set browser.ignoreSynchronization = true; before trying to read the third-party URL, so the browser does not wait (and therefore requires) Angular promises for permission on the page (and set it to false afterwards);
  • Use browser.getCurrentUrl() as opposed to browser.getLocationAbsUrl() , since the former simply uses the simple webdriver method to read the URL and not access it through 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; }); 
+7
source

You need to configure the ignoreSynchronization flag - set it to true before clicking on the link and returning 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 change the URL here .

+2
source

Source: https://habr.com/ru/post/986250/


All Articles