我想测试几个按钮点击事件的行为。这是我的* _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则相同的结果:真实在其中......应该......部分)。
我在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
我做错了什么?
提前致谢!任何帮助将受到高度赞赏!
答案 0 :(得分:1)
如果您在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