gpt4 book ai didi

ruby - cucumber 、 capybara 和 Selenium 随机工作

转载 作者:数据小太阳 更新时间:2023-10-29 07:00:33 24 4
gpt4 key购买 nike

使用 cucumber 、 capybara 和 Selenium 进行设置,但某些场景只能随机运行。
正在运行
rvm 上的 ruby 1.8.6
导轨 2.3.8
selenium 弹出 firefox 3.6

我试图添加这个但没有运气:

with_scope(selector) do
click_button(button)
selenium.wait_for_page_to_load
end

错误输出有时是:

>  Given I am logged in and have created newsletter and subscribers                           # features/step_definitions/newsletter_send_steps.rb:108
end of file reached (EOFError)
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/protocol.rb:133:in `sysread'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/protocol.rb:133:in `rbuf_fill'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/timeout.rb:62:in `timeout'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/timeout.rb:93:in `timeout'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/protocol.rb:126:in `readline'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:2020:in `read_status_line'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:2009:in `read_new'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:1050:in `request_without_fakeweb'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:1037:in `request_without_fakeweb'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:543:in `start'
/Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:1035:in `request_without_fakeweb'
./features/step_definitions/web_steps.rb:24:in `__instance_exec2'
./features/step_definitions/web_steps.rb:9:in `with_scope'
./features/step_definitions/web_steps.rb:9:in `with_scope'
./features/step_definitions/web_steps.rb:23:in `/^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/'
features/enhanced/newsletter_send1.feature:7:in `Given I am logged in and have created newsletter and subscribers'

其他时候:

> no button with value or id or text 'create_user_button' found (Capybara::ElementNotFound)
./features/step_definitions/web_steps.rb:24:in `__instance_exec2'
./features/step_definitions/web_steps.rb:9:in `with_scope'
./features/step_definitions/web_steps.rb:9:in `with_scope'
./features/step_definitions/web_steps.rb:23:in `/^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/'
features/enhanced/newsletter_send1.feature:7:in `Given I am logged in and have created newsletter and subscribers'

有时它只是有效....

这就是我的 env.rb 的样子

ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')

require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
require 'capybara/rails'
require 'capybara/cucumber'
require 'capybara/session'
require 'cucumber/rails/capybara_javascript_emulation'
require "selenium-webdriver"

Capybara.default_driver = :selenium
Capybara.default_wait_time = 5
Capybara.ignore_hidden_elements = false
Capybara.default_selector = :css

ActionController::Base.allow_rescue = false

require 'database_cleaner'
DatabaseCleaner.strategy = :truncation

Before do
Capybara.reset_sessions!
DatabaseCleaner.clean
end

Cucumber::Rails::World.use_transactional_fixtures = false

cucumber 步骤:
鉴于我在注册页面上
我在“正文”中用“jeppsipeppsi@arcticelvis.com”填写“user_login”
我在“body”中用“secret”填写“user_password”
然后我在“body”中用“secret”填写“user_password_confirmation”
然后我检查了“body”中的“terms_of_use”
然后我在“body”中按下“create_user_button”

任何见解都会很棒:)

最佳答案

这是 HTTP 模拟,如果您(完全)从您的环境中删除 fakeweb 或 webmock,它应该会再次工作。

Adam Greene 关于设置 Curb 的最后评论确实有效:Selenium::WebDriver.for :firefox, :http_client => Selenium::WebDriver::Remote::Http::Curb

Read the thread on the Capybara group.

我们遇到的问题是使用 fakeweb 或 webmock 回放记录的 http 流量,因为网络驱动程序现在是 Curb。因此,如果您的目标是伪造 Capybara 上的流量,您将再次进行浏览器测试,但您将无法通过同一浏览器播放流量。 (我们正在使用 VCR 进行录制。)

添加 Curb 支持在 Fakeweb 的 Github Issues 网站上被列为“票”。

关于ruby - cucumber 、 capybara 和 Selenium 随机工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2957719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com