标签: capybara

Capybara.javascript_driver =:poltergeist在测试期间没有显示浏览器

我正在尝试使用poltergeist进行测试,但是当我运行测试时,浏览器没有显示.

这是我的spec_helper.rb:

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'rspec/page-regression'

require 'capybara/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'
Capybara.register_driver :poltergeist do |app|
  #Capybara::Poltergeist::Driver.new(app, {debug: true, :timeout => 90})
  Capybara::Poltergeist::Driver.new(app, {debug: false, :default_wait_time => 30, :timeout => 90})
end
Capybara.javascript_driver = :poltergeist

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails capybara poltergeist

0
推荐指数
1
解决办法
746
查看次数

Rspec与capybara面临的问题与page.should have_content

我是Rspec的新手,在这里我试图测试一个集成测试.当我(使用Capybara)单击按钮时,页面内容将被替换为后期响应.现在我正在检查页面内容,它出现在页面上,但我的测试仍然失败.以下是规格

it "get force check takeover1" do
    visit('/las_xml')
    select('Showroom', :from => 'urlVal')
    fill_in('fpHeaderForce', :with => 'PSD.L.Syn')
    fill_in('currentDate', :with => '2013-09-11')
    click_button('submit')
    page.should have_content('Buy 2013 Labor Law Posters')
end
Run Code Online (Sandbox Code Playgroud)

但结果是,

1) las box get force check takeover1
   Failure/Error: page.should have_content('Test page')
   expected #has_content?("Buy 2013 Labor Law Posters") to return true, got false
   # ./integration/las_box_spec.rb:19:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

和结果响应html包含,

<div class="las-link" id="">
    <div class="laborLink_actual labor_01">
        <span class="laborLink"></span>
        <a href="#">Buy 2013 Labor Law Posters</a>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails capybara

0
推荐指数
1
解决办法
2635
查看次数

未定义的方法"获取"和"让"与Rspec 3 - rails 4

我决定使用新的Rspec 3(+ capybara/factory_girl)开始一个新项目,并且在学习新语法时遇到了麻烦.现在我有

user_pages_spec.rb(功能)

scenario "Signing Up" do

        let(:submit) { "Sign up" }

        scenario "With valid information" do
            background do
                fill_in "Username", with: "bbvoncrumb"
                fill_in "Email", with: "bbvoncrumb@example.com"
                fill_in "Password", with: "foobar123"
                fill_in "Password confirmation", with: "foobar123"
            end

            scenario "should create a user" do
                expect { click_button submit }.to change(User, :count).by(1)
            end
        end
    end
Run Code Online (Sandbox Code Playgroud)

使用未定义的方法'let'失败.和:

static_pages_spec.rb(控制器)

describe StaticPagesController do

  describe "GET 'home'" do
    it "returns http success" do
      get :home
      expect(response).to be_success
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

使用"未定义的方法'获取'.(这只是默认的控制器规范)

rspec ruby-on-rails capybara rspec3

0
推荐指数
1
解决办法
616
查看次数

如何测试水豚元素数组中的页面内容?

我正在使用Cucumber,Capybara和RSpec。假设我在页面上有一个列表:

<ul>
  <li><span class="title">Thing 1</span><span class="description">Desc 1</span></li>
  <li><span class="title">Thing 2</span><span class="description">Desc 2</span></li>
  <li><span class="title">Thing 3</span><span class="description">Desc 3</span></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

我可以通过以下方式获得所有这些列表项:

all('li').count.should == 3
Run Code Online (Sandbox Code Playgroud)

现在,我要测试每个项目的内容是否正确。顺序很重要。我尝试了一些不同的事情,这些事情都感觉很混乱,或者导致了错误。例如:

things = Thing.all
all('li').each_with_index do |element, index|
  within element do
    page.should have_content things[index].title
    page.should have_content things[index].description
  end
end

undefined method `element' for #<Cucumber::Rails::World:0x007fe1b62f8308>
Run Code Online (Sandbox Code Playgroud)

测试每一项内容的最佳方法是什么?

capybara

0
推荐指数
1
解决办法
2739
查看次数

Ruby on Rails Capybara ::不明确:模糊匹配

我对rails很新,还在学习它.现在我得到了这样的测试失败消息:

1) LayoutLinks should have the right links on the layout
 Failure/Error: click_link("Help")
 Capybara::Ambiguous:
   Ambiguous match, found 2 elements matching link "Help"
 # ./spec/requests/layout_links_spec.rb:47:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

因为我在我的主页上有两个相同的"帮助"链接,但似乎测试认为这是一个模糊的匹配,我希望它以相同的方式测试它们,因为链接指向同一页面.

实际上网站上有几种解决方案,但由于我很新,所以大多数解决方案都很复杂,所以有人能给我最简单的解决方案吗?提前致谢.

更新:

在我的观点和规范中没有什么复杂的.我还在学习一切.

这是我的规格

        visit root_path
        expect(page).to have_title("Home")      
        click_link("About")
        expect(page).to have_title("About")
        click_link("Contact")
        expect(page).to have_title("Contact")
        click_link("Help")
        expect(page).to have_title("Help")
Run Code Online (Sandbox Code Playgroud)

这是我的标题部分在布局中

<header>
  <nav class="round">
    <ul>
        <li><%= link_to "Home", root_path %></li>
        <li><%= link_to "Help", help_path %></li>
        <li><%= link_to "Sign in", "#" %></li>
    </ul>
  </nav>
</header>
Run Code Online (Sandbox Code Playgroud)

这是我的页脚部分布局

<footer>
  <nav class="round">
    <ul>
        <li><%= link_to "About", …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails capybara rspec-rails

0
推荐指数
2
解决办法
5107
查看次数

如果我在我的控制器测试中存根.save方法测试如何检查正确的显示模板?

我正在尝试使用RSpec在rails应用程序中测试控制器创建方法,如下所示:

def create
  @user = User.new(user_params)
  if @user.save
     redirect_to user_path(@user.id)
  else
     render new_user_path
     flash[:error] = "User not saved"
  end
end
Run Code Online (Sandbox Code Playgroud)

但是,如果我踩灭.new,迫使它回到避免使用活动记录和用户模型测试trueID@user不被设置.save为正常,所以我不能测试它重定向到user_path(@user.id)@user.id是零

这是我对RSpec的初步测试:

it "creates a user and redirects" do
  expect_any_instance_of(User).to receive(:save).and_return(true) 
  post :create, { user: {name: "John", username: "Johnny98", email: "johnny98@example.com"} }

  expect(assigns(:user).name).to eq("John")
  expect(response).to redirect_to user_path(assigns(:user))
end
Run Code Online (Sandbox Code Playgroud)

我该如何在RSpec中测试这个重定向.

ruby rspec ruby-on-rails capybara

0
推荐指数
1
解决办法
1090
查看次数

如何在水豚中单击此按钮(使用“ ID”或“ Xpath”选择器)

请帮我解决这个问题

我在Capybara中有一个按钮:

<li id="main-menu-button" data-radium="true" style="flex: 0 0 auto; padding:   0px; box-sizing: border-box; color: rgb(158, 144, 212); display: flex; margin: 5px; border-radius: 5px; width: 50px; height: 50px; flex-flow: row nowrap; justify-content: center; position: relative; transition: background-color 100ms ease-out;">
  <img src="/assets/images/branding/reachify-r-logo-white.png" alt="Logo" data-radium="true" style="width: 50px; height: 50px; padding: 10px; box-sizing: border-box; border-radius: 4px; background-color: rgba(0, 0, 0, 0.2);">
</li>
Run Code Online (Sandbox Code Playgroud)

我尝试使用:click_button“主菜单按钮”和find_button(“主菜单按钮”).click

但它给出了错误:

 Unable to find button "Organization" 
  (Capybara::ElementNotFound)
Run Code Online (Sandbox Code Playgroud)

ruby testing automation cucumber capybara

0
推荐指数
1
解决办法
4627
查看次数

有没有办法在Capybara中按文字查找任何元素?

我想在我的页面上找到任何带有给定文本的元素,但是当我将它传递给没有元素的查找时,它会给我一个错误

find(material.attachment_filename) #material.attachment_filename is "01. pain killer.mp3"
Run Code Online (Sandbox Code Playgroud)

但如果我这样做:

find('a',text: material.attachment_filename)
Run Code Online (Sandbox Code Playgroud)

它工作正常,给定的错误是:

硒:: webdriver的::错误:: InvalidSelectorError:

给定css选择器表达式"01. pain killer.mp3"无效:SyntaxError:指定了无效或非法字符串

selenium automated-tests capybara

0
推荐指数
1
解决办法
2373
查看次数

无法加载此类文件-capybara / minitest

希望有人可以帮助我。我确实进行了搜索,但没有找到任何有效的解决方案。

我已经开始为应用编写测试。我的集成测试运行正常,但后来我决定,那么多的TDD的驱动,因为我没有,因为我没有那么多时间,现在要进行广泛的测试应用程序的所有层,我应该使用的,而不是integration检验system测试,因为它们使我可以像在浏览器中一样测试整个流程。

Rails 5.1.2

Gemfile (尝试了不同的变化,只是水豚,然后结合了其他两个)

gem 'minitest-rails'
gem 'minitest-rails-capybara'
gem 'capybara'
Run Code Online (Sandbox Code Playgroud)

test_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  fixtures :all

  EMPTY_NEW_USER = {
    email: '',
    first_name: '',
    last_name: '',
    username: '',
    password: ''
  }

  EXISTING_USER = {
    email: '****',
    first_name: 'John',
    last_name: 'Doe',
    username: '',
    password: 'testingpass',
    password_confirmation: 'testingpass'
  }

  # Add more helper methods to be used by …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails minitest system-testing capybara

0
推荐指数
1
解决办法
686
查看次数

黄瓜水豚换行符

我正在将黄瓜和水豚一起使用。我注意到,在安装捆绑软件之后,突然之间,我的测试失败了,新的换行符作为文本的一部分出现在字符串中。

错误示例:

RSpec::Expectations::ExpectationNotMetError: expected to find text "Longview Road Clase Swansea SA6 7JL" in "Skip to main content\nGOV.UK\nDigital tachograph card\n......."
Run Code Online (Sandbox Code Playgroud)

过去,那些换行符不存在。我正在努力寻找导致此问题的宝石。

有没有一种方法可以停止此操作,而无需在我从网页提取的每个字符串中都做一个剥离?

一些gem版本:

水豚-2.18 Rspec期望-3.7.0黄瓜-2.4.0

cucumber capybara rspec-expectations

0
推荐指数
1
解决办法
924
查看次数