1

I used following step-definition with cucumber and webrat and everything worked fine:

Then /^I should see "([^\"]*)" worker in the workerlist/ do |number|
   response.should have_selector("td.worker_name", :count=>number)
end

I have moved now to selenium and "somehow" the have_selector doesn't take a :count parameter anymore. I get following error:

ArgumentError: wrong number of arguments (2 for 1)   
./features/step_definitions/worker_generation_steps.rb:15:in `have_selector'

Next I tried to use assert_contain, but I couldn't find a regex that checks the exact number. Unfortunately, following step definition passes if the number of "class="worker_name"" is less than the expected number.

Then /^I should see "([^\"]*)" worker in the workerlist/ do |number|
  assert_contain (/((.*)(class="worker_name"))#{number}/m)
end

My questions:

1.) How could I check the easiest way that in my example "td.worker_name" appears exactly a number of times?

2.) If there is no way around regex: How could I rewrite the regex above so that it checks the exact number of "class="worker_name""?

Thanks a lot!

4

2 に答える 2

0

AutomatedTester の回答のおかげで、次の実用的なソリューションが見つかりました。

Then /^I should see "([^\"]*)" worker in the workerlist/ do |number|
    response.selenium.get_xpath_count("//td[@class='worker_name']").to_i.should be(number.to_i)
end

get_xpath_count は Webrat::Selenium:Matchers によって直接サポートされていませんが、基礎となる Selenium API を介してアクセスできました。

于 2010-03-03T15:41:09.380 に答える
0

Ruby や Webrat の経験はありませんが、私が行う方法は次のとおりです。

    begin
        assert_equal "2", @selenium.get_xpath_count("//td[@class='worker_name']")
    rescue Test::Unit::AssertionFailedError
        @verification_errors << $!

これは、クエリで xpath カウントを実行し、それが 2 であることを確認することです。現時点では、Selenium 2 を使用しない限り、Selenium および CSS セレクターでそれを行うことはできません。

于 2010-03-01T10:05:22.673 に答える