Не удается найти элемент для нажатия с помощью Capybara + Rails3

Фон:Я использую Capybara с Rspec для тестирования приложения Rails 3. Используемый драйвер:Селен

Проблема: Я не могу найти кнопку «Войти», чтобы нажать на нее в моем тесте.

HTML-код:

<form accept-charset="UTF-8" action="/" class="filter_form" id="login" method="post">
        <fieldset>
          <div class="modal-body">
            <div class="clearfix login-fields">
              <label for="user_email">Email</label>
              <div class="input login-inputs">
                <input class="input-text" id="user_email" name="user[email]" placeholder="email" size="30" type="email" value="">
              </div>
            </div>
            <div class="clearfix login-fields">
              <label for="user_password">Password</label>
              <div class="input login-inputs">
                <input class="input-text" id="user_password" name="user[password]" placeholder="password" size="30" type="password">
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <input class="btn btn-primary login_btn" id="btn_login" name="commit" type="submit" value="Sign in">
            <a href="/lms/forgot_password" class="btn">Forgot password...</a>
            <a href="#" class="btn close cancel" data-dismiss="modal">Cancel</a>
          </div>
        </fieldset>
</form>

Неудачный тест

it "should login correctly if the right credentials are given", :js => true do

    Capybara.default_wait_time = 5
    Capybara.reset_sessions!
    visit '/'
    click_link('login_link') #this will bring a modal window with the code posted above using js
    within("#login") do
      fill_in 'user_email', :with => "my-email@example.com"
      fill_in 'user_password', :with => "mypwd"
    end

    response.should have_selector('input#btn_login') #This passes
    click_on("input#btn_login") #Here it fails, saying it can't find an element with that selector
    response.should have_selector(:xpath, '//div[@class="alert-message block-message info"]')
  end

Мой тестовый файл находится внутри spec/requests.

Любые идеи? Спасибо!

21
задан Deleteman 4 July 2012 в 20:49
поделиться