Tag: capybara

使用rspec和capybara测试rails + backbone应用程序

我正在使用列出的gem为我的应用程序编写测试。 我找不到如何设置Capybara与骨干(ajax in all)一起工作 示例测试: require ‘spec_helper’ describe “Main” do describe “GET /” do it “displays articles” do Article.create!(title:’title’,body:’body text’) visit ‘/’ page.should have_content(‘body text’) end end end 和测试的输出: Failures: 1) Main GET / displays articles Failure/Error: page.should have_content(‘body text’) expected there to be text “body text” in “Loading…” # ./spec/features/main_spec.rb:8:in `block (3 levels) in […]

Docker中的Capybara无头镀铬返回DevToolsActivePort文件不存在

我试图配置系统测试,以在selenium中使用无头铬。 我有以下水豚配置: # spec/support/capybara.rb Capybara.server = :puma, { Silent: true } RSpec.configure do |config| config.before(:each, type: :system) do driven_by :rack_test end config.before(:each, type: :system, js: true) do driven_by :selenium_chrome_headless, screen_size: [1400, 1400] end end 和以下Dockerfile(没有数据库,因为我正在使用主机): FROM ruby:2.5.1 RUN apt-get update RUN apt-get install -y wget git # Node RUN curl -sL https://deb.nodesource.com/setup_9.x | bash – […]

RSpec :: ExampleGroups :: User :: Validations的未定义方法`validate_presence_of’

我试图通过我的模型规范进行validation,但我无法让它们通过。 我已将所有validation规则放在我的模型文件中 应用程序/模型/ user.rb class User :friendships has_many :plans has_many :memberships, class_name: “PlanMemebership” has_many :notes has_many :replies, class_name: “NoteReply” has_many :upvotes, class_name: “NoteUpvote” validates :first_name, presence: true validates :last_name, presence: true validates :email, presence: true validates :facebook_user_id, presence: true, uniqueness: true validates :facebook_user_token, presence: true, uniqueness: true validates :token, presence: true, uniqueness: true validates :birthday, […]

使用Capybara + Rails3找不到要点击的元素

背景 :我正在使用Capybara和Rspec来测试Rails 3应用程序。 使用的驱动程序 :Selenium 问题 :我无法找到“登录”按钮,以便在我的测试中点击。 HTML代码: Email Password Forgot password… Cancel 测试失败 it “should login correctly if the right credentials are given”, :js => true do Capybara.default_wait_time = 5 Capybara.reset_sessions! visit ‘/’ click_link(‘login_link’) #this will bring a modal window with the code posted above using js within(“#login”) do fill_in ‘user_email’, :with => “my-email@example.com” […]

使用Capybara Webkit 1.3.1测试警报对话框文本

我希望使用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. [DEPRECATION] Capybara::Webkit::Driver#confirm_messages is deprecated. Please use Capybara::Session#accept_confirm or Capybara::Session#dismiss_confirm instead. 使用警告中的任何一种方法都不会测试对话框的内容。

如何在Capybara中重用代码

我在Rails的一个function测试中有一堆具有重复结构的代码。 我想通过重复使用结构来干掉我的规格。 有什么建议? 一个例子是: feature “Search page” subject { page } it “should display results” # do something within “#A” do should have_content(“James”) end within “#B” do should have_content(“October 2014”) end # do something else # code with similar structure within “#A” do should have_content(“Amy”) end within “#B” do should have_content(“May 2011”) end end 起初,我尝试在RSpec中定义一个自定义匹配器,但是当我within块within添加时,它似乎不起作用。 […]

Rails载波测试 – 如何在测试后删除文件?

我正在使用rspec和capybara测试carrierwave上传function。 我有类似的东西: describe “attachment” do let(:local_path) { “my/file/path” } before do attach_file(‘Attachment file’, local_path) click_button “Save changes” end specify {user.attachment.should_not be_nil} it { should have_link(‘attachment’, href: user.attachment_url) } end 这很有效。 问题是测试后上传的图像仍然在我的public / uploads目录中。 测试完成后如何将其删除? 我试过这样的事情: after do user.remove_attachment! end 但它不起作用。

使用Capybara / Rspec使用will_paginate Gem测试视图

做Michael Hartl的Rails教程, 第10章,第5节,练习2 。 我 – 非常简单 – 尝试编写测试以确保使用will_paginate gem在几页上出现分页div(这似乎是Hartl测试分页是否有效的首选方法),但是当我添加以下代码时… subject { page } . . . it { should have_selector(‘div.pagination’) } ..it返回.. 1) UserPages profile page Failure/Error: it { should have_selector(‘div.pagination’) } expected css “div.pagination” to return something 这特别奇怪,因为在这个特定的_spec文件中,这个相同的Rspec代码在一些测试中传递而在其他测试中失败(我将在下面强调这一点)。 pagination div也存在于浏览器的源代码中,当然它工作正常。 因为它在某些地方而不是在其他地方失败,我得假设这是某种“范围” – 或与will_paginate相关的分配类型问题 – 你看,对于失败的测试,被分页的内容实际上是“ Microposts“控制器,但正在测试的页面/视图由”用户“控制器处理。 对于通过测试,视图和控制器都是“用户”。 这可能是问题吗? 我的FactoryGirl设置/调用也可能被破坏,并且由于某种原因没有在测试中触发分页代码。 我是一个Rails n00b – 实际上是编程的新手 […]

在rails上的ruby中运行测试时有一个默认端口

我试图用rake spec我运行我的测试我使用rspec,capybara与selenium作为webdriver。 问题是我什么时候尝试运行规范它每次都在不同的端口启动测试环境。 我不希望这发生,因为它弄乱了我的Facebook登录。 我怎样才能让环境每次都在同一个端口启动。 请帮忙!

RSpec + Capybara请求规格w / JS无法正常工作

使用Javascript时,我无法获得请求规范。 如果我在没有Javascript的情况下运行它们,我的规范就会通过 (该页面可以使用或不使用JS)。 具体来说,当我做Post.should have(1).record这样的断言时,规范就失败了。 Capybara只是不从DB中获取记录,并且在运行之间不会清理数据库。 我已经尝试使用DatabaseCleaner禁用事务管道 – 我猜这是常见的方法。 没有骰子。 我也尝试(并且,理想情况下更喜欢)在没有DatabaseCleaner的情况下运行,使用事务夹具并强制AR在线程之间共享相同的连接( JoséValim描述的补丁 )。 再一次,没有骰子。 此外,我也试过在Capybara-webkit和Selenium之间切换 – 问题仍然存在。 我已经提出了一个只有一个基本的Post脚手架的示例应用程序,它复制了这个问题: https : //github.com/cabgfx/js-specs有一个带有事务夹具和AR共享连接的spec_helper.rb,以及一个spec_helper_database_cleaner。 rb用于其他场景。 我通常使用Spork,但我在spec_helper.rb文件中都禁用了它,只是为了消除潜在的失败点(在两个应用程序中;“真正的”和示例应用程序)。 我在Macbook Air上使用Pow进行本地开发,使用MRI 1.9.3至RVM运行OS X 10.7.3。 (我也试过1.9.2)。 希望我有意义 – 任何指导/帮助/指针都非常感谢!