Labels

Sunday, 14 April 2013

Discovering Selenium and creating a Test Suite


Recently I have been thinking quite a lot about testing...The reason is that I have never been that confident in JUnit and I have always had testers do that side of stuff for me. Well enough is enough, Testing is one of the most important/if not the most important part of development and it's about time I learned how it is done.

Currently at work my job seems to fluctuate between web developer and back-end Java developer. Now I know that Java can use JUnit for unit testing (testing if a method returns what it's supposed to, and what not) but I wasn't sure how to test the web front end stuff.
Then I found Selenium.

On Selenium's home page the question is asked "What is Selenium?"
And the answer is given "Selenium automates browsers."
That's really enough to understand what it is they do. After reading that line I thought "This is exactly what I'm looking for".
I downloaded the Selenium RC server and started messing around with it. The RC edition is useful because it means testing can be done remotely, we can set up the server hub on one machine and create a number of nodes for other machines. This means developers can test there own work before committing it (if they choose to). if this is not for you try looking into the WebDriver edition.
Selenium supports a number of languages including JUnit 4, which is perfect for us. To generate the tests Selenium has an IDE which is a plug-in for Firefox found here. Using this simple IDE you can create scripts (much like a macro) which can be run straight from the IDE or exported into JUnit. Selenium supports a number of browsers (all the major ones) so no need to worry about that, tests can be run in each browser to check for cross platform issues.

So anyway...I decided I would write a whole new Test Suite for the web-based testing. This would save the company a lot of time and make the testing procedure more accurate and less time-consuming.
Before using Selenium all our test cases for our software where in the form of documents. For example we would have a document called "Vehicle Test" and in the document would be the basic testing procedure for adding/editing/deleting a vehicle on our system. This was all done through the web browser and would take roughly 10-15 minuets to complete, this had to be done before every release so as you can imagine, quite laborious.

So I started reading through the test documentation and converting it into JUnit using the Selenium IDE, I was surprised how simple it all was, I didn't have any issues, just click record and then run through the test they way I always had done.

Once completed I just exported the Data to JUnit 4 and slapped it into the test project I had created in my Java IDE. I did have to manually add in assertions to check that validation text was appearing on the page, for example text such as "Please Use Another Name" or "IP address Already Exists". I don't know if there is a way to do that in the IDE just yet, I'm sure there will be. There was also an issue with the FireFox IDE not picking up all the WaitForPageToLoad options, some I needed to add some of these in also.

I would say when working with selenium, don't rely to much on the Firefox IDE Plug-in, just use it as a rough guide to get you started. You will realise you start to learn a lot more about JUnit as you go and eventually you wont use the Plug-in IDE at all.

I will update this post with more info as I learn more about browser automation.

No comments:

Post a Comment