开发者

Capybara/Selenium/Chrome not able to change value of select drop-down

开发者 https://www.devze.com 2023-04-01 12:40 出处:网络
When I run my test with the features, steps, and HTML below the test executes without error (until it fails on the assertion steps), but I can see that no change occurs to the drop-down selects.What a

When I run my test with the features, steps, and HTML below the test executes without error (until it fails on the assertion steps), but I can see that no change occurs to the drop-down selects. What am I doing wrong?

HTML:

<div class='field'> 
  <label for="verification_value">Verification Number</label> 
  <input id="verification_value" type="text" /> 
</div> 
<div class='field'> 
  <label for="month">Month</label> 
  <select id="month"> 
    <option value="1">1 - January</option> 
    <option value="2">2 - February</option> 
    <option value="3">3 - March</option> 
    <option value="4">4 - April</option> 
    <option value="5">5 - May</option> 
    <option value="6">6 - June</option> 
    <option value="7">7 - July</option> 
    <option value="8">8 - August</option> 
    <option value="9">9 - September</option> 
    <option value="10">10 - October</option> 
    <option value="11">11 - November</option> 
    <option value="12">12 - December</option> 
  </select> 
 </div>

step:

When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
  select(value, :from => field)
end

feature:

Feature: In order for this to work, a select menu should be changeable

    @javascript
    Scenario: A user follows the steps to successfully do fun stuff
        Given I go to a  page
        And I fill in "verification_value" with "12345"
        And I select "2 - February" from  "month"
        Then I should see "everything worked" within "body"

And I select "2" from "month" doesn't开发者_如何学JAVA actually produce any errors, it just doesn't change the select option. It should be setting the select to 2 - February

I also tried it with the firefox driver, and I get the same result

Update

Concerning the regex I added a puts line, and it was indeed ran

When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
  puts "STEP MATCHED"   # << it did put "STEP MATCHED"
  select(value, :from => field)
end

I copied that from the default web_steps.rb so I'm surprised it's not working for some people, but works fine for me.


It looks like you have an extra double quote in the SELECT tag. That may be causing the problem.


I haven't tried your code, and I don't really have time to right now, but you might consider testing that regular expression. If you're trying to avoid requiring the "I" in that step definition, I'd recommend doing this:

When /^(?:I )?select "([^"]*)" from "([^"]*)"$/ do |value, field|
  select(value, :from => field)
end

The question-mark after a capture group (denoted by parentheses) implies that the contents of the capture group is optional. That might help it identify the step if the prior answer is any indication as to why it's not working.

0

精彩评论

暂无评论...
验证码 换一张
取 消