0

I've got this simple test case that tests a login form. For some reason webdriver refuses to run the test and comes back with a "too many redirects" message. The page is just an ordinary login screen, very simple and there are no redirects whatsoever. Access from the server to the page seems ok.

I'm using selenium-webdriver-2.25.0 on a centos server.

Below the error message:

(...)

[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'

(...)

My code:

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

UPDATE

It seems that no matter what url I use for the 'base url' the errors keeps occuring.

Nick Kugaevsky
  • 2,935
  • 1
  • 18
  • 22
B B
  • 3,922
  • 2
  • 18
  • 13
  • also does `verify { assert element_present?(:link, "Logout") } ` seriously work for u ? – Amey Sep 12 '12 at 19:55
  • it seems to be doing its job. We are using selenium IDE and this is an output from that. – B B Sep 13 '12 at 09:19
  • If you try to actually run that line (and the following two lines), there should be an error. I was hoping it works though, because there is no verify in ruby test/unit only assert. Also, I would think it should be `assert @driver.element_present?(:link, "logout")` – Amey Sep 13 '12 at 14:45

1 Answers1

0

I managed to solve this problem myself. The issue was that I was accessing the server through its public facing url (selenium.server.com) instead of through the internal lan url (which bypass the firewall).

Changing that fixed the problem.

B B
  • 3,922
  • 2
  • 18
  • 13