量角器在重复中找到项目并单击它

时间:2018-02-19 12:26:03

标签: angularjs protractor

我试图在转发器中找到一个名字的发言人。然后找到发言者点击编辑按钮。

到目前为止我的测试失败了:(。任何人都有领先优势?

查看:

<div ng-repeat="speaker in $ctrl.speakers">
  <div class="name" ng-bind="speaker.name"></div>
  <button name="editbutton" title="edit" ng-click="$ctrl.onEdit(speaker)"></button>
</div>

Protractortest:

it('should remove Bill Gates', async function () {
    await browser.get(speakerLink); //url to page
    await browser.driver.sleep(200);

    let speakers = await element.all(by.repeater('speaker in $ctrl.speakers'));
    await speakers.isPresent();

    await speakers.then(function (speakers) {
        let description = element(by.model('speaker.name'));
        if (description.getText() == ('Bill Gates')) {
            await element(by.name('editbutton')).click();
        }
    });
    await browser.driver.sleep(5000);
});

量角器错误

量角器因错误

而失败
    await element(by.name('editbutton')).click();  
          ^^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)    at Module._compile (module.js:588:28)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at C:\Users\ralf\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine\lib\jasmine.js:93:

更多信息

运行节点v8.6.0

使用普通的香草javascript(暂时,计划转移到typescript / webpack)

1 个答案:

答案 0 :(得分:1)

这可能不是最好的解决方案,但这是我实现同样的事情并且它工作得很好。我希望这会有所帮助。

  this.openCategory = function (category) {
element.all(by.repeater('page in section.pages')).then(function (rows) {
  rows.some(function (row) {
    row.getText().then(function (value) {
      if (value === category) {
        log.info('[PASS] - Category:' + ' ' + category + ' ' + 'matched the value:' + ' ' + value + ', ' + 'that is shown on UI.');
        row.click()
          .then(function (value) {
            log.info('[PASS] - Category:' + ' ' + category + ', ' + 'clicked.');
          });
      }
    });
  });
});