【发布时间】:2016-11-22 05:10:15
【问题描述】:
我正在使用 Protractor 和 Cucumber 来编写一些测试,但我在某些时候遇到了困难。在登录后的步骤中,我使用量角器提供的 browser.get(url) 函数重新路由到另一个页面。但它总是在页面完全加载之前返回。到目前为止,我已经尝试了很多解决方案,但没有运气。我已经尝试过 browser.wait, browser.get(url).then(function(){ // 加载时的代码}) 但我得到了 0 个积极的结果。
这是我的代码:
// Steps will be implemented here
this.Given(/^I am logged in as user \'([^\']*)\'$/, function (user, callback) {
console.log('USER: ' + user);
browser.driver.get('https://cit-was70-l06/ipa')
browser.driver.findElement(by.xpath('my_xpath')).sendKeys(user);
browser.driver.findElement(by.xpath('my_xpath')).sendKeys(user);
browser.driver.findElement(by.xpath('my_xpath')).click().then(callback);
});
this.Then(/^The screen is shown, with title \'([^\']*)\'$/, function (title, callback) {
console.log('Title from feature file: ' + title);
var url = 'some/url/in/application/';
browser.get(url).then(function(){
// This portion executes before page is completely loaded.
// So if I try to get any element, it throws me an error.
// [15:32:13] E/launcher - "process.on('uncaughtException'" error, see
// launcher
// [15:32:13] E/launcher - Process exited with error code 199
// It works if I add static delay to wait for page load completely
// but that will not be a good solution if I have too much pages to test
callback();
});
console.log('After page laoad');
});
任何建议的解决方法将不胜感激。
【问题讨论】:
标签: angularjs node.js asynchronous protractor cucumberjs