如何在量角器测试使用browser.getCurrentUrl()? [英] How to use browser.getCurrentUrl() in a protractor test?
问题描述
我一直在努力与当今量角器code的这些行:
元素(by.linkText(人物))点击()。
browser.waitForAngular();
VAR URL = browser.getCurrentUrl();
...
看来, getCurrentUrl
时放在 waitForAngular()
语句之后总是失败。
错误输出太含糊:
不明错误:JavaScript错误:在等待结果的文件卸载
块引用>那么,什么是点击超链接,并检查新网址的正确方法?
下面是我的测试:
如果我
getCurrentUrl()
链接被点击之前,它('可以访问网页的人',函数(){
VAR URL = browser.getCurrentUrl();
。元素(by.linkText(人物))点击();
期待(真).toBe(真);
});该测试将通过。
如果我
getCurrentUrl()
链接被点击之后,它('可以访问网页的人',函数(){
VAR URL = browser.getCurrentUrl();
。元素(by.linkText(人物))点击();
期待(真).toBe(真);
URL = browser.getCurrentUrl();
});这是错误抛出量角器与
不明错误
上面的输出。出了什么问题?解决方案而不是的
呼叫的等待URL修改的waitForAngular()
browser.wait(函数(){
返回browser.getCurrentUrl()。然后(函数(URL){
返回/index/.test(url);
});
},10000,网址没有改变);最初由@juliemr在不明错误提示:JavaScript错误:在等待结果文件卸载
I have been struggling with these lines of Protractor code today:
element(by.linkText("People")).click(); browser.waitForAngular(); var url = browser.getCurrentUrl(); ...
It appears that
getCurrentUrl
always fails when placed after awaitForAngular()
statement.The error output is too vague:
UnknownError: javascript error: document unloaded while waiting for result
So, what is the correct way to click on a hyperlink and check the new url?
Here are my tests:
If I
getCurrentUrl()
before the link is clicked,it('can visit people page', function () { var url = browser.getCurrentUrl(); element(by.linkText("People")).click(); expect(true).toBe(true); });
The test will pass.
If I
getCurrentUrl()
after the link is clicked,it('can visit people page', function () { var url = browser.getCurrentUrl(); element(by.linkText("People")).click(); expect(true).toBe(true); url = browser.getCurrentUrl(); });
An error is thrown in Protractor with the
UnknownError
output above. What went wrong?解决方案Instead of
waitForAngular()
call, wait for the URL to change:browser.wait(function() { return browser.getCurrentUrl().then(function(url) { return /index/.test(url); }); }, 10000, "URL hasn't changed");
Originally suggested by @juliemr at UnknownError: javascript error: document unloaded while waiting for result.
这篇关于如何在量角器测试使用browser.getCurrentUrl()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!