testing - 无法使用 Capybara,不确定我哪里出错了 'background' 和 'it' 等不工作

标签 testing rspec automated-tests capybara

您好,我正在学习 capybara ,我已经尝试了各种答案,所以我无法继续。我正在尝试使用 capybara 测试应用程序。访问不工作,错误说它需要在“它”或示例/可执行 block 等中。但是下面的代码、背景和场景等不工作,执行不在里面。

结果:

C:\Ruby223\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/Users/xxx/RubymineProjects/xxx-app/spec/features/xxxxx.rb
"aaa"

Process finished with exit code 0

我不想弄乱 Rails 应用程序,所以我想要一个独立的文件,我可以从中执行测试,然后在开发人员的帮助下与 Rails 应用程序集成。

require 'capybara/dsl'
require 'capybara'
require 'capybara/rspec'
require 'rspec'



feature "Signing in" do
  p 'aaa'
  background do
    p 'aaa1'
    Capybara.register_driver :selenium_chrome do |app|
      Capybara::Selenium::Driver.new(app, :browser => :chrome)
    end
    Capybara.run_server = false
    Capybara.current_driver = :selenium_chrome
    Capybara.app_host = 'http://www.google.com'
  end

  scenario "Signing in with correct credentials" do
    p 'aaa2'
    visit '/q=?alkjaaa'
    within("#session") do
      fill_in 'email', with: 'user@example.com'
      fill_in 'password', with: 'caplin'
    end
    click_button 'Signin'
    expect(page).to have_content 'results'
  end

  given(:other_user) { User.make(email: 'other@example.com', password: 'rous') }

  scenario "Signing in as another user" do
    p 'aaa'
    visit '/sessions/new'
    within("#session") do
      fill_in 'Email', with: other_user.email
      fill_in 'Password', with: other_user.password
    end
    click_button 'Signin'
    expect(page).to have_content 'Invalid email or password'
  end
end

最佳答案

单独使用 ruby​​ 运行该文件不会做任何事情,因为它所做的只是定义测试,而不是执行它们。如果您使用 rspec 运行该文件,那么它将运行文件中定义的测试。

rspec your_file.rb

关于testing - 无法使用 Capybara,不确定我哪里出错了 'background' 和 'it' 等不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40576259/

相关文章:

javascript - React/Jest/Enzyme 浅渲染测试中如何将文本输入到表单中?

ruby-on-rails - Rspec+Rails : POST URL-parameter to controller

ruby-on-rails - 包含文件 ruby Selenium

ruby-on-rails - 在 Rails 中自动测试流程

javascript - Cypress 没有点击元素

android - 测试 - 在此过程中未初始化 FirebaseApp

unit-testing - "pause"被忽略

unit-testing - 使用随机数进行 Junit 测试

testing - Ember.js 的测试数据生成(如 factory_girl 或 machinist)

git - 大测试数据文件和github