当前位置: 首页 > 知识库问答 >
问题:

如何在水豚和硒中打开浏览器

高奇
2023-03-14
describe 'Downloads', js: true do

context ' compress zip and download file' do
  before do
    Capybara.current_driver = :selenium
    session = Capybara::Session.new(:selenium)
    session.visit '/users/sign_in'
    find('#tab_signin').click
    within("#new_user") do
      fill_in 'user_login', :with => 'admin@local.host'
      fill_in 'user_password', :with => 'password'
    end
    click_button 'Sign in'
end

it 'downloads the project and navigates to downloads page' do
  visit 'some/path'
  within '.create-download' do
    find(:select).find("option[value='zip']").select_option
  end
  sleep 3
  page.should have_css('#download-modal.in')
end
Capybara.javascript_driver = :selenium
Capybara.register_driver :selenium do |app|
  profile = Selenium::WebDriver::Firefox::Profile.new
  Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end

不仅浏览器没有打开,而且测试失败,输出如下:

Failure/Error: visit '/users/sign_in'
 ArgumentError:
   unknown option: {:resynchronize=>true}

共有1个答案

柴兴修
2023-03-14

所以经过大量的工作,我终于想通了。感谢@Raj关于将配置信息放在哪里的建议。特性/support/env.rb是针对cucumber的,我使用的是RSpec。

我读到的大多数关于selenium和capybara的文章都告诉我在块的开头使用js:true选项,但这不起作用。一旦我将其更改为feature:true,它就起作用了。我的最终解决方案如下所示:

describe 'Downloads', feature: true do

context 'compress zip and download file' do
before do

  visit '/users/sign_in'
  find("a[href$='signin']").click
  within("#new_user") do
    fill_in 'user_login', :with => 'admin@local.host'
    fill_in 'user_password', :with => 'password'
  end
  click_button 'Sign in'
end

it 'downloads the project and navigates to downloads page' do
  visit 'some/path'
  within '.create-download' do
    find(:select).find("option[value='zip']").select_option
  end
  sleep 3
  page.should have_css('#download-modal.in')
end
end
end

然后我的spec_helper.rb看起来像:

Capybara.register_driver :selenium do |app|
  profile = Selenium::WebDriver::Firefox::Profile.new
  Capybara::Selenium::Driver.new( app, :profile => profile)
end
Capybara.default_wait_time = 10
Capybara.current_driver = :selenium
Capybara.app_host = 'http://localhost:3000'
 类似资料:
  • 我已经应用了所有代码 我犯了这个错误 线程“main”java中出现异常。lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver设置。铬。驱动系统属性;有关更多信息,请参阅https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.最新版本可从以下网站下载:http://chromedriver.

  • 我用cucumber配水豚和硒-WebDriver。到目前为止,我一直使用Chrome,但该项目也要求对Firefox进行一些跨浏览器测试。 在Firefox中运行时,我只是得到一个空白窗口,网页不出现。

  • 比起Ruby、Capybara和SitePrism,我更熟悉Java和Selenium,所以如果这个问题太多,我深表歉意。 Selenium有一个非常有用的类来管理Select标签,Selenium::WebDriver::Support::Select,它可以通过传递代表select的Selenium Element(Selenium::WebDriver::Element)来创建。我想得到一个

  • 全局基类 登录名 } 问题是,当运行此功能时,我得到了下面的错误,我不明白为什么会发生这种情况,因为它在错误的位置上没有给我任何帮助。 未定义步骤:给定I打开Chrome 未定义步骤:浏览网站时 未定义的步骤:然后我使用“user1”和“password1”登录网站

  • 问题内容: 我想执行XMLHttpRequest,然后通过POST方法发送文件名在浏览器中打开PDF。 这可能吗,或者XMLHttpRequest仅用于HTML? 问题答案: 如果您查询的URL实际上返回PDF数据,则无法通过XMLHttpRequest进行操作。 为什么?因为该响应是包含原始PDF数据的HTTP响应。即使您确实可以通过responseText`属性访问数据,JavaScript也