0

我有一个测试登录表单的简单测试用例。由于某种原因,webdriver 拒绝运行测试并返回“重定向过多”消息。该页面只是一个普通的登录屏幕,非常简单,没有任何重定向。从服务器访问页面似乎没问题。

我在 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 "user@server"
    @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

更新

似乎无论我为“基本网址”使用什么网址,错误都会不断发生。

4

1 回答 1

0

我自己设法解决了这个问题。问题是我通过其面向公众的 url (selenium.server.com) 而不是通过内部 lan url(绕过防火墙)访问服务器。

改变它解决了这个问题。

于 2012-09-12T14:07:34.363 回答