What is Selenium?
Selenium automates browsers. That's it.
—
SeleniumHQ.org
Simply put, Selenium will help you make the browser do what you do, on it's own. The simplest of examples, is you may want to make it such that you don't have to type in your name and password into a form anymore, therefore, you decide to "record" yourself doing it once and click replay every time you want to do it afterward.
Selenium IDE
Selenium IDE is the tool that will help you do the "recording". It has a very simple user interface. Some would say it's not an IDE at all because of it's deviation from the normal look and feel of a coding tool. However misleading it may seem, this is one very powerful tool.
You do not need the Selenium IDE plugin to do any Selenium testing. However, it could make your experience a lot better and development faster because you will not have to memorize the entire Selenium framework to get your part of your tests running. Below are a few tips that will help you use Selenium IDE.
Record Your Actions
The obvious thing that Selenium does is it records what you are doing. To initialize recording, open selenium IDE by opening Firefox and navigate to Tools->Selenium IDE
You will get the following interface:
When the Red circle
is pressed in, that means you are recording. To stop recording click the red circle. While recording, any of the actions you do on the screen will populate inside the IDE.
Modify Your Targets
You will find out real quick that Selenium IDE doesn’t always choose the best targets right off. Don’t fret though! Instead of having to find out what the xpath or css label for your element is, IDE has done the labor for you
Make sure to pick one that cannot be duplicated on the page by accedent. Otherwise, selenium may get confused.
Fill In The Gaps -- Verify and Assert
Now that you’ve recorded your process, you need to fill in the gaps with tests. For instance, We want to make sure that the password confirmation field works. One way to test that is to hit “Create new account” and then an error dialog pops up. At this point, we need to make a check for the test “The specific passwords do not match.” There are several different commands that can check for text on the page. We have 2 types of checks at our disposal.
- Assert - Use when you want to pass or fail a test.
- Verify - Use when you want to check for something to make a decision on the flow of the test.
In this case we want the test to fail if the words “The specific passwords do not match.” A really easy way to fill in the gaps with verifications and assertions is to simply rightclick on the element you wish to check.
You can also add your own commands manually by clicking somewhere in the list of commands recorded and looking through the dropdown on the IDE. You can type to narrow your choices down if you know what you are looking for.
Note: Use the Reference tab.
Storing Your Tests
The way your store your tests depends on what you want to do with them later. So at this point you got to ask yourself a question:
Do I want to move on to a different testing platform such as a unit tester like PHPUnit?
-OR-
Do I want to stick with what I have now because it's easy?
Well there may be a few other factors. Kinda a pros and cons list that may help you decide first which question you are asking yourself.
Moving on to different testing platform:
Pros:
- You get logic:
- Conditionals: Ifs and eleses.
- Loops: while, for
- easier storage: variables are easier to set and extract
- You can begin automating when tests run.
- You can usually run the Selenium IDE tests unmodified. (backward compatibility)
Cons:
- You can no longer record easily.
- You must set up this testing framework and it's dependencies.
- You must re-write your tests to accommodate the browser closing after each test.
Sticking with Selenium IDE
Pros:
- Simple interface.
- Easy to run.
- Fast to build.
- Software is always up to date due to automatic updates.
Cons:
- Can't do loops making it harder to test items that repeat with unknown lengths
- Cannot reuse portions of tests to simplify steps (functions).
- Harder to have multiple people work on the same tests.
What Else to Do
So... depending on what you decide:
If you plan to move on to more advanced testing:
Separate different features into different Test Suites.
If you plan to stick with what you got now:
Combine all features into the same Test Suite.
However, make sure you separate your tests into logical testcases, and place the tests somewhere they are shared such as a shared drive or in a Version Control System such as git or svn.
Running Your Tests
Make a backup of the database.
The task you are trying to accomplish here is to keep your data the way it is before the test so you can go back to that. This helps especially when you are creating tests because you may find that you need to rerun one that has already run and you aren't able to do that because that particular task can only be performed once on the site. I also suggest you do this on a
copy of your site. Don't ever test on the live one.
Now, this part can get technical. If you aren't the technical type and you are looking for an easy answer to this, you may want to checkout the
backup and migrate module.
If you are the technical type, you can use drush to do a dump with
drush sql-dump
while in the directory of your site. You could also just do a mysql dump to a file if you know what database you are storing to. Regardless, get that data and save it.
Run the Tests!
Now hit that little green play button with the solid rectangles and go! That's it. Watch your tests zip on through. When it's done restore your database if needed and you are done.