How to set up selenium grid to test Internet Explorer from a Mac or Linux computer

This blog post explains how to set up Selenium Grid to run your selenium-powered tests on another computer or virtual machine. In this example, you currently run an rspec test suite on a Mac using the selenium-webdriver gem, but you’d like your application to work in Internet Explorer. The example application can be found here. I made it for this blog post, and styled the code to be as simple as possible for learning purposes.

Since Internet Explorer doesn’t run on Macs you could install a VM with Windows on it, and test out the site by hand. But by using the instructions in this blog post, you can simply run your existing test suite directly on IE. The instructions can easily be adapted to other operating systems and web browsers.

First, install VirtualBox on your Mac. VirtualBox is free and open source software that runs on Windows, Linux, Mac and other host systems. Go here to download VirtualBox.

Either install a legitimate copy of Windows in a VirtualBox VM, or download one from modern.ie. I don’t recommend pirating Windows, not least because most pirated copies online are full of exploits and viruses and such things. Go here to download a free, legitimate Windows VirtualBox image from Microsoft. If you already have Windows installed using other VM software, that will work fine too. In fact, these instructions will work even if Windows is on a different computer, e.g. if you have a Windows laptop laying around you can use for this.

Launch your Windows VM. Make sure the Windows VM and your Mac can ping each other over the network. If you have trouble with this when using VirtualBox, shut down your Windows VM, then go into the settings for your Windows VM. Choose Network, and for Adapter 1 “Attached to” choose Bridged Adapter. This will place the VM on the same network subnet as your main computer. When you start the Windows VM back up, launch a command prompt by clicking the Start menu and running “cmd”. Then run “ipconfig” to find your IP address. Once your Windows VM and Mac can ping each other, move on to the next step.

Install Java on both your host computer and the Windows VM. Go here to download Java.

Download the Selenium Grid binary jar file to both your Mac and your Windows VM. Go to the following link and click the folder with the highest version number. In that folder, download the file named selenium-server-standalone-????.jar with the ???? replaced by the version number. Go here to download Selenium Grid.

Download the Internet Explorer Driver to your Windows VM only. It is in the same folder as the Selenium Grid binary. The filename for the 32-bit version is IEDriverServer_Win32_????.zip, again with ???? replaced with the latest version number.

On the Windows VM, unzip the IEDriverServer file you downloaded. Then place the .exe file that comes out in a directory in the Windows PATH. One such directory is C:\Windows\.

Now we need one selenium grid hub, and one node. The Mac will be the hub, and Windows will be the node. On the Mac go to the directory with the selenium-server-standalone file you downloaded earlier. Then run (replacing the selenium-server stuff with the actual filename):

java -jar selenium-server-standalone-????.jar -role hub

You will see some console output about “Launching a selenium grid server”. Now go to the url http://localhost:4444/grid/console. You should see that your hub is up and running, but not offering any browsers yet.

Before you begin this step, make a note of your Mac’s IP address. Let’s say it is 192.168.0.3. Now go to your Windows VM and open a command prompt. Navigate to the selenium-server-standalone-????.jar file directory, and execute the following command, replacing the ???? with the proper filename, and 192.168.0.3 with your actual Mac’s IP address:

java -jar selenium-server-standalone-????.jar -role node -hub http://192.168.0.3:4444/grid/register

You should see some terminal output about “Launching a selenium grid node”. Now go back to your grid console webpage and refresh it. The one at http://localhost:4444/grid/console. You should see some web browsers on offer! You now have a selenium grid running.

Now it is time to run a test over the grid. Go to my sample project on github here.

Follow the sample project’s instructions and get the server and tests running locally. Once you have done that, use git to checkout the selenium_grid branch. Then open the spec/index_page_spec.rb file in a text editor. You will see the following code in a before block

@firefox = Selenium::WebDriver.for(:remote, desired_capabilities: :internet_explorer)

@firefox.navigate.to(“http://192.168.0.20:3000“)

Edit the IP address on the navigate.to argument to be your Mac’s IP address. Then in the project’s root directory run bundle exec rspec. In your Windows VM you should see Internet Explorer launch, visit the webpage, and close, followed by rspec reporting that the test passed.

Congratulations! You have set up a minimal selenium grid and run a test using rspec against a local web application. I hope this guide was useful for you, please leave any questions in the comments!

References

The Selenium Grid wiki

Hacker News discussion of this post

Advertisements

One thought on “How to set up selenium grid to test Internet Explorer from a Mac or Linux computer

  1. anoopvdk says:

    Hey,

    Thanks for this great blog post.
    I was following your post until running the sample project and I tried to run my project instead of that but I got an error
    {code}
    Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleap is.com/index.html
    {code}

    I added IEDriver path to %PATH variable in node machine (VM) but that didn’t help.

    I’d appreciate if you could give me any hint to resolve that issue?

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

%d bloggers like this: