Friday, November 22, 2013

How To Create Test Suites

Test Suites


We have managed to create a number of tests using Selenium IDE and have managed to run
them successfully. The next thing to have a look at is how to create a test suite, so that we
can open the test suite and then have it run a number of tests that we have created.

1. Click New Test Case.
2. You will see that Selenium IDE has opened a new area on the left of the IDE as
shown in the following screenshot:





You can do this as many times as you want and when the Play entire test suite button is
clicked it will run all the tests in the test suite. It will log all the passes and failures at the
bottom of the Test Case box.
To Save this, click on the File menu and then click Save Test Suite and save the Test Suite file
to somewhere that you can get to again. One thing to note is that saving a test suite does not
save the test case. Make sure that you save the test case every time you make a change and
not just the test suite.
To change the name of the test case to something a lot more meaningful you can do this by
right-clicking on the test and clicking on the Properties item in the context menu:



You can now add meaningful names to your tests and they will appear in Selenium IDE
instead of falling back to their filenames.

We have managed to create our first test suite. This can be used to group tests together to
be used later. If your tests have been saved, you can update the test suite properties to give
the tests a name that is easier to read.

Monday, November 11, 2013

How Storing information from the page in the test

Storing information from the page in the test



Sometimes there is a need to store elements that are on the page to be used later in a test.
This could be that your test needs to pick a date that is on the page and use it later so that
you do not need to hardcode values into your test.
Once the element has been stored you will be able to use it again by requesting
it from a JavaScript dictionary that Selenium keeps track of. To use the variable it
will take one of the following two formats: it can look like ${variableName} or
storedVars['variableName']. I prefer the storedVars format as it follows
the same format as it is within Selenium internals.

1. Open up Selenium IDE and switch off the Record button.
2. Navigate to http://book.theautomatedtester.co.uk/chapter1.
3. Right-click on the text Assert that this text is on the page and go to the storeText
command in the context menu and click on it.
4. A dialog will appear as shown in the following screenshot. Enter the name
of a variable that you want to use. I have used textOnThePage as the name
of my variable.




5. Click on the row below the storeText command in Selenium IDE.
6. Type type into the Command textbox.
7. Type storeinput into the Target box.
8. Type ${textOnThePage} into the Value box.
9. Run the test. It should look like the following screenshot:



Once your test has completed running you will see that it has placed Assert that this text is
on the page into the textbox.


We have successfully created a number of tests and have seen how we can work against
AJAX applications but unfortunately creating tests that run perfectly first time can be
difficult. Sometimes, as a test automator, you will need to debug your tests to see
what is wrong.
To work through this part of the chapter you will need to have a test open in Selenium IDE.


These two steps are quite useful when your tests are not running and your want to execute a
specific command.
1. Highlight a command.
2. Press the X key, this will make the command execute in Selenium IDE.



When a test is running you can press the Pause button to pause the test after the step that is
currently being run. Once the test has been paused the Step button is no longer disabled and
you can press it to step through the test as if you were stepping through an application.
If you are having issues with elements on the page you can type in their location and then
click on the Find button. This will surround the element that you are looking for with a green
border that flashes for a few seconds.

The echo command is also a good way to write something from your test to the log. This is
equivalent to Console.log in JavaScript. For example, echo | ${variableName}.
Also remember that if you are trying to debug a test script that you have created with
Selenium IDE, you can set breakpoints in your test. You simply right-click on the line and
select breakpoint from the list.