簡體   English   中英

RSpec,水豚,bootbox.js,Rails-3.2。 :selenium驅動程序的奇怪行為

[英]RSpec, capybara, bootbox.js, Rails-3.2. Strange behavior of :selenium driver

我想測試幾個按鈕單擊事件的行為。 這是我的* _spec.rb

***pause_spec.rb***

require 'spec_helper'
require 'rspec'

describe CreditApplicationsController, type: :controller do
  render_views  

before do
  visit '/users/sign_in'                             #### FIRST SIGN IN
    #user = User.find_by_email("mymail@example.com") #### AND FILL REQUIRED FIELDS
  @user = FactoryGirl.create(:user)

  sign_in @user
  fill_in_fields(@user)
  main_page_available?(@user)                         #### *** ####
end

it 'should check pause_on button' do
  click_link 'pause-link'    ### OK HERE, after this - pop up bootbox.js
                             ### confirm window

  #click_link 'Pause-confirm'             ### HERE IS MY PROBLEM ###  
                                          ### click_link / click_button can't find
                                          ### button within my bootbox.js     
  assert has_selector? "leave"
end

end

我嘗試了另一種方法來通過水豚腳本對此進行測試。

我嘗試了以下方法:

describe CreditApplicationsController, type: :controller, 
                                       js: true, driver: :selenium do

.....

並改變

 click_link 'Pause-confirm'

=>

find('.btn-success').trigger('click')
... or ...
page.execute_script("$('.btn-success').click()")

它沒有任何結果,而且我的方法main_page_available?(@ user)中出現錯誤,只是因為我為describe部分添加了js:true (如果在其中“應該...”部分中添加js:true ,則結果相同)。

我在spec_helper.rb中的方法fill_in_fields(user)和main_page_available?(user)

    def fill_in_fields(user)
    # @user = User.find_by_email("a.solodkov@prbb.com")
      fill_in "user[email]", with: user.email
      fill_in "user[password]", with: "12345678"
      click_button "Sign in"

      ## Success with sign in action?
      if has_selector? 'input#user_net_name'
        assert has_selector? 'input#user_net_name'
        fill_in "user[net_name]", with: user.net_name
        fill_in "user[password]", with: "12345678"
        fill_in "user[password_confirmation]", with: "12345678"
        click_button 'change-button'
      end
    end

    def main_page_available?(user)
      # Main page?
      if has_selector? 'small.pull-right'
        within "small.pull-right" do
          assert has_content? "#{user.id}"
        end
      else
        assert has_selector? 'table#admin-credit-application'
      end
    end

我究竟做錯了什么?

提前致謝! 任何幫助將不勝感激!

如果在檢查js模態窗口(在我的情況下為bootbox.js-CustomConfirmBox)中檢查元素時遇到問題,則必須為規格指定js:true

這是我解決上述問題的方法:

it 'should check pause_on pause_off', js: true do #, driver: :selenium
  click_link 'pause-link'
  page.should have_xpath("//div[@class='modal-body']")
  page.should have_xpath("//div[@class='bootbox modal fade in']")
  page.should have_xpath("//a[@class='btn btn-success']")
  click_link 'Pause'
  page.should have_xpath("//a[@class='btn btn-block btn-success']")
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM