2010. június 10., csütörtök

Selenium Framework Structure - Java - Continued

So... Last time we had everything wired up in the framework.

Just watch out to comment enough in your xml file or you will get confused what is what no matter how meaning full names you give your elements.

So you want your tests to run every night and you want your developers to run these tests before they commit.

For the first part it's easy. For the second you need to do some extra work.

You see programmers are lazy people. They don't want to bother to set anything not even editing a config file. So you need to make sure that they can run something with two clicks MAX. Or one command line argument.

So what you need to do is using testng you need to organize your tests into groups. Groups like:

  • Smoke Test

  • Slow Smoke Test

  • Home Page test

  • Login Test

  • User Dashboard settings test

And so on and so fort. You can achieve this by using the java annotation @ at class level.

So like:

@Test(groups = { "DashboardTests" })

After defining groups you can use testng-s xml setting file to create a config that runs only these tests like :

test name="Regression1"



include name="DashboardTests"




This way you are running the group of tests. So every test that is in that particular Class. You then would save this xml into an xml named : AllDashboardTests.xml and the developer needs only to run that one.

Last but not least you need to set your ANT files.

For that i recommend using separated projects under eclipse. Why? Because you have more then one iteration of a web site. You have versions that needs to be automated not just one.

So i recommend using more projects Like:

  • Main automation project: Would contain utility classes, libraries, stuff that is constant over all of your projects

  • Version One: Would contain files specific for this version. UI Elements, Implemented test cases, steps, configuration files.

  • Version Two: Would contain files specific for this version.

So for this structure you need an ant script that can work with all these projects. For that you would have a main script under your Main Automation Project project and several smaller scripts under each version that contains useful information or only linkage to the main script.

The main script would handle everything that is constant over all your projects that means:

  • Building the files

  • Executing tasks like: check style, copying, creating directories

  • Creating report

So your smaller ant script would only contain information like, which testng xml to execute.

I also recommend creating an ant target that starts and stops selenium. So your would only have run something like this:

ant test-start-selenium

This would then run the tests and start selenium too. And stop it too of course. This would look like this:


depends="selenium-start, runtests, selenium-stop"/>


target name="selenium-start"

java jar="${automationframework.dir}/lib/selenium-server-standalone-2.0a4.jar"



arg line="-firefoxProfileTemplate ${firefoxProfileTemplate}"


sleep seconds="1"/



target name="selenium-stop"

get taskname="selenium-shutdown"




So this would start your server ( and add a parameter to it called -firefoxProfileTemplate ). This way all you have to do is execute one little task and it would do everything for you.

Easy eh?

For Hudson and Selenium Grid integration please see this:


I didn't began to write down how to do it, because this tutorial is great for it.

And i didn't quite yet did it myself. :) So i have to do that one too.

I hope you liked my post, if something is left out, please tell me.


Sorry for the bad edit... I gave up with blogger handling xml tags... Damn them.

2 megjegyzés:

  1. Thank you for the wounder full post.

  2. Thanks for the kind words!

    I'm glad you liked it!