gpt4 book ai didi

ruby - 我如何在 Ruby 中使用 Selenium ?

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

我用 Firefox Selenium 做了一些测试,然后将它导出到 Ruby。尽管测试在 Firefox 中运行良好,但我在 Ruby 中运行相同的套件时遇到了问题。

我尝试运行他们拥有的示例程序之一,但我也遇到了相同的连接被拒绝错误。这是我在尝试运行他们的 google_test 套件时遇到的错误。

tellingsen$ ruby google_test.rb 
Loaded suite google_test
Started
E
Finished in 0.001558 seconds.

1) Error:
test_page_search(ExampleTest):
Errno::ECONNREFUSED: Connection refused - connect(2)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `open'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `connect'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `connect'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:542:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:1035:in `request'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:845:in `post'
/Users/tellingsen/.gem/ruby/1.8/gems/selenium-client-1.2.18/lib/selenium/client/protocol.rb:89:in `http_post'
/Users/tellingsen/.gem/ruby/1.8/gems/selenium-client-1.2.18/lib/selenium/client/protocol.rb:12:in `remote_control_command'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
/Users/tellingsen/.gem/ruby/1.8/gems/selenium-client-1.2.18/lib/selenium/client/protocol.rb:11:in `remote_control_command'
/Users/tellingsen/.gem/ruby/1.8/gems/selenium-client-1.2.18/lib/selenium/client/protocol.rb:19:in `string_command'
/Users/tellingsen/.gem/ruby/1.8/gems/selenium-client-1.2.18/lib/selenium/client/base.rb:85:in `start_new_browser_session'
google_test.rb:21:in `setup'

1 tests, 0 assertions, 0 failures, 1 errors

有人可以帮我解决这个问题吗?

注意:

  • Mac 操作系统:10.6.4
  • 苹果电脑专业版
  • ruby :1.8.7
  • gem:selenium-client 1.2.18

编辑这是我试过的 google_test.rb

#!/usr/bin/env ruby
#
# Sample Test:Unit based test case using the selenium-client API
#
require "test/unit"
require "rubygems"
gem "selenium-client", ">=1.2.18"
require "selenium/client"

class ExampleTest < Test::Unit::TestCase
attr_reader :browser

def setup
@browser = Selenium::Client::Driver.new \
:host => "localhost",
:port => 4444,
:browser => "*firefox",
:url => "http://www.google.com",
:timeout_in_second => 60

browser.start_new_browser_session
end

def teardown
browser.close_current_browser_session
end

def test_page_search
browser.open "/"
assert_equal "Google", browser.title
browser.type "q", "Selenium seleniumhq"
browser.click "btnG", :wait_for => :page
assert_equal "Selenium seleniumhq - Google Search", browser.title
assert_equal "Selenium seleniumhq", browser.field("q")
assert browser.text?("seleniumhq.org")
assert browser.element?("link=Cached")
end

end

最佳答案

我在论坛和谷歌上搜索了几个小时后找到了答案。

我需要做的是运行 selenium 服务器以使其正常工作。我可以从这个网站下载它 http://seleniumhq.org/download/ (当前:Selenium RC 2010 年 2 月 23 日 1.0.3)。

从那里我打开了一个新的终端并做了

cd Downloads/selenium-remote-control-1.0.3/selenium-server-1.0.3
java -jar selenium-server.jar

然后用另一个终端窗口运行我的 ruby​​ 生成的脚本

ruby google_test.rb

成功了!

关于ruby - 我如何在 Ruby 中使用 Selenium ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3603373/

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