我在Protractor中有一个测试用例,它加载主页,然后单击一个重定向到另一个页面的按钮。在那个其他页面中,我想要获取元素的值。
describe('todo list', function() {
it('should find the contact phone number from the home page', function() {
browser.get('http://homepage...');
element(by.id('re_direct_to_contact_page')).click();
var number = element(by.id('phonenumber')).getText();
expect(number).toEqual('412-....-...');
});
});
然而,虽然它加载页面但它不检查元素值,并且测试用例失败。
量角器如何加载另一页以检查值?
注意: - 我编写了这个示例,但在我的实际测试用例中,我将数据从一个页面发送到另一个页面,因此我无法直接加载我想要的页面。
编辑:堆栈跟踪
protractor conf.js使用selenium服务器 在http://localhost:4444/wd/hub [launcher]运行1个实例 的webdriver
错误:等待Protractor与页面同步时出错: “[ng:test] http://errors.angularjs.or/1.4.0/ng/test”
StackTrace:未定义
1次测试,1次断言,1次失败
答案 0 :(得分:1)
您可能面临时间问题。尝试重新构建您的测试:
var number = element(by.id('phonenumber')).getText();
expect(number).toEqual('412-....-...');
对此:
expect(element(by.id('phonenumber')).getText()).toEqual('412-....-...');
虽然Jasmine和Protractor试图在继续之前解决每一个承诺,但有时它并没有像你想的那样快。将整个承诺链置于期望中有助于在通过匹配器之前强制执行所有这些决策。