我可以在与capybara的链接中执行javascript click_link('next_page')吗?
链接如下所示:
<a onclick="$('#submit_direction').attr('value', '1');$('#quizForm').submit()" id="next_page" href="#">Next Question</a>
Run Code Online (Sandbox Code Playgroud)
我在github的capybara读到,我可以点击提交按钮提交表单,如下所示:
click_on('Submit Answer')
Run Code Online (Sandbox Code Playgroud)
但是,在我的情况下,我需要在链接中使用javascript提交表单,那么,如何测试里面有javascript的链接?还click_link('next_page')不够吗?
编辑
设置:js=> true我的测试后看起来像这样:
it "should pass when answering all correct", :js=>true do
login_as(student, :scope => :student)
visit ("/student_courses")
#page.execute_script("$('#submit_direction').attr('value', '1');$('#quizForm').submit()")
trace "HTML:------------", page.html
end
Run Code Online (Sandbox Code Playgroud)
之前:js => true,我可以正常访问页面,但是,我注意到在以下页面之后无法访问页面:js => true,这是我访问页面后得到的错误:
在2012-01-23 06:29:26 +0200(5010.7ms)开始获取127.0.0.1的"/ student_courses"更新"学生"SET"last_sign_in_at"='2012-01-23 04:29:26.274285'," current_sign_in_at"='2012-01-23 04:29:26.274285',"last_sign_in_ip"='127.0.0.1',"current_sign_in_ip"='127.0.0.1',"sign_in_count"= 1,"updated_at"='2012-01 -23 04:29:26.276279'WHERE"学生"."id"= 1 SQLite3 :: BusyException:数据库被锁定:UPDATE"students"SET"last_sign_in_at"='2012-01-23 04:29:26.274285'," current_sign_in_at"='2012-01-23 04:29:26.274285',"last_sign_in_ip"='127.0.0.1',"current_sign_in_ip"='127.0.0.1',"sign_in_count"= 1,"updated_at"='2012-01 -23 04:29:26.276279'WHERE"学生"."id"= 1 HTML:------------ _ _内部服务器错误
内部服务器错误
无法回滚事务 - 正在进行的SQL语句
WEBrick/1.3.1(Ruby/1.9.3/2011-10-30),版本127.0.0.1:34718
那么,为什么SQLite3 :: BusyException:数据库现在被锁定了?!
当我用gem'selenium-webdriver'(带" describe "with valid information", :js => true do")运行测试时
规格/请求/ post_pages_spec.rb
require 'spec_helper'
describe "Post pages" do
subject { page }
category = Category.create(name: "Food")
let(:post) { FactoryGirl.create(:post) }
describe "with valid information", :js => true do
it "should create a post" do
fill_in "Title", with: post.title
fill_in "Content", with: post.content
fill_in "Publish", with: Date.today
check "Food"
expect { click_button "Create Post" }.to change(Post, :count).by(1)
end
end
end
Run Code Online (Sandbox Code Playgroud)
我在规范中遇到错误:
Failures:
1) Post pages post creation with valid information should …Run Code Online (Sandbox Code Playgroud) 我正在使用Rspec与Capybara运行使用VCR gem的集成测试来模拟存根api请求.我面临着各种奇怪的问题.测试第一次成功运行并创建yaml文件以保存请求及其响应.但是如果我在创建yaml文件后再次运行测试,那么它会遇到问题并显示以下问题: -
F
Failures:
1) AffiliateSignUpProcesses Sign up using affiliate link should create User/Affiliate/AffiliateToken and Conversion when user is created
Failure/Error: visit pricing_path(:aid => 'this_is_sample_value')
VCR::Errors::UnhandledHTTPRequestError:
================================================================================
An HTTP request has been made that VCR does not know how to handle:
GET http://127.0.0.1:58021/__identify__
VCR is currently using the following cassette:
- /home/pcname/appname/selenium-error/fildername/appaname/cassettes/acceptanceTest/AffiliateSignUpProcess.yml
- :record => :once
- :match_requests_on => [:method, :uri]
Under the current configuration VCR can not find a suitable HTTP interaction
to replay and is prevented from …Run Code Online (Sandbox Code Playgroud) rspec ruby-on-rails-3 capybara-webkit selenium-webdriver vcr
Poltergeist驱动程序具有可以关闭图像加载的功能,如何使用capybara-webkit达到相同的目的?
这将使我的应用程序运行更快,因为我们使用虚荣网址加载了一些图片。
我有这个路由到user_friendships控制器的block动作:
block_user_friendship PUT /user_friendships/:id/block(.:format) user_friendships#block
Run Code Online (Sandbox Code Playgroud)
您需要知道的是阻止操作需要一个:id.
我可以在rspec规范中测试动作的结果视图,如下所示:
require 'spec_helper'
it "should not display the names of users who have a state of pending or requested" do
visit "/user_friendships/1/block"
page.should have_content("user with id of 1 blocked!")
end
Run Code Online (Sandbox Code Playgroud)
但这是一个脆弱的规范,因为URL是硬编码的.如何:id使用block_user_friendship_path变量填充params哈希的条目?
例如,这不起作用:
require 'spec_helper'
it "should not display the names of users who have a state of pending or requested" do
visit block_user_friendship_path, id: "/23"
page.should have_content("user with id of 23 blocked!")
end
Run Code Online (Sandbox Code Playgroud)
(结果 …
我正在使用 Capybara Webkit 测试警报对话框中的文本。我知道accept_js_confirms和reject_js_confirms方法,但我希望在执行操作之前评估对话框的内容。例如,在 Selenium 中,可以执行以下操作:
alert = page.driver.browser.switch_to.alert
expect(alert.text).to eq t('report_periods.edit.delete_confirmation')
alert.accept
我目前正在用来expect(page.driver.confirm_messages).to include t('report_periods.edit.delete_confirmation')测试同一对话框的文本,但是,在更新我们的 capybara-webkit gem 后,我们的测试会输出一个弃用警告:[DEPRECATION] Capybara::Webkit::Driver#confirm_messages is deprecated. Please use Capybara::Session#accept_confirm or Capybara::Session#dismiss_confirm instead.使用警告中的任何一种方法都不会测试对话框的内容。
我已经看过这个问题并在文档中查找了这个词cookie。但是,我正在使用如下所示的遗留代码。
require 'capybara'
require 'amatch'
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
session = Capybara::Session.new(:chrome)
session.visit("http://facebook.com")
Run Code Online (Sandbox Code Playgroud)
如何将cookies从session对象中取出?
我正在使用capybara 2.1.0和capybara-webkit 1.1.1。请注意,我需要使用 chrome,因为我需要 chrome 为我的用例提供的完整 JS 支持。
重复的问题包含解决方案,但答案被许多与该问题无关的内容所掩盖。副本也不包括可复制的最小工作示例。
Capybara 中有等待和非等待功能。我正在尝试尽可能多地使用第一个。
有没有办法使用find(或其派生类之一)来查找异步出现的 CSS 元素?不幸的是,函数page.has_css?是一个非等待函数。
selenium capybara capybara-webkit selenium-chromedriver selenium-webdriver
我需要使用capyvara从选定的单选按钮内的span标签中读取文本值
我有一个radio button后跟文本的列表及其括号内的计数.
例如:radiobutton with Thank You(82)
I what想要读取括号内选定的单选按钮数82.
我使用以下代码..但它不起作用
value=page.find(".cardFilterItemSelection[checked='checked'] + span.itemCount").text
Run Code Online (Sandbox Code Playgroud)
并尝试使用Xpath但没有得到任何东西
value=page.find(:xpath,"//input[@class = 'cardFilterItemSelection' and @checked = 'checked']/span[@class = 'itemCount']/text()")
Run Code Online (Sandbox Code Playgroud)
怎么可能?
<label id="thankyou_label" for="thankyou_radio" class="itemName radio">
<input checked="checked" tagtype="Occasion" value="Thank You" id="thankyou_radio" name="occasionGroup" class="cardFilterItemSelection" type="radio">
<span class="occasion_display_name">
Thank You
</span>
<span class="itemCount">
(82)
</span>
</label>
<label id="spring_label" class="itemName radio" for="spring_radio">
<input id="spring_radio" class="cardFilterItemSelection" type="radio" name="occasionGroup" value="Spring" tagtype="Occasion">
<span class="occasion_display_name">
Spring
</span>
<span class="itemCount">
(0)
</span>
</label>
Run Code Online (Sandbox Code Playgroud) 我的 ruby on rails 应用程序有一个 RSPec 测试套件,如下所示:
scenario "Buyer visits people you follow page" do
...do stuff
end
scenario "Buyer logs out" do
...do stuff
end
scenario "Buyer creates a new event", :js => true do
...do stuff
end
Run Code Online (Sandbox Code Playgroud)
在每个场景运行之前,后台 sign_in_as 模块运行:
module SignInHelpers
def sign_in_as(user = FactoryGirl.create(:user))
visit welcome_page_url
save_and_open_page
fill_in :user_email, with: user.email
fill_in :user_password, with: "password"
click_button "Log in"
end
end
Run Code Online (Sandbox Code Playgroud)
我没有设置 :js=>true 的所有场景都可以正常工作。场景“买方创建新事件”javascript 很重要,所以我想使用我的 webkit 来启用 javascript 和水豚 page.execute_script 方法......测试失败:
Buyer Features Buyer creates …Run Code Online (Sandbox Code Playgroud) 我有一个使用rspec 3.4.0 capybara 2.6.2和的 rails 项目capybara-webkit 1.8.0
我有表单,其 html 如下:
<form class="jsForm padding " id="edit_seller_profile_20" enctype="multipart/form-data" action="/seller_profile" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="?"><input type="hidden" name="_method" value="patch"><input type="hidden" name="authenticity_token" value="RBjidiRHSDaPNRVmmfVBArIQL/MvjdWcm3897r5+gLuekmWtwROLhslAcVMgxyYde9EJ6KgsWdsgYxZvLqdC7g==">
<div class="row no-padding-bottom" id="first">
<!-- Popover START -->
<div class="helper">
<a tabindex="0" id="pop-trigger" role="button" data-toggle="popover" data-placement="bottom" data-trigger="focus" data-content="If you don't have a company logo, you could just put an image of yourself in here." data-original-title="" title="">
<div class="help-mark"></div>
</a>
</div>
<!-- Popover END -->
<div class="col-xs-12 no-margin-bottom profile-photo">
<p …Run Code Online (Sandbox Code Playgroud) 我在我的一个项目中使用 Rails 5 (Ruby 2.3.3)。我使用 Capybara (capybara-wekbit) 和 RSpec 编写了一个测试。
我正在使用请求规范测试控制器操作。这是控制器
class TimelineController < ApplicationController
before_action :set_child
before_action :authenticate_user!
def index
end
private
def set_child
@child = Child.find(params[:child_id])
end
end
Run Code Online (Sandbox Code Playgroud)
这是测试
RSpec.describe "Timeline", type: :request do
it 'can visit the child timeline path', js: true do
child = FactoryGirl.create(:valid_child)
sign_in child.caregiver.user
p child
visit child_timeline_path(child)
end
end
Run Code Online (Sandbox Code Playgroud)
该p child行打印以下内容
#<Child id: 1, first_name: nil, last_name: nil, dob: "2018-06-21 00:00:00", caregiver_id: 1, doctor_id: 1, preferred_name: nil, gender: nil, street: …Run Code Online (Sandbox Code Playgroud) 有没有办法将 HTTP 标头添加到 Capybara 请求/测试中。
我正在使用以下宝石。
capybara (2.4.4)
capybara-webkit (1.5.2)
chromedriver-helper (1.0.0)
rails (4.2.6)
Run Code Online (Sandbox Code Playgroud)
以下是水豚设置:
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.javascript_driver = :chrome
Capybara::Screenshot.register_driver(:chrome) do |driver, path|
driver.browser.save_screenshot(path)
end
Run Code Online (Sandbox Code Playgroud) capybara-webkit ×13
capybara ×12
rspec ×6
ruby ×3
selenium ×2
cookies ×1
cucumber ×1
rspec-rails ×1
vcr ×1
xpath ×1