Tag: capybara

Rails – 如何为存根/伪造的http或ajax响应存根特定的响应时间

我想测试一个function,当我的应用程序在Rails UJS / ajax超时时发送usera自定义消息。 超时Rails UJS请求的代码本身就在应用程序上: $.rails.ajax = function(options) { if (!options.timeout) { options.timeout = 10000; } return $.ajax(options); }; 当观察chrome dev工具在我的本地开发模式下超时时发生的事情时,我注意到代码状态奇怪地是200但是当它“超时”时,我的消息确实显示给用户。 on(‘ajax:error’,function(event,xhr, status, error){ // display message in modal for users if(status == “timeout”) { console.log( ‘ ajax request timed out’); var msg; msg = Messenger().post({ hideAfter: 8, message: “Too long, the app timed […]

关于Ruby Tutorial第9章的RSPEC错误

我在mac osx10.8上使用ruby 1.8.7。 我不知道这些错误是什么意思。 我目前正处于ruby on rails教程的第9章末尾。 任何帮助是极大的赞赏! 1) Authentication signin with invalid information Failure/Error: before { click_button “Sign in” } NoMethodError: undefined method `[]’ for nil:NilClass # ./app/controllers/sessions_controller.rb:8:in `create’ # (eval):2:in `send’ # (eval):2:in `click_button’ # ./spec/requests/authentication_pages_spec.rb:21 2) Authentication signin with invalid information Failure/Error: before { click_button “Sign in” } NoMethodError: undefined method `[]’ […]

使用FileApi将文件上载到输入区域

我正在使用Capybara + RSpec和capybara_webkit作为驱动程序。 和一个带有FileApi的JS上传器。 我正在尝试上传三张图片: 当我点击“选择照片”按钮(在浏览器上)时,它会打开一个典型的窗口,我可以从我的计算机中选择3个文件。 我想知道如何在水豚上重现它,就像照片选择器打开时一样,我无法控制它。 我试图将图片添加到我的测试文件夹并尝试: attach_file(‘image’, File.absolute_path(‘../pictures/photo1.JPG’)) 但没有结果。

实例化capybara浏览器并设置代理

按照此文档,我正在尝试实例化一个水豚浏览器并设置代理 b = Capybara::Driver::Webkit::Browser.new b.set_proxy :host => ‘localhost’, :port => 8888 不幸的是,文档已经过时,我找不到新的正确方法。 我明白了: NameError: uninitialized constant Capybara::Driver::Webkit::Browser

Capybara :: ElementNotFound仅适用于特拉维斯的所有规格

我正在使用selenium,capybara和rspec进行测试,我注意到所有测试都在本地传递,但是在travis上,所有测试都失败了,每个规范都出现此错误。 Capybara::ElementNotFound: 我不确定这里有什么问题,这是.travis.yml上的specs runner script: – xvfb-run bundle exec rspec spec/features/*.rb 对于spec_helper.rb这里是我的配置: RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.use_transactional_fixtures = false config.infer_base_class_for_anonymous_controllers = false1 config.filter_run_excluding :broken => true config.render_views Capybara.default_driver = :selenium Capybara.default_selector= :css Capybara.run_server = true Capybara.default_wait_time = 30

Capybara不会填写表格字段(虽然它找到了)

我正在使用Ruby 2.2.1和Capybara 2.2.4开发Rails 4.2.1。 编写规范来注册用户,Capybara确实找到了字段(我没有得到ElementNotFound错误),但是当我尝试validation时,我发现所有字段都是空的并且在打开launchy之前告诉Capybara单击注册按钮显示所有字段为空。 规格: require ‘rails_helper’ RSpec.feature “Sign Up Users”, type: :feature do scenario “saves user to the database with valid data” do visit root_path click_link “Sign Up” find(“#user_name”).set(“John Doe”) fill_in “user_username”, with: “johndoe” fill_in “user_email”, with: “john@example.com” fill_in “user_password”, with: “helloworld” fill_in “user_password_confirmation”, with: “helloworld” save_and_open_page click_button “Create Account” expect(page).to have_text(‘Account successfully […]

Capybara-webkit引发了Capybara :: Driver :: Webkit :: WebkitInvalidResponseError

我在我的rspec中收到了来自webkit驱动程序的以下消息: Capybara::Driver::Webkit::WebkitInvalidResponseError: Unable to load URL: http://127.0.0.1:44923/posts 几天前它起作用了。 问题在于save_page方法。 可能有什么不对?

Capybara增加最大允许页面加载时间

我有一个页面,有时加载超过一分钟。 假设这是预期的行为并且不会改变。 在这些情况下,我得到Net::ReadTimeout 。 请注意,这是在通过单击上一页上的按钮而不是ajax请求导航到页面之后。 因此, Capybara.using_wait_time没有帮助。 我尝试了一些激进的东西(其中一些我知道不会起作用),如: 设置page.driver.browser.manage.timeouts的implicit_wait , script_timeout和page_load 。 循环遍历整个对象空间并设置所有Selenium::WebDriver::Remote::Http::Default的timeout值。 循环遍历整个对象空间并设置所有Net::HTTP的read_timeout 。 page.driver.browser.send(:bridge).http.instance_variable_get(:@http).read_timeout= 似乎没有工作。 这应该是非常微不足道的,但我找不到办法。 如果你知道一个很棒的webdriver不可知解决方案。 如果没有 – 我正在使用selenium 。

Ruby on Rails 3 + Rspec + Capybara:检查响应状态

我从Webrat迁移到Capybara,现在我遇到了很多错误。 例如在webrat中我可以在集成测试中使用它: response.should be_success 但Capybara表明: Failure/Error: response.should be_success NoMethodError: undefined method `success?’ for nil:NilClass 有没有提供这种function的方法? UPD :我的规格: require ‘spec_helper’ describe “Admins” do before(:each) do @admin = FactoryGirl.create(:admin) visit ‘/’ click_link “Login” fill_in “Email”, :with => @admin.email fill_in “Password”, :with => ‘qwerty’ click_button “Sign in” end describe “Admin panel” do it “should have correct links” do […]

Rails:RSpec – 用于nil的未定义方法`cookie_jar’:NilClass

Rails新手。 试着按照Michael Hartl的教程。 试图添加辅助方法来模拟RSpec测试中的日志: describe “when the a user has logged in and attempts to visit the page” do let(:user) { FactoryGirl.create :user } before do log_in user end it “should redirect the user to next page” do specify { response.should redirect_to loggedin_path } end end 在我的spec / support / utilities.rb中: def log_in user visit […]