iainrose / page-objects

A basic framework for running automated tests using WebDriver w Java, TestNG & Gradle
29 stars 27 forks source link

This project is an example of building a test automation framework using WebDriver w Java, TestNG, Gradle with InteliJ or Eclipse.

It extends the basic tutorial found on the Selenium Wiki and runs a couple of tests against Stack Overflow.

http://code.google.com/p/selenium/wiki/GettingStarted http://code.google.com/p/selenium/wiki/PageObjects

There are a couple of key concepts demonstrated in this project that will help you get started

Creating the IDE project

InteliJ cd ~//page-objects ./gradlew idea

Open the generated page-objects.ipr file and you're good to go. All your dependencies will be automatically resolved and ready to use.

Eclipse cd ~//page-objects ./gradlew eclipse

If you don't want to use Gradle you can also do this manually, as explained here by Simon Stewart aka The WebDriver guy. http://www.youtube.com/watch?v=Eft3qGFoqwE

If you want to update the version of Selenium or TestNG you are using just update the version numbers in build.gradle and rerun the above commands to regenerate your project.

Writing the Tests

I find using a Test Driven (Test) Development approach works well here.

Note also that the tests don't know anything about WebDriver .... keep it that way!

Building the Page Objects

You can use the PageFactory helper to define your locators

http://code.google.com/p/selenium/wiki/PageFactory

However, I prefer to store them as By objects

There are several reasons for this:

Running the tests via the IDE

Right click on the test and select 'run' or 'debug'

Running the tests using Gradle

Unless you have Gradle installed, you'll need to use the Gradle wrapper which is included in the project ./gradlew or gradle.bat on Windows

To run all tests (uses Firefox by default) ./gradlew clean test

To run a single test class ./gradle clean test -Dtest.single="ExampleTest"

To run only tests belonging to group 1 (as defined in the includegroup1 task in build.gradle) ./gradlew clean includegroup1

To run only tests not belonging to group 1 (as defined in the excludegroup1 task in build.gradle) ./gradlew clean excludegroup1

To run tests in Chrome ./gradle clean test -DBROWSER=chrome

To run tests in IE gradle.bat clean test -DBROWSER=internetExplorer

All and any feedback welcome and appreciated, I'm still learning too. @iainrose