2013-11-26 27 views
1

我正在使用Selenium的Ruby使用Selenium的Ruby Bindinds和Test :: Unit使用Selenium进行单元测试UI交互。它在很大程度上取得了成功,但我遇到了一个我无法工作的测试案例。我需要做的是等待表加载到页面上,然后点击sorting类的表头,记录表的第一行,并将其与第一行的单击后进行比较。跳过没有sorting类的标题,并确定所有可排序的标题是否在浏览器中工作。使用硒测试ui交互的问题

现在的问题。该测试未通过Selenium的assert_nothing_raised测试超时。哪里?我不知道。它参考[test_cases/tc_commodities.rb:6],但第6行是assert_nothing_raised do。由于测试从那开始,没有太多的信息。然后我通过删除代码开始在代码中缩小它的范围。问题出在columns.each循环中,这意味着wait.until块。这没有意义,因为我可以在超时期间看到页面上显示的标题。页面关闭,测试失败。我再次运行测试,停止执行并查看DOM。所有正确的元素都在那里并被显示出来。剧本有足够的时间来接他们。可以肯定,我把一个sleep 15。仍然超时等待显示标题。

  1. 为什么这个超时?我从来没有在页面上显示的项目没有问题,没有返回真正的.displayed?

  2. 这是测试用例的最佳方法吗?任何人都可以提出一个更好的解

失败的测试输出

$ ruby test_cases/tc_commodities.rb 
Run options: 

# Running tests: 

Column Found 
F 

Finished tests in 46.652411s, 0.0214 tests/s, 0.0214 assertions/s. 

    1) Failure: 
test__sort_columns_on_stories_table(TestCommodities) [test_cases/tc_commodities. 
rb:6]: 
Exception raised: 
<#<Selenium::WebDriver::Error::TimeOutError: timed out after 10 seconds>>. 

1 tests, 1 assertions, 1 failures, 0 errors, 0 skips 

硒码

def test__sort_columns_on_stories_table 
    assert_nothing_raised do 
     @browser.get 'some url' 
     @wait.until do 
      @browser.find_element(:css, "#dataTable tbody tr:nth-child(2)").displayed? 
     end 

     columns = @browser.find_elements(:css, "#dataTable thead th.sorting") 

     columns.each do |column| 
      puts "Column Found" 

      @wait.until do 
       column.displayed?     
      end 

      puts "Column Displayed" 

      first_story_before = @browser.find_element(:css, "#dataTable tbody tr:nth-child(1)").attribute('id') 
      column.click 
      first_story_after = @browser.find_element(:css, "#dataTable tbody tr:nth-child(1)").attribute('id') 

      assert_not_equal(first_story_after, first_story_before) 
     end 
    end 
end 

编辑

我使用的是Chrome和杉木efox Web驱动程序。两者都有同样的问题。我可以为column.displayed?删除wait.until,但是当它清楚时,它会抛出一个错误,它在页面上不显示。

回答

0

我也面临类似的问题TimeTime out异常等待页面加载。但该页面已完全加载。

您正在使用哪种浏览器?如果它的IE,IEDriverServer的版本是什么?

+0

你能告诉我你正在使用哪种浏览器吗?如果它的IE,哪个版本的IEDriverServer? – user2680325

+0

我使用的是Chrome和Firefox Web驱动程序。两者都有同样的问题。我可以为'column.displayed?'删除'wait.until',但是当它抛出一个错误时,它显示在页面上时不显示。 – Kylee