Git Product home page Git Product logo

vanq-java's Introduction

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 http://vanq.org

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

- Switching the navigation of the tests from one page object to another
- Abstracting the test setup into a BaseTest class
- Using TestNG and Gradle to run the tests

Clone the GitHub repo
---------------------

git clone [email protected]:iainrose/vanq-java.git

Creating the IDE project
------------------------

InteliJ
cd ~/<checkout dir>/vanq-java
./gradlew idea

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

Eclipse
cd ~/<checkout dir>/vanq-java
./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.
- Write the test
- Create the Page Object Methods
- Create the Page Object Locators
- Run the test and debug until it passes

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:

- You control when the WebElement will get looked up each time you use the locator which can help avoid stale element exceptions
- You can reuse your locators in methods that assert the presence or absence of a WebElement (return driver.findElements(yourByObjectLocator).size() > 0)
- You can reuse your locators in all the canned ExpectedConditions waits
- Personally I think they look cleaner in the code

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
./gradlew clean test -Dtest.single="MeetingsPageTest"

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

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

To run tests in Chrome
./gradlew 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

vanq-java's People

Contributors

iainrose avatar

Watchers

Vinay B P avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.