Polonium


License

License

GroupId

GroupId

com.oakfusion
ArtifactId

ArtifactId

polonium
Last Version

Last Version

1.2
Release Date

Release Date

Type

Type

jar
Description

Description

Polonium
Polonium

Download polonium

How to add to project

<!-- https://jarcasting.com/artifacts/com.oakfusion/polonium/ -->
<dependency>
    <groupId>com.oakfusion</groupId>
    <artifactId>polonium</artifactId>
    <version>1.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.oakfusion/polonium/
implementation 'com.oakfusion:polonium:1.2'
// https://jarcasting.com/artifacts/com.oakfusion/polonium/
implementation ("com.oakfusion:polonium:1.2")
'com.oakfusion:polonium:jar:1.2'
<dependency org="com.oakfusion" name="polonium" rev="1.2">
  <artifact name="polonium" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.oakfusion', module='polonium', version='1.2')
)
libraryDependencies += "com.oakfusion" % "polonium" % "1.2"
[com.oakfusion/polonium "1.2"]

Dependencies

compile (11)

Group / Artifact Type Version
junit : junit jar 4.11
org.seleniumhq.selenium : selenium-server jar 2.43.1
org.seleniumhq.selenium : selenium-java jar 2.43.1
org.apache.httpcomponents : httpclient jar 4.3.4
commons-codec : commons-codec jar 1.9
com.github.detro.ghostdriver : phantomjsdriver jar 1.1.0
commons-configuration : commons-configuration jar 1.10
xml-apis : xml-apis jar 1.4.01
org.slf4j : slf4j-api jar 1.7.6
org.slf4j : jcl-over-slf4j jar 1.7.6
org.apache.commons : commons-lang3 jar 3.3.2

test (1)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.1.2

Project Modules

There are no modules declared in this project.

Polonium's logo

polonium-project

Polonium project uses concept of Page Object pattern.

##Maven Maven dependency:

<dependency>
	<groupId>com.oakfusion</groupId>
	<artifactId>polonium</artifactId>
	<version>1.1</version>
</dependency>

##Page Object classes in Polonium

First of all you need to create Page Object class annotated with @PageFragment(url = "<page_url_here>"). Moreover this class has to extend com.oakfusion.polonium.BasePageFragment class.

Notice: if you would like to have method in your Page Object class, which returns different Page Object, please use next(Class<T> clazz) method from parent class. Then you will be able to use instance of returned class in your test class.

Page Object example:

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import com.oakfusion.polonium.BasePageFragment;
import com.oakfusion.polonium.annotations.PageFragment;

@PageFragment(url = "http://tutorialapp.saucelabs.com")
public class ShootoutMainPage extends BasePageFragment {

	@FindBy(xpath = "//a[@href='http://tutorialapp.saucelabs.com/register']")
	private WebElement registerLink;

	public ShootoutRegisterPage openRegisterPage() {
		registerLink.click();
		return next(ShootoutRegisterPage.class);
	}
}

##Test classes in Polonium

Test class needs to be annotated with @RunWith(PoloniumRunner.class) annotation. All class' members annotated with @PageFragment will be instantiated and injected by Polonium framework.

Notice: First page of flow which you are testing, should be open with open() method.

Test class example:

import org.junit.Test;
import org.junit.runner.RunWith;
import com.oakfusion.polonium.PoloniumRunner;
import com.oakfusion.polonium.annotations.PageFragment;

import static org.junit.Assert.assertEquals;

@RunWith(PoloniumRunner.class)
public class ShootoutTest {

	@PageFragment
	ShootoutMainPage shootoutMainPage;

	@Test
	public void shouldContainH1Text() {
		shootoutMainPage.open();
		ShootoutRegisterPage shootoutRegisterPage = shootoutMainPage.openRegisterPage();
		assertEquals("Register", shootoutRegisterPage.getH1Content());
	}
}

##Using specific WebDrivers

Polonium by default uses org.openqa.selenium.htmlunit.HtmlUnitDriver driver with enabled JavaScript.

Polonium supports few more drivers:

  • FirefoxDriver
  • ChromeDriver
  • PhantomJSDriver
  • InternetExplorerDriver

###Using FirefoxDriver Annotate your test class with com.oakfusion.polonium.annotations.PoloniumConfiguration annotation: @PoloniumConfiguration(driver = PoloniumConfiguration.Driver.FIREFOX)

Notice: Firefox browser is required in your operating system.

###Using ChromeDriver To use it, you need to download ChromeDriver standalone server. You can do it in two different ways:

  • by downloading it manually from here and then use annotation: @PoloniumConfiguration(driver = PoloniumConfiguration.Driver.CHROME, pathToDriver = "<path_to_ChromeDriver_standalone_server>")

  • or by using Maven. We release each new version of ChromeDriver as a Maven dependency so it is available from Maven Central. All you need to do, is configuring Maven Dependency Plugin in your pom.xml:

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-dependency</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>unpack</goal>
						</goals>
						<configuration>
							<artifactItems>
								<artifactItem>
									<groupId>com.oakfusion</groupId>
									<artifactId>chromedriver-dep</artifactId>
									<version>2.9</version>
									<type>jar</type>
									<overWrite>true</overWrite>
									<outputDirectory>/${settings.localRepository}/com/oakfusion/chromedriver-dep</outputDirectory>
								</artifactItem>
							</artifactItems>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

Then run mvn test to trigger downloading and unpacking the driver to /${settings.localRepository}/com/oakfusion/chromedriver-dep. Polonium will be looking for the server in this directory so you don't have to specify path to it: @PoloniumConfiguration(driver = PoloniumConfiguration.Driver.CHROME)

Notice: Chrome browser is required in your operating system.

###Using PhantomJSDriver PhantomJSDriver requires PhantomJS in your operating system. You can:

  • download PhantomJS manually from here and then use annotation: @PoloniumConfiguration(driver = PoloniumConfiguration.Driver.PHANTOMJS, pathToDriver = "<path_to_PhantomJS_binary_file>")

  • or use Maven in the same way like with ChromeDriver standalone server:

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-dependency</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>unpack</goal>
						</goals>
						<configuration>
							<artifactItems>
								<artifactItem>
									<groupId>com.oakfusion</groupId>
									<artifactId>phantomjs-dep</artifactId>
									<version>1.9.7</version>
									<type>jar</type>
									<overWrite>true</overWrite>
									<outputDirectory>/${settings.localRepository}/com/oakfusion/phantomjs-dep</outputDirectory>
								</artifactItem>
							</artifactItems>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

Then run mvn test to trigger downloading and unpacking the driver to /${settings.localRepository}/com/oakfusion/phantomjs-dep. Polonium will be looking for the PhantomJS in this directory so you don't have to specify path to it: @PoloniumConfiguration(driver = PoloniumConfiguration.Driver.PHANTOMJS)

###Using InternetExplorerDriver To use it, you need to download standalone server (IEDriverServer). You can do it in two different ways:

  • by downloading it manually from here and then use annotation: @PoloniumConfiguration(driver = PoloniumConfiguration.Driver.IE, pathToDriver = "<path_to_IEDriverServer_binary_file>")

  • or by using Maven and Maven Dependency Plugin:

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-dependency</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>unpack</goal>
						</goals>
						<configuration>
							<artifactItems>
								<artifactItem>
									<groupId>com.oakfusion</groupId>
									<artifactId>iedriver-dep</artifactId>
									<version>2.40.0</version>
									<type>jar</type>
									<overWrite>true</overWrite>
									<outputDirectory>/${settings.localRepository}/com/oakfusion/iedriver-dep</outputDirectory>
								</artifactItem>
							</artifactItems>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

Then run mvn test to trigger downloading and unpacking the driver to /${settings.localRepository}/com/oakfusion/iedriver-dep. Polonium will be looking for the server in this directory so you don't have to specify path to it: @PoloniumConfiguration(driver = PoloniumConfiguration.Driver.IE)

Notice: Internet Explorer browser is required in your operating system.

##Waiting for web elements on the page. Sometimes you will need to wait for some elements to be visible on page before you continue testing. Polonium supports such situations and comes with com.oakfusion.polonium.annotations.WaitFor annotation. Using this annotation You can specify for which web elements you want to wait for. There is two ways to achieve that:

  • when You use those elements as class members:
@PageFragment(url = "http://localhost:8080/")
@WaitFor({"boxNumber2", "link"})
public class LocalhostAfterClickPage extends BasePageFragment {

	@FindBy(id = "boxNo2")
	private WebElement boxNumber2;

	@FindBy(partialLinkText = "Lin")
	private WebElement link;

	public String getLinkText() {
		return link.getText();
	}

}
  • when You only want to wait for specific element: @WaitFor( partialLinkText = "Lin" )

##Screenshots after failing tests. When you specify different driver than HtmlUnitDriver, Polonium will do the screenshot of each failed test and will place it in target/polonium/screenshots directory.

Versions

Version
1.2
1.1
1.0