量角器:获取第 url 个非 angular 页
Protractor: get url of not angular page
案例我尝试测试:
在 Angular 应用程序页面上按下按钮,将您重定向到其他网站(不是 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');
});
但我得到:
UnknownError: unknown error: angular is not defined
如何实现?谢谢!
您需要调整 - 在单击 link 之前将其设置为 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');
});
另请参阅:
您可能还需要等待 URL 更改,。
你需要做两件事
- 在尝试读取第 3 方页面的 URL 之前设置
browser.ignoreSynchronization = true;
,这样浏览器就不会等待(因此需要)Angular promises 在页面中解析(然后将其设置为 false
);
- 使用
browser.getCurrentUrl()
而不是 browser.getLocationAbsUrl()
,因为前者只是使用普通的 webdriver 方法读取 URL,而不是通过 Angular 访问它。
以下应该有效:
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;
});
案例我尝试测试: 在 Angular 应用程序页面上按下按钮,将您重定向到其他网站(不是 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');
});
但我得到:
UnknownError: unknown error: angular is not defined
如何实现?谢谢!
您需要调整 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');
});
另请参阅:
您可能还需要等待 URL 更改,
你需要做两件事
- 在尝试读取第 3 方页面的 URL 之前设置
browser.ignoreSynchronization = true;
,这样浏览器就不会等待(因此需要)Angular promises 在页面中解析(然后将其设置为false
); - 使用
browser.getCurrentUrl()
而不是browser.getLocationAbsUrl()
,因为前者只是使用普通的 webdriver 方法读取 URL,而不是通过 Angular 访问它。
以下应该有效:
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;
});