SiKing

March 1, 2011

Upgrading to Selenium 2

Filed under: automation — SiKing @ 9:48 am

Current release (as of 2/28/2011) of Selenium is 2.0b2; there is no proposed final release date, only a list of tasks that must be completed before a final release is considered by the project. Historically, the Selenium project has taken a very long time (years) before any major release.

Impact to existing test suite

One of the goals of Selenium 2 is to maintain downwards compatibility. This is accomplished by providing the same library (ThoughtWorks.Selenium.Core.dll) that was initially shipped with Selenium 1. Java, C#, and Python libraries are all available; other languages appear to have been abandoned.

After replacing this library, our current solution still compiles with no problems.

Replacing the Selenium Server with version 2 and running the test suite, some tests fail. Most problems come from evaluating XPath statements for locating various elements. With minimal effort, I was able to get all the Smoke tests to pass.

New functionality

Selenium 2 comes with two new major features: new browser support and “WebDriver”.

Browser support

Selenium 2 has support for both Android and iPhone. These platforms are currently not supported by any of our software, but are interesting anyway.

It should be noted that some of the browsers that were natively supported by Selenium 1, such as Safari, no longer have native support in Selenium 2. This also has no current impact to us.

Selenium 2 also supports “HtmlUnit”, which is a mode that does not require any browser to be running or even installed on the test machine. The only thing that is required for this is the classic Java Selenium Server. However, in order to take advantage of this mode some parts of the existing framework will have to be rewritten.

WebDriver

This is a new technology that Selenium 2 was built on, which gives the tests direct access to the browser without the need to run an intermediary proxy server – the classic Selenium Server. Tests written using the WebDriver are much friendlier and the resulting code is much more expressive.


        IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl(“http://test.server.local/Processor”);

IWebElement entityBox = driver.FindElement(By.Id(“cgUserName_txtEntityKey”));
IWebElement userBox = driver.FindElement(By.Id(“cgUserName_txtUserName”));
IWebElement submitBtn = driver.FindElement(By.XPath(“//input[@value=’Submit’]”));
entityBox.SendKeys(“testEntity”);
userBox.SendKeys(“autoghost”);
Console.WriteLine(entityBox.Value);
submitBtn.Click();

IWebElement passwordBox = driver.FindElement(By.Id(“cgPassword_txtPassword”));
IWebElement loginBtn = driver.FindElement(By.XPath(“//input[@value=’Login’]”));
passwordBox.SendKeys(“qwerty123”);
loginBtn.Click();

driver.Quit();

Additional code examples can be found on the Selenium website. This mode requires browser-specific libraries (currently available for Firefox, Internet Explorer, Chrome, and the above mentioned HtmlUnit). Other browsers can be run in emulation mode. It is possible in Selenium 2, that all these modes, including Selenium 1 tests, can all live side-by-side.

The WebDriver technology is much less bound to the NUnit framework, and in fact any framework including a completely custom in-house can easily be supported.

Existing tests would have to be rewritten in order to take full advantage of the WebDriver functionality.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: