Skip to content

Commit

Permalink
Merge pull request #1 from jdi-templates/5249
Browse files Browse the repository at this point in the history
selenium template init
  • Loading branch information
AlexeyGirin authored Jan 22, 2024
2 parents c598ba7 + 4b3a6e6 commit b05b9da
Show file tree
Hide file tree
Showing 14 changed files with 561 additions and 2 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Run tests
env:
ALLURE_VERSION: "2.10.0"

on:
push:
branches:
- main

pull_request:
branches:
- main
release:
types:
- created

jobs:
build:
name: Tests on JDK
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java: [ 11, 17 ]

steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
java-package: jdk
distribution: 'temurin'
cache: 'maven'

- name: Build with Maven
id: build
run: mvn clean install -DskipTests -ntp

- name: Tests
id: functests
timeout-minutes: 10
continue-on-error: true
run: mvn test -ntp

- name: Check tests are passed
if: ${{ steps.functests.outcome != 'success' }}
run: |
echo Tests result: ${{ steps.functests.outcome }}
exit 1
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

# Idea files
*.iml
.idea/
target/

# Allure files
.allure/
allure-results/
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# jdn-template-selenium
Template project for JDN with Selenium
# Selenium Testng empty template

Empty template for Test Automation project with Selenium

# Instruction:

1. Download template and unpack in appropriate folder

2. Open project in IDE (for example IntelliJIdea)

3. Reporting: Allure is enabled, after running tests just run **allure:serve** in maven plugins (allure should be
installed locally)

4. Parameters that can be changed: configure the headless mode, base URL and browser type (chrome/safari/ie/firefox/edg)
by updating the properties in the pom.xml file.

5. TestNg Retry and before after listeners: You can also modify rules of retry tests (now it is 1 retry for each test)
and actions before/after all tests (now it prints test name and result) in **testng** folder

6. pages generated by JDN should be places in src/main/java/pages package

7. Each page object class must be inherited from BasePage, including one of the mandatory paremeters is PATH describing
the URI of the page e.g. in http://example.com/login PATH = "/login".
132 changes: 132 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.epam.jdi</groupId>
<artifactId>jdn-template-selenium</artifactId>
<version>1.0.0</version>
<name>Template: Selenium TestNG Testing project</name>

<properties>
<testng.version>7.8.0</testng.version>
<commons.config.version>2.7</commons.config.version>
<log4j.core.version>2.22.0</log4j.core.version>
<selenium.java.version>3.141.59</selenium.java.version>
<lombok.version>1.18.22</lombok.version>
<webdrivermanager.version>5.6.3</webdrivermanager.version>
<allure.testng.version>2.13.6</allure.testng.version>
<allure.maven.version>2.12.0</allure.maven.version>
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
<maven.surefire.plugin.version>2.22.2</maven.surefire.plugin.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<!-- app parameters-->
<base.url>https://example.com</base.url>
<headless>true</headless>
<browser>chrome</browser>
</properties>

<dependencies>
<!-- Apache Commons Configuration -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>${commons.config.version}</version>
</dependency>
<!-- Log4j2 Dependency -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.core.version}</version>
</dependency>
<!-- Selenium Dependency -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.java.version}</version>
</dependency>
<!-- TestNG Dependency -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<!-- Lombok Dependency -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>test</scope>
</dependency>
<!-- WebDriverManager Dependency -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>${webdrivermanager.version}</version>
</dependency>
<!-- Allure Reporting Dependency -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>${allure.testng.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.12.0</version>
<configuration>
<reportVersion>2.13.6</reportVersion>
<properties>
<property>
<name>allure.results.directory</name>
<value>target</value>
</property>
</properties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<systemPropertyVariables>
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>listener</name>
<value>io.qameta.allure.testng.AllureTestNg</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/test/resources</directory>
</resource>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>

39 changes: 39 additions & 0 deletions src/main/java/configuration/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package configuration;

import static java.lang.Boolean.parseBoolean;

public class Configuration {
private static final Configuration INSTANCE = new Configuration();

private final String baseUrl;
private final String browser;
private final boolean headless;

private Configuration() {
// Initialize configuration properties
this.baseUrl = getProperty("base.url", "https://example.com");
this.browser = getProperty("browser", "chrome");
this.headless = parseBoolean(getProperty("headless", "true"));
}

public static Configuration getInstance() {
return INSTANCE;
}

public String getBaseUrl() {
return baseUrl;
}

public String getBrowser() {
return browser;
}

public boolean isHeadless() {
return headless;
}

private String getProperty(String propertyName, String defaultValue) {
return System.getProperty(propertyName, defaultValue);
}
}

62 changes: 62 additions & 0 deletions src/main/java/pages/BasePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package pages;

import java.util.List;

import configuration.Configuration;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public abstract class BasePage {

public final WebDriver driver;
public final int DEFAULT_TIMEOUT = 30;
protected String baseUrl;
protected String path;

public BasePage(WebDriver driver, String path) {
this.driver = driver;
this.path = path;
baseUrl = Configuration.getInstance()
.getBaseUrl();
PageFactory.initElements(driver, this);
}

public void waitUntilElementVisible(WebElement webElement) {
WebDriverWait wait = new WebDriverWait(driver, DEFAULT_TIMEOUT);
wait.until(ExpectedConditions.visibilityOf(webElement));
}

public void waitUntilElementClickable(WebElement webElement) {
WebDriverWait wait = new WebDriverWait(driver, DEFAULT_TIMEOUT);
wait.until(ExpectedConditions.elementToBeClickable(webElement));
}

public void click(WebElement webElement) {
waitUntilElementClickable(webElement);
webElement.click();
}

public WebElement getElement(WebElement webElement) {
waitUntilElementVisible(webElement);
return webElement;
}

public List<WebElement> getElements(List<WebElement> webElements) {
for (WebElement element : webElements) {
waitUntilElementVisible(element);
}
return webElements;
}

public void sendKeys(WebElement webElement, String text) {
waitUntilElementVisible(webElement);
webElement.sendKeys(text);
}

public void open() {
driver.get(baseUrl + this.path);
}
}
16 changes: 16 additions & 0 deletions src/main/java/pages/HomePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

// This is an example of Page Object definition. To be removed
public class HomePage extends BasePage {
private static final String PATH = "/";
@FindBy(css = "p > a")
public WebElement link;

public HomePage(final WebDriver driver) {
super(driver, PATH);
}
}
Loading

0 comments on commit b05b9da

Please sign in to comment.