如何在Protractor中获取转发器内的绑定文本

时间:2015-10-20 14:34:30

标签: angularjs selenium-webdriver jasmine protractor

使用此example web,如何使用量角器获取{{result.first}}的值?那个在转发器里面,所以我无法通过绑定来访问它。

这是我想要使用该值的示例。

<div ng-controller="CalcCtrl" class="container">
    <div>
      <h3>Super Calculator</h3>
      <form class="form-inline">
        <input ng-model="first" type="text" class="input-small"/>
        <select ng-model="operator" class="span1"
                ng-options="value for (key, value) in operators">
        </select>
        <input ng-model="second" type="text" class="input-small"/>
        <button ng-click="doAddition()" id="gobutton" class="btn">Go!</button>
        <h2>{{latest}}</h2>
      </form>
    </div>
    <h4>History</h4>
    <table class="table">
      <thead><tr>
        <th>Time</th>
        <th>Expression</th>
        <th>Result</th>
      </tr></thead>
      <tr ng-repeat="result in memory">
        <td>
          {{result.timestamp | date:'mediumTime'}}
        </td>
        <td>
          <span>{{result.first}}</span>
          <span>{{result.operator}}</span>
          <span>{{result.second}}</span>
        </td>
        <td>{{result.value}}</td>
      </tr>
    </table>
</div>

这是Protractor代码:

describe('Protractor Demo App', function() {
  var firstNumber = element(by.model('first'));
  var secondNumber = element(by.model('second'));
  var goButton = element(by.id('gobutton'));
  var latestResult = element(by.binding('latest'));
  var history = element.all(by.repeater('result in memory'));

  function add(a, b) {
    firstNumber.sendKeys(a);
    secondNumber.sendKeys(b);
    goButton.click();
  }

  beforeEach(function() {
    browser.get('http://juliemr.github.io/protractor-demo/');
  });

  it('should have a history', function() {
    add(1, 2);
    add(3, 4);

    expect(history.count()).toEqual(2);
  });
});

1 个答案:

答案 0 :(得分:3)

在量角器的APIrepeaters

中阅读更多内容
element.all(by.repeater('result in results')).first()
element.all(by.repeater('result in results')).get(0)

两者都将返回第一个结果,对于其中的每个元素,将其与element.all(by.repeater('result in results')).first().element...

链接