2016-06-13 27 views
2

是否可以使用應存在於表格單元格中的精確值在ng-repeat內定位表格行?量角器:定位匹配單元格值的表格行

我知道我可以檢索使用此語法特定列:

element(by.repeater('customer in vm.customers').row(0).column('customer.name') 

在我的情況,我不知道該指數是什麼呢。

所以說我是一個典型的表聲明,如下所示:

<table> 
    <tr ng-repeat="customer in customers"> 
     <td> 
      {{customer.firstName}} 
     </td> 
     <td> 
      {{customer.lastName}} 
     </td> 
    </tr> 
</table> 

而且我得到以下輸出

<table> 
    <tr> 
     <td> 
      Bob 
     </td> 
     <td> 
      Smith 
     </td> 
    </tr> 
    <tr> 
     <td> 
      James 
     </td> 
     <td> 
      Tulley 
     </td> 
    </tr> 
</table> 

有一個定位,我可以用說讓我行包含鮑勃史密斯? 我知道這是不漂亮,但這樣的:

element(by.repeater('customer in vm.customers').column('customer.firstName=James').column('customer.lastName=James') 

我的使用情況是在表單視圖編輯一條記錄之後,用戶被髮送回表視圖,在這我要檢查的值確實已更新。

是否有任何有用的食譜\方法可以幫助在這裏?

回答

0

你可以使用XPath相匹配的中繼器,並從該行通過一個調用文字:

element(by.xpath("//tr[@ng-repeat='customer in customers'][normalize-space(.)='Bob Smith']")) 
+0

確定不完全是我的初衷,是希望的東西用量角器定位器樣式更具可讀性句法!無論如何,我會好奇心地嘗試一下。謝謝 – mindparse

+0

當你需要匹配一些文本時,XPath是一種方法。當然,你可以用'element(by.repeater('customer in vm.customers')')獲取所有行,然後用'.filter(e => e.getText(v => v =='Bob Smith '))',但它會更加昂貴和難以維護。 –

-2

看看我的量角器代碼實驗室。我有一個練習,做一些非常相似的事情。下面是代碼:https://github.com/andresdominguez/protractor-codelab/blob/ex3-solution/spec/list-helper.js#L13

而且測試的樣子:

it('should add user', function() { 
    var name = 'test name ' + uniqueId; 
    var email = 'foo' + uniqueId + '@gmail.com'; 
    var phone = '212-555-0000'; 

    userList.addUserButton.click(); 

    userProperties.name.sendKeys(name); 
    userProperties.email.sendKeys(email); 
    userProperties.phone.sendKeys(phone); 
    userProperties.saveButton.click(); 

    expect(userList.list.getUsersByName(name)).toEqual([{ 
    name: name, 
    email: email, 
    phone: phone 
    }]); 
}); 

見測試:https://github.com/andresdominguez/protractor-codelab/blob/ex3-solution/spec/ex3-solution-spec.js#L13

相關問題