量角器:得到没有角度页面的网址

时间:2021-01-07 01:23:02

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

案例我尝试测试:在Angular app page按下按钮,将您重定向到其他某个站点(不是Angular应用程序)。

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

UnknownError:未知错误:未定义角度

How that can be achived? Thanks!

如何实现?谢谢!

2 个解决方案

#1


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);
  • 设置browser.ignoreSynchronization = true;在尝试读取第三方页面的URL之前,浏览器不会等待(并因此要求)Angular承诺在页面中解析(并在之后将其设置为false);

  • 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.
  • 使用browser.getCurrentUrl()而不是browser.getLocationAbsUrl(),因为前者只使用普通的webdriver方法来读取URL,而不是通过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;
});

#2


2  

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

您需要调整ignoreSynchronization标志 - 在单击链接之前将其设置为true,并在afterEach()中将其设置为false:

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.

您可能还需要等待URL更改,例如此处。

#1


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);
  • 设置browser.ignoreSynchronization = true;在尝试读取第三方页面的URL之前,浏览器不会等待(并因此要求)Angular承诺在页面中解析(并在之后将其设置为false);

  • 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.
  • 使用browser.getCurrentUrl()而不是browser.getLocationAbsUrl(),因为前者只使用普通的webdriver方法来读取URL,而不是通过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;
});

#2


2  

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

您需要调整ignoreSynchronization标志 - 在单击链接之前将其设置为true,并在afterEach()中将其设置为false:

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.

您可能还需要等待URL更改,例如此处。