How to store value from a table cell in Protractor?

时间:2016-04-04 17:14:41

标签: javascript angularjs protractor

I would like to store the value 'contractId' from the first row in the table, so when I add a contract it will use the this value plus 1 for an unique ID. When I try using the protractor test below, it returns "[object Object]1".

Here is the table:

<tbody>
           <tr data-ng-repeat="contract in vm.contract">
           <td data-ng-bind-html="contract.internalId"></td>
           <td data-ng-bind-html="contract.contractId"></td>
           <td data-ng-bind-html="contract.contractDescription"></td>
</tbody>

My current protractor test:

it('create contract', function(){
    var id = element.all(by.repeater('contract in contracts')).get(0).element(by.binding("contract.contractId")).getText();
    id = id + 1;
    element(by.cssContainingText('.submit-button', 'Add Contract')).click();
    element(by.model('vm.newContract.contractId')).sendKeys(id);
 });

1 个答案:

答案 0 :(得分:2)

Protractor is asynchronous. The result of getText() is a promise, not a string.

it('create contract', function(){
    var id = element.all(by.repeater('contract in contracts')).get(0).element(by.binding("contract.contractId")).getText();
    id.then(function(text) {
      text = text + 1;
      element(by.cssContainingText('.submit-button', 'Add Contract')).click();
      element(by.model('vm.newContract.contractId')).sendKeys(text);
    });
 });