我正在尝试针对我的本地服务器运行e2e测试并测试生成的url(在单击导航按钮之后)是正确的结果.但是,生成的url始终为false.
我的代码如下所示:
HTML:
//http://localhost/#/current_Page
<html>
<head><title></title></head>
<body>
//should change the current url to
//http://localhost/#/new_page
<button class="button" ng-click="change_page()">Change Page</button>
</html>
Run Code Online (Sandbox Code Playgroud)
测试代码:
var protractor = require('protractor');
require('protractor/jasminewd');
describe('Tests', function() {
var ptor;
describe('Test 1', function() {
var ptor = protractor.getInstance();
ptor.get('#/current_page');
it('change page and current url', function() {
ptor.findElement(protractor.By.className('.button').click().then(function() {
expect(ptor.currentUrl()).toContain('#/new_page');
});
});
}, 30000);
});
Run Code Online (Sandbox Code Playgroud)
问题是单击按钮后的当前URL仍为#/ current_url,并且未更改为预期结果#/ new_page.
有谁知道我哪里出错了?
在之前的问题中,我已经看到等待url更改的好方法是使用:
browser.wait( function() {
return browser.getCurrentUrl().then(function(url) {
return /myURL/.test(url);
});
}, 10000, "url has not changed");`
Run Code Online (Sandbox Code Playgroud)
但我试图有一个方法,我可以将myURL作为变量传递(如果我需要将其与其他网站一起使用)并且无法正常工作.
我在我的Page Object文件中尝试这个:
this.waitUrl = function(myUrl) {
browser.wait( function(myUrl) {
return browser.getCurrentUrl().then(function(url, myUrl) {
return myUrl.test(url);
});
}, 10000, "url has not changed");
};
Run Code Online (Sandbox Code Playgroud)
如果这是可能的任何想法,如果这样做怎么办?
案例我尝试测试:在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:未知错误:未定义角度
如何实现?谢谢!
protractor ×3
angularjs ×2
javascript ×2
testing ×2
asynchronous ×1
automation ×1
end-to-end ×1