2012-12-01 68 views

回答

0

硒默认带有水豚,添加:js =>真正的黄瓜步骤,你应该很好去。我使用rspec的不黄瓜,但我有像

describe "Something" do 
it "should use selenium", js: true do 

page.should have_content "It works!" 
end 

你应该看到Firefox的拿出 您可以wanna考虑一个无头的驱动程序来减少对浏览器启动成本

下面是Rails 3的项目在行动中有使用硒

https://github.com/rails3book/ticketee

0

我把一个例子一些特点:

require "selenium-webdriver" 
gem "test-unit" 
require "test/unit" 

class Papidal < Test::Unit::TestCase 

    def setup 
    @driver = Selenium::WebDriver.for :firefox 
    #@base_url = "http://localhost:8090/" 
    @accept_next_alert = true 
    @driver.manage.timeouts.implicit_wait = 30 
    @verification_errors = [] 
    end 

    def teardown 
    @driver.quit 
    assert_equal [], @verification_errors 
    end 

    def test_papidal 
    @driver.get("http://localhost:8090/myproject/") 
    @driver.find_element(:xpath, "//a[@wicketpath='showModalLink']").click 
    end 

    def element_present?(how, what) 
    @driver.find_element(how, what) 
    true 
    rescue Selenium::WebDriver::Error::NoSuchElementError 
    false 
    end 

    def verify(&blk) 
    yield 
    rescue Test::Unit::AssertionFailedError => ex 
    @verification_errors << ex 
    end 

    def close_alert_and_get_its_text(how, what) 
    alert = @driver.switch_to().alert() 
    if (@accept_next_alert) then 
     alert.accept() 
    else 
     alert.dismiss() 
    end 
    alert.text 
    ensure 
    @accept_next_alert = true 
    end 
end 

如果你想与Internet Explorer使用: