【发布时间】:2017-01-10 14:45:12
【问题描述】:
我的场景如下所示: 1.打开登录页面 2.输入用户名, 3.输入密码, 4.点击登录, 5. 角色选择模式打开,列出可能的用户角色 6. 点击第一个角色。
我的测试是这样的:
'use strict';
describe('Login page', function () {
beforeEach(function () {
browser.get('/#/login');
});
it('should login', function () {
var _user = element(by.model('loginForm.exchange.user'));
var _pass = element(by.model('loginForm.exchange.password'));
var loginButton = element(by.xpath('/html/body/snap-content/ui-view/div/section/content/div/div/div[2]/div/form/button'));
_user.sendKeys('myUsername');
_pass.sendKeys('myPassword');
loginButton.click();
var _roleModal = by.className('modal-dialog');
browser.driver.wait(function () {
return browser.driver.isElementPresent(_roleModal);
}, 5000)
.then(function () {
browser.driver.sleep(3000);
console.log('modal now opened.');
var _elementInModal = by.css('[ng-click="cancel()"]');
browser.driver.wait(function () {
return browser.driver.isElementPresent(_elementInModal);
}, 1000)
.then(function () {
browser.driver.sleep(2000);
console.log('element present.');
// issue here being, I can't access the roles listed in modal, even though I've created a check if the button with cancel() exists in modal itself.
// using by.xpath('/html/body/div[5]/div/div/form/div/div/div/div/ul/li[1]') to fetch 1st role doesn't work either.
element.all(by.repeater('role in userRoles')).then(function (role) {
console.log('HUEY! ROLE!', role);
var titleElement = role[0].element(by.css('media-body'));
console.log(titleElement);
});
});
});
}, 30000);
});
在谈论模态时请记住,这是引导模态 (https://angular-ui.github.io/bootstrap/)。
模态模板:
<div ng-switch-when="userRoles">
<div class="card">
<ul class="table-view" >
<li ng-repeat="role in userRoles" class="table-view-cell" ng-click="save(role)">
<a class="navigate-right">
<div class="media-body">
{{role.LTEXT}}
</div>
</a>
</li>
</ul>
</div>
</div>
这几天让我发疯。我似乎无法从现有模式中选择角色。即使使用节点调试工具从 VSCode 进行调试,无论我选择哪个 *,我都无法打印出任何内容。
【问题讨论】:
-
有错误吗?仅供参考,如果您只想要
.all方法中的第一项,您可以使用函数 .first() 而不是对其进行索引。 -
感谢您的评论。我在 31 秒后收到超时错误(在测试的最后一行设置)
-
@gregor 请注意,您可能打算使用
.media-bodyCSS 选择器而不是media-body。 -
你得到了什么输出,你看到
HUEY! ROLE!打印了吗? -
@alecxe 我没有从那部分得到任何输出。没有“休伊!角色!”。最后一个控制台日志是“元素存在”。此外,将 media-body 更改为 .media-body 或使用 by.className 也没有带来任何好处。
标签: javascript angularjs protractor angularjs-e2e