pak*_*aka 6 javascript testing end-to-end angularjs protractor
案例我尝试测试:在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');
});
Run Code Online (Sandbox Code Playgroud)
但我得到:
UnknownError:未知错误:未定义角度
如何实现?谢谢!
你需要做两件事
browser.ignoreSynchronization = true;在尝试读取第三方页面的URL之前设置,因此浏览器不会等待(并且需要)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;
});
Run Code Online (Sandbox Code Playgroud)