Selenium Tutorial - Part 1
Getting Started with Selenium IDE

The topic today is on Selenium, a set of tools used to automate anything that runs on HTML. The essentials of what and how-to will be covered with an emphasis on real-world use, so it will not be exhaustive. This means points will be dealt with speed, since there are other tutorials that can fill in the holes and will be referenced for those that crave adventuring.

Here is how the parts will be split:

We will be skipping over Selenium RC as the costs outweigh the benefits[1] [2]. Selenium IDE is a Firefox only add-on that records Mouse Events and Keystrokes that you have done on a web page and much more. The reason why IDE is important is because it speeds up workflow through its export to code feature, as we will see later. Getting the most from this section involves following along, as this will be kept as short and efficient as possible.

Download Selenium IDE

To begin, download the Selenium IDE Add-on from Firefox from Add-ons at Mozilla.

You should now see the extension in your add-ons and the button your toolbar. If not, expand the [≡] and go to "Customize".

Creating a Test

Clicking the button should expand Selenium IDE. Now, we will begin creating a test for http://docs.seleniumhq.org/.

  1. Set the Base URL to http://docs.seleniumhq.org/
  2. Click the [Red Button] on the right to start recording your tests.

And that's it. Here is a detailed description of the third row left to right:

Button 1: The slider that controls the speed of playback of tests.
Button 2: Playback the Test Suite from the beginning.
Button 3: Playback the Test Case
Button 4: Pause/Resume (Enabled during playback of test)
Button 5: Step (Enabled when pausing test)
Button 6: Rollup (for bunching commands, seems to work better through creating a new command instead)
Button 7: Scheduler (Schedules existing test cases)
Button 8: Record button

A test suite consists of multiple test cases. Test cases are listed on the left, you should see only one test case starting out.
A test case consists of multiple commands. Commands are recorded via the record button.
The slider is important for running tests without web driver, because if the playback is too fast, then the webpage may not load and subsequent tests may fail.

Example TestCase, using docs.seleniumhq.org

Here is our the prime example.

Description of each line:

  1. Open http://docs.seleniumhq.org/
  2. Search and Click the \<a href="/download" > link located on the current page
  3. Click the Document link on the new page.
  4. Click the Download link on the new page.
  5. I have my TestCase paused at the "type" command, which types "server" into the element of id=q.
  6. Click the Submit button. The green triangle means start the Testcase playback here. (Press S or rightclick)
  7. Assert that "Google custom Search" title exists in the new page.
  8. Verify that the value in element id=gsc-i-id1 is "server".

This Testcase XML file generated by Selenium can be downloaded here: 2TestCaseSelenium.html.

After downloading, you import it by going File and Open.

Asserts and Useful commands

There is assertTitle and verifyTitle. Both do the same thing, the difference is if an assert fails then the executing testcase stops, but verify conditions would continue execution.

An easy way to create asserts rather than typing in a new command is through Right-click.

Exporting Tests

We're able to schedule and create tests efficiently, but the Export function provided in the File menu is the most frequently used and experimental. The next part of the tutorial will utilize Selenium WebDriver which is much more flexible and more options for an automated web test. As well, WebDriver is works with any Web Browser.

To avoid writing code, we can export the test case to the language of your choice for Selenium Web Driver then create the necessary functions and have the freedom to make modifications in the language environment. This requires that you have the driver and references created for your test project. Again, this is Part 2 material.

Afterword

Topics not covered here can be found at the references below.

Other Add-ons

You can easily find more add-ons on your own in Add-ons at Mozilla, but these are ones that others have been recommended with Selenium.

FireBug: The super Inspector. Notable features are synchronized mouse hover to show element and right click to show element.
FirePath: Gives a modifiable XPath by Right-Click.
WebDriver Element Locator: Language specific element locator.

Other Tools

Selenium may be all that's needed for web tests. However, there may be times it cannot do what you need (such as automating non-Web-based UI, or better API for automating keystrokes). In these cases, AutoIt and AutoHotkey (IronAHK for Linux/Mac) can be used to complement Selenium. Personally I have a background in AHK, so you may see something of it in the future.

References

Selenium IDE Documentation
SeleniumHQ




Last updated: May 16th, 2016