使用ruby 1.9.2、selenium客户端和rspec(无rails)进行独立测试

使用ruby 1.9.2、selenium客户端和rspec(无rails)进行独立测试,ruby,testing,selenium,rspec,Ruby,Testing,Selenium,Rspec,有没有人成功地建立了一个独立的环境来使用ruby 1.9.2、selenium客户端和rspec测试一个非RAILS网站 我在网上搜索过,但似乎找不到神奇的公式。存在gem版本冲突、缺少库等问题。在这一点上,我完全感到困惑 基本问题:对于非RAILS应用程序(IIS/ASP),我有许多使用SeleniumIDE 1.0.10的测试套件和测试。我只想使用SeleniumIDE可以提供的转换测试,并使用ruby或更好的rake运行它们。(请注意,硒脲可以创建RSpec或测试/单元测试,我很想让这两种

有没有人成功地建立了一个独立的环境来使用ruby 1.9.2、selenium客户端和rspec测试一个非RAILS网站

我在网上搜索过,但似乎找不到神奇的公式。存在gem版本冲突、缺少库等问题。在这一点上,我完全感到困惑

基本问题:对于非RAILS应用程序(IIS/ASP),我有许多使用SeleniumIDE 1.0.10的测试套件和测试。我只想使用SeleniumIDE可以提供的转换测试,并使用ruby或更好的rake运行它们。(请注意,硒脲可以创建RSpec或测试/单元测试,我很想让这两种测试都能正常工作)

据我所知,selenium客户端具有启动/停止SeleniumRC服务器和运行测试的rake任务。但就我的生命而言,我不能让这一切继续下去

如果需要,我可以提供更多信息。但是,在这一点上,我很高兴知道有人也在走这条路

-谢谢


顺便说一句,我这样做是将IIS/ASP应用程序与rails混合并迭代进行完整转换的前奏。如果我不能迈出这第一步,我的老板会拒绝我去rails的想法,所以请帮忙;-)

您是否考虑过使用创建沙盒环境并为您管理依赖关系?

在使用rails时,我使用rvm和bundler。对于这个问题中我所关心的项目,我不希望有一个单独的环境来进行旧东西的独立测试(IIS/ASP)

因此,我决定使用Test:unitselenium转换来代替RSpec,并使用一些rake任务在与hybrid项目相同的环境中独立进行测试

这是有意义的,因为几乎所有这些selenium测试都在测试混合系统的旧部分,在集成新rails代码时,将被rspec/cucumber/capybara测试所取代,直到旧部分(以及独立测试)不再存在

selenium在新的仅集成rails的项目中仍然有使用,特别是在AJAX测试中


请参阅此示例。

您将需要gem安装“rspec”和“selenium客户端”。我安装了ruby 1.9.2,是的,我使用rvm。我为firefox_版本的废话道歉。我的Macbook上安装了多个firefox版本。如果您只安装了一个firefox,只需指定:browser=>“*firefox”

您需要打开两个终端窗口。首先,启动selenium-server.jar

在第二个窗口中,将cd放入包含rspec_hello.rb的目录,然后输入 ruby./rspec_hello.rb

    require "rubygems"         # >= 1.8.12
    require 'rspec'            # >= 2.1.0
    require "selenium/client"  # >= 1.2.18

    describe "google" do
      # attr_reader :selenium_driver
      @selenium_driver = nil

      before(:each) do
        firefox_version = 3
        firefox_path = "/Applications/Firefox" + firefox_version.to_s + ".app/Contents/MacOS/firefox-bin"
        @selenium_driver = Selenium::Client::Driver.new \
          :host => "localhost",
          :port => 4444,
          :browser => "*firefox #{firefox_path}",
          :url => "http://www.google.com/",
          :timeout_in_second => 60
          @selenium_driver.start
      end

      after(:each) do
        puts " "
        puts "goodbye world"
        @selenium_driver.close_current_browser_session
      end

      it "test google" do
        puts "hello world"
        @selenium_driver.open "/"
        @selenium_driver.type "q", "selenium wiki"
        @selenium_driver.click "btnG"
        @selenium_driver.wait_for_text("Selenium Wiki")
    @selenium_driver.text?("Selenium Wiki").should be_true
  end
end
这里是rspec_hello.rb

    require "rubygems"         # >= 1.8.12
    require 'rspec'            # >= 2.1.0
    require "selenium/client"  # >= 1.2.18

    describe "google" do
      # attr_reader :selenium_driver
      @selenium_driver = nil

      before(:each) do
        firefox_version = 3
        firefox_path = "/Applications/Firefox" + firefox_version.to_s + ".app/Contents/MacOS/firefox-bin"
        @selenium_driver = Selenium::Client::Driver.new \
          :host => "localhost",
          :port => 4444,
          :browser => "*firefox #{firefox_path}",
          :url => "http://www.google.com/",
          :timeout_in_second => 60
          @selenium_driver.start
      end

      after(:each) do
        puts " "
        puts "goodbye world"
        @selenium_driver.close_current_browser_session
      end

      it "test google" do
        puts "hello world"
        @selenium_driver.open "/"
        @selenium_driver.type "q", "selenium wiki"
        @selenium_driver.click "btnG"
        @selenium_driver.wait_for_text("Selenium Wiki")
    @selenium_driver.text?("Selenium Wiki").should be_true
  end
end