【发布时间】:2018-03-14 20:22:30
【问题描述】:
我是 Protractor 的新手,正在尝试为一个非常简单的场景编写测试用例:转到登录页面并提交表单,重定向到仪表板页面,然后单击仪表板上的搜索按钮。部分登录工作正常:
pages/login.js:
'use strict';
var LoginPage = function () {
this.email = element(by.css('#email'));
this.password = element(by.css('#password'));
this.submit = element(by.css('[type="submit"]'));
expect(this.email.isPresent()).toBe(true, 'Email field not found');
expect(this.password.isPresent()).toBe(true, 'Password field not found');
expect(this.submit.isPresent()).toBe(true, 'Submit button not found');
};
module.exports = new LoginPage();
test-spec.js:
it('should log in', function () {
console.log('Logging into Application.');
browser.get('https://example.com/auth/login');
var loginPage = require('./pages/login');
loginPage.email.sendKeys('myemail@example.com');
loginPage.password.sendKeys('mypassword');
loginPage.submit.click();
console.log('Waiting to be redirected to the dashboard page...');
return browser.driver.wait(function () {
return browser.driver.getCurrentUrl().then(function (url) {
return /dashboard/.test(url);
});
}, 30000);
});
但是,当我尝试找到搜索按钮并单击它时...
pages/dashboard.js:
'use strict';
var DashboardPage = function () {
var elementFromSecondPage = $('a[href*="/property/search"]');
console.log('trying to wait for element to be visible: ' + elementFromSecondPage);
browser.wait(protractor.until.elementIsVisible(elementFromSecondPage), 60000, 'Error: Element did not display within 1 minute');
console.log('done waiting');
console.log('trying to find this.search element');
this.search = element(by.css('a[href*="/property/search"]'));
console.log('this.search: ' + this.search);
expect(this.search.isPresent()).toBe(true, 'Search button not found');
};
module.exports = new DashboardPage();
test-spec.js:
it('should go to search', function () {
console.log('Going to the Search page.');
var dashboardPage = require('./pages/dashboard');
dashboardPage.search.click();
});
当试图找到搜索按钮时,它会出错:
登录上游。
正在等待重定向到仪表板页面...
转到“搜索”页面。
试图等待元素可见:[object Object]
等待完成
试图找到 this.search 元素
this.search: [object 对象]
失败:1)angularjs上游添加列表应该去搜索消息:失败:超时等待异步Angular任务在11秒后完成。这可能是因为当前页面不是 Angular 应用程序。请参阅常见问题解答以获取更多详细信息:https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular While waiting element with locator - Locator: By(css selector, a[href*="/property/search"])
这是我要搜索的元素的 html:
<a routerlinkactive="active" class="caret rpr-labeled-button rpr-labeled-button-search-alt active" href="/property/search">
...
</a>
我尝试了多种不同的解决方案来尝试等待仪表板页面及其 DOM 加载,但无论如何我仍然收到此错误。这很令人困惑,因为如果您查看上面的输出,当我执行 jQuery 时会发现它成功加载了元素,所以它显然就在那里。
【问题讨论】:
标签: angular protractor