Skip to content

kunal-piplani-incontact/java-testng-selenium

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

testng-selenium

Remove the TestNG Selenium boilerplate.

Overview

  1. Overview
  2. Project Goals
  3. Maven Dependency
  4. Writing Suites
  5. Writing a Page Factory
  6. Writing a Page Object
  7. Configuring

Project Goals

  • Configuration through Property Files, System properties and annotations.
  • Facilitate running tests in parallel.
  • Remove typical boilerplate, such as taking screenshots on test failures, configuring WebDriver, and instantiating page objects.
  • Declarative way of defining page objects with PageFactory.
  • Declarative way of configuring tests individually.

Maven Dependency

You can add TestNG-Selenium to your existing project as follows:


For new projects, you can quickly get setup by using the following command at a terminal:
```shell mvn archetype:generate \ -DarchetypeGroupId=com.github.jsdevel \ -DarchetypeArtifactId=testng-selenium-archetype ```

Writing Suites

In each of your suite classes, extend AbstractSuite and pass your PageFactory as a generic type argument.


AbstractSuite provides a getPageFactory method to create the page factories passed in as generic type arguments. In this example, the page factory passed as a generic type on line 7 is returned by getPageFactory.

Writing a Page Factory

A PageFactory is nothing more than an interface:


Each method declared in a PageFactory should return a sub class of AbstractPage. This allows TestNG-Selenium to do some cool things when initializing your page objects, like navigating to them when WebDriver has been created, wiring up annotated fields using Selenium's PageFactory initializer, and validating that the URL currently being viewed by WebDriver is valid for the requested page. This approach also allows you to avoid boilerplate by letting TestNG-Selenium manage your page factory's lifecycle.

Writing a Page object.

  1. Create a class I.E. GoogleHomePage
  2. Extend com.github.jsdevel.testng.selenium.AbstractPage.
  3. Pass your page object's type, and the page factory used to create it as generic type arguments to AbstractPage.
  4. Optionally add WebElement fields annotated with @FindBy (see Google's PageFactory pattern.).


If you need to do something before validation occurs, such as wait for requests, or poll a global javascript variable, you can override AbstractPage#handlePageInitialized().

Configuring

TestNG-Selenium may be configured in one of 3 ways:
  • Properties File
  • System Properties
  • Annotations
In general, annotation based configuration overrides system based configuration on a per test basis.

Property File Based Configuration

TestNG-Selenium will look for a file called "testng-selenium.properties" at the root of your classpath. If found, then values contained therein will override the default configuration values. The key value pairs are the same as they are for System Based Configuration.

System Based Configuration

System based configuration is driven by System properties. System properties override both properties file and default configuration.
Here is a list of the system properties recognized by TestNG-Selenium with their default values:

Annotation Based Configuration

Annotation based configuration can override the default configuration, properties file annotation, and system based configuration for a single test run.
Here is an example of how we can override a system property using an annotation for a single test run. For the full list of supported annotations, see package contents under com.github.jsdevel.annotations.

About

Remove the TestNG Selenium boilerplate.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.6%
  • Shell 0.4%