2015-08-20 43 views
1

我有一个测试案例在量角器中加载主页,然后单击一个按钮重定向到另一个页面。在其他页面中,我想获取元素的值。量角器 - 改变页面/视图

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 Using the selenium server at http://localhost:4444/wd/hub [launcher] Running 1 instances of WebDriver

Error: Error while waiting for Protractor to sync with the page: "[ng:test] http://errors.angularjs.or/1.4.0/ng/test "

StackTrace: undefined

1 test, 1 assertion, 1 failure

+0

测试用例现在如何失败?请提供堆栈跟踪。 – alecxe

+0

@alecxe更新了堆栈跟踪。 – BDillan

+0

纠正我,如果我错了,联系页面是一个非角度页面? – alecxe

回答

1

这是可能的,你可能会面临一个时间问题。尝试重新构建您的测试从这个:

var number = element(by.id('phonenumber')).getText(); 
    expect(number).toEqual('412-....-...'); 

要这样:

expect(element(by.id('phonenumber')).getText()).toEqual('412-....-...'); 

虽然茉莉花和量角器尝试解决在移动之前每一个承诺,有时不尽快你会怎样喜欢。将整个承诺链纳入期望有助于在通过匹配器之前强制执行所有承诺链的解决方案。

+0

不会更改任何内容:/ – BDillan

+0

您是否已验证您的元素是否在您的定位器中找到? – MBielski

+0

我该如何验证? – BDillan