0
我有這個測試登錄表單的簡單測試用例。 由於某些原因,webdriver拒絕運行測試並返回「太多重定向」消息。該頁面只是一個普通的登錄屏幕,非常簡單,並且沒有任何重定向。從服務器訪問頁面似乎沒問題。Selenium WebDriver for ruby以「太多重定向」失敗
我在centos服務器上使用selenium-webdriver-2.25.0。
以下錯誤信息:
(...)
[WARNING] MultiJson is using the default adapter (ok_json). We recommend loading a different JSON library to improve performance.
EE
Finished in 0.206445 seconds.
1) Error: test_login(Login):
Selenium::WebDriver::Error::WebDriverError: too many redirects
/usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:62:in `request'
/usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:63:in `request'
/usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
(...)
我的代碼:
require "rubygems"
require "selenium-webdriver"
require "test/unit"
class Login < Test::Unit::TestCase
def setup
@driver =Selenium::WebDriver.for(:remote, :url => "http://selenium.server.com/wd/hub")
@base_url = "http://www.myservice.com"
@driver.manage.timeouts.implicit_wait = 30
@verification_errors = []
end
def teardown
@driver.quit
assert_equal [], @verification_errors
end
def test_login
@driver.get(@base_url + "/login/")
@driver.find_element(:id, "username").clear
@driver.find_element(:id, "username").send_keys "[email protected]"
@driver.find_element(:id, "password").clear
@driver.find_element(:id, "password").send_keys "mykeys!"
@driver.find_element(:xpath, "//input[@value='Login']").click
verify { assert element_present?(:link, "Logout") }
verify { assert element_present?(:link, "Settings") }
verify { assert element_present?(:link, "Products") }
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
@verificatiohttp://jenkins.dev.emesa-auctions.com/cms/n_errors << ex
end
end
UPDATE
看來,不管我用什麼網址爲 '基本URL' 的錯誤不斷髮生的歷史。
也'確認{assert element_present?(:link,「註銷」)} '認真爲你工作嗎? – Amey
它似乎在做它的工作。我們使用硒IDE,這是一個輸出。 – Bruno
如果您嘗試實際運行該行(以及以下兩行),則應該有錯誤。我希望它能夠正常工作,因爲ruby test/unit中沒有任何驗證。另外,我認爲它應該是'assert @ driver.element_present?(:link,「logout」)' – Amey