案例我尝试测试: 在 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
如何实现?谢谢!
最佳答案
你需要做两件事
- 在尝试读取第 3 方页面的 URL 之前设置
browser.ignoreSynchronization = true;
,这样浏览器就不会等待(因此需要)Angular promise 在页面中解析(然后将其设置为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;
});
关于javascript - Protractor :获取非 Angular 页面的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29952764/