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

Selenium Framework Structure - Java - Continued

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"

groups

run

include name="DashboardTests"

run

groups

test

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

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: