Saturday, November 27, 2010

Selenium’s How-To

Recently I ran into a couple of issues that started affecting some selenium automated tests I was developing, below the issues and solutions implemented:

XHR ERROR: Response_Code = –1 Request Error

When executing the open command the tests started failing with the following error

XHR ERROR: URL = https:// Response_Code = -1 Error_Message = Request Error. on Firefox version 3.6.12 and Selenium RC version 1.0.3

I found that the issue was reported by other users (issue 408 on selenium project page). The open command started working again after making the suggested workaround on comment 4,  calling the open command and passing the second parameter true:

public void CustomOpen(string url)
{     
    commandProcessor.DoCommand("open", new String[] { url, "true" });
}

According to comment 4, the issue was caused by a feature that was supposed to be disabled.

The issue seems to be related to that second parameter (ignoreResponseCode) on the open command and the default value assigned when it is null or empty, there is more details about the fix on commend 14. The fix hasn't been released yet, so if you run into this issue you can use this workaround.

Https pages

When running selenium on development / test environment, usually there is a need to deal with the certificate exceptions thrown by the browser.

I was experiencing the following behavior when running the tests using *firefoxproxy mode, this mode will remember the certificate exception added but if the site is redirected automatically to other location, Selenium throws permission denied exception (I supposed this is related to Same Origin Policy restriction).

Reading a little further, *firefoxproxy mode is supported only for backward compatibility and *firefox mode should be use in Selenium-RC 1.0 beta 2 and later.

I tried the following solutions mentioned here running selenium using *firefox mode:

Both approaches worked, but the test execution experiences a small delay when using RCE.