2012-01-16 4 views
0

누가 루비, 오이 & 셀레늄을 사용하여 테이블의 항목 수를 계산하는 빠른 방법을 알고 있습니까? Cucumber + Selenium - 테이블의 행 수를 계산하는 방법?

상당히 기본, 나는 행의 수를 계산하려면 :

<table id="product_container"> 
<tr> 
    <th>Product Name</th> 
    <th>Qty In Stock</th> 
</tr> 
<tr> 
    <td>...</td> 
    <td>...</td> 
</tr> 
</table> 

답변

3

당신은 사용할 수 있습니다

$rowsCount = $this->getXpathCount("//table[@id='product_container']/tr");

을 그리고 당신이 아닌 경우 헤더 행을 계산하려면 표를 다음과 같이 수정해야합니다.

<table id="product_container"> 
    <thead> 
     <tr> 
      <th>Product Name</th> 
      <th>Qty In Stock</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>...</td> 
      <td>...</td> 
     </tr> 
    </tbody> 
</table> 

그럼 제품 수를 얻을 수 있습니다 :

$rowsCount = $this->getXpathCount("//table[@id='product_container']/tbody/tr");
2

다음 단계 정의는 카피 바라와 함께 작동합니다.

Then /^I should have (\d+) table rows$/ do |number_of_rows| 
    actual_number = page.all('#product_container tr').size 
    actual_order.should == number_of_rows 
end 

사용법 :

Then I should have 10 table rows 

page.all documentation.

page.should have_css "#product_container tr", :count => number_of_rows.to_i 
1

난 항상 이러한 상황에서 getXpathCount() (셀레늄 방법) 사용하고는 PHP에서 좋은 :)
작동 :

관련 문제