简体   繁体   中英

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

I would like to test behavior of several button-clicking events. Here is my *_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

I have tried another approach to test this through capybara scripting.

I have tried the following:

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

.....

And change

 click_link 'Pause-confirm'

=>

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

It gives no result plus I have got error within my method main_page_available?(@user), just because I have added js: true for describe section (the same result if add js: true within it 'should... section).

My methods fill_in_fields(user) and main_page_available?(user) in spec_helper.rb

    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

What am I doing wrong?

Thanks in advance! Any help will be highly appreciated!

If you have problems with checking elements within js modal windows (bootbox.js in my case - CustomConfirmBox) you must specify js: true for your specs.

Here is the way how I solve aforementioned problem:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM