【问题标题】:Im getting an error when trying to run a cucumber test, which manipulates a confirm dialogue using selenium-webdriver尝试运行黄瓜测试时出现错误,该测试使用 selenium-webdriver 操作确认对话
【发布时间】:2014-11-18 00:28:41
【问题描述】:

我只是想让我的黄瓜测试接受确认对话,在我的黄瓜测试中,我安装了 selenium-webdriver,它给了我这个错误:

无法在 60 秒内获得稳定的 firefox 连接 (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)

我尝试运行 gem update selenium-webdriver,但没有成功。

这是我的功能文件:

功能:删除用户 为了删除现有用户 作为用户 我希望能够从数据库中删除用户

Scenario: User successfully deletes another user
    Given I am currently on the Users page
    When I select a user to delete
    Then the user should no longer visible on the users page

这里是步骤文件的相关部分:

功能:删除用户,场景:用户成功删除另一个用户

当/^我选择一个用户删除js时:true$/do page.evaluate_script('window.confirm = function() { return true; }') find(:xpath, "//a[@href='/users/2?page=1' and @data-confirm='Are you sure?']").click 结束

然后 /^该用户在用户页面上不再可见$/ 做 期望(页面).to have_no_content "cwl0@aber.ac.uk" 结束

这里是 env.rb 文件:

需要“黄瓜/铁轨” 需要'selenium-webdriver'

目录["../../spec/factories/*.rb"].each {|file|需要相对文件}

ActionController::Base.allow_rescue = false

如果您的应用没有数据库,请删除/注释掉以下行。

对于某些数据库(如 MongoDB 和 CouchDB),您可能需要改用 :truncation。

开始 DatabaseCleaner.strategy = :transaction 救援名称错误 raise “如果您想使用它,您需要将 database_cleaner 添加到您的 Gemfile(在 :test 组中)。” 结束

在做之前 DatabaseCleaner.start 加载 Rails.root.join('db/seeds.rb') 结束

做后|场景| 数据库清理器.clean 结尾 Cucumber::Rails::Database.javascript_strategy = :truncation

这是gemfile:

来源'https://rubygems.org'

宝石'薄'

gem '回形针', '~> 4.1'

gem '简单导航'

gem 'will_paginate', '~> 3.0'

在运行 Rails 4.1.5 时,Windows 和某些 Linux 平台需要!

gem 'tzinfo-data'

改为捆绑边缘 Rails:gem 'rails',github:'rails/rails'

gem 'rails', '4.1.5'

使用 sqlite3 作为 Active Record 的数据库

宝石'sqlite3'

为样式表使用 SCSS

gem 'sass-rails', '~> 4.0.3'

使用 Uglifier 作为 JavaScript 资产的压缩器

gem 'uglifier', '>= 1.3.0'

将 CoffeeScript 用于 .js.coffee 资产和视图

gem 'coffee-rails', '~> 4.0.0'

gem 'oauth', '~>0.4.6'

请参阅 https://github.com/sstephenson/execjs#readme 了解更多支持的运行时

gem 'therubyracer',平台::ruby

使用 jquery 作为 JavaScript 库

gem "jquery-rails", "~> 2.3.0" 宝石'jquery-ui-rails','4.1.2'

Turbolinks 使您的网络应用程序中的链接更快。阅读更多:https://github.com/rails/turbolinks

gem 'turbolinks'

轻松构建 JSON API。阅读更多:https://github.com/rails/jbuilder

gem 'jbuilder', '~> 1.2'

组 :doc 做 # bundle exec rake doc:rails 在 doc/api 下生成 API。 宝石'sdoc',要求:假 结束

组:测试做 gem '黄瓜导轨', :require => false 宝石“发射” 宝石'database_cleaner' gem 'selenium-webdriver', "~> 2.38.0" gem 'rspec-rails', '~> 3.0.0' 宝石'factory_girl_rails' 结束

请有人建议测试此功能的最佳方式,让我接受确认对话?

【问题讨论】:

  • 你使用的是什么版本的火狐?我将获得最新版本的 FF 并下载最新的 selenium 驱动程序。更多信息:stackoverflow.com/questions/12588082/…
  • 刚刚尝试使用 bundle update 更新到最新的 selenium 驱动程序,现在又给我一个错误,真是一场噩梦:安装 ffi (1.9.6) 时出错,Bundler 无法继续。在捆绑之前确保gem install ffi -v '1.9.6' 成功。
  • ok 设法解决了 ffi 问题(希望如此),更新了最新版本的 firefox 和 selenium,仍然遇到同样的问题。我不确定是否需要明确声明测试应该使用 selenium,或者是否需要在使用它的测试中包含某些内容,但它仍然不起作用
  • 我认为你需要安装 selenium-client。

标签: ruby-on-rails selenium-webdriver cucumber


【解决方案1】:

检查您使用的 selenium-webdriver 版本与您的 Firefox 版本的兼容性,并在您的 gemfile.lock 文件中进行适当的版本更改。 https://selenium.googlecode.com/git/rb/CHANGES

可在此处找到较旧的 Firefox 版本 https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/

【讨论】:

  • 感谢您,我设法通过回滚到 Firefox 25 使其部分工作,但它仍然无法正常工作。它设法让用户登录,但在 javascript 测试中没有得到任何进一步的结果,当它应该在登录后打开用户页面时。
【解决方案2】:

在您的 Gemfile 中有以下内容:

group :test do
  gem "capybara"

  # selenium webdriver is a dependency of Capybara. However it needs updating
  # much more frequently to keep up with firefox. Including it in the Gemfile
  # allows us to run 'bundle update selenium-webdriver' when this happens.
  gem 'selenium-webdriver'
end

然后按照评论中的说明进行操作,即运行

bundle update selenium-webdriver

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 2019-12-06
    • 2017-11-26
    • 2017-02-04
    • 2020-12-19
    相关资源
    最近更新 更多