-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jdi-templates/5250
Template project for JDN with Selenide
- Loading branch information
Showing
12 changed files
with
412 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,27 @@ | ||
# jdn-template-selenide | ||
Template project for JDN with Selenide | ||
# Selenide Testng empty template | ||
|
||
Empty template for Test Automation project with Selenide | ||
|
||
# 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 placed in src/test/java/test/BaseTest.java | ||
|
||
- baseUrl - base url of your site under tests | ||
- browser - chrome/edge/firefox etc. | ||
- pageLoadTimeout - timeout to wait page load | ||
- headless - to run tests in headless mode, so if you want to hide browser set true | ||
|
||
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". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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-selenide</artifactId> | ||
<version>1.0.0</version> | ||
<name>Template: Selenide 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> | ||
<selenide.version>6.19.1</selenide.version> | ||
<lombok.version>1.18.22</lombok.version> | ||
<allure.version>2.13.6</allure.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> | ||
<!-- Selenide Dependency --> | ||
<dependency> | ||
<groupId>com.codeborne</groupId> | ||
<artifactId>selenide</artifactId> | ||
<version>${selenide.version}</version> | ||
</dependency> | ||
<!-- TestNG--> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<version>${testng.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- Lombok--> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${lombok.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- Allure Selenide--> | ||
<dependency> | ||
<groupId>io.qameta.allure</groupId> | ||
<artifactId>allure-testng</artifactId> | ||
<version>${allure.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.qameta.allure</groupId> | ||
<artifactId>allure-selenide</artifactId> | ||
<version>${allure.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.qameta.allure</groupId> | ||
<artifactId>allure-maven</artifactId> | ||
<version>${allure.maven.version}</version> | ||
<configuration> | ||
<reportVersion>${allure.version}</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>${maven.compiler.plugin.version}</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>${maven.surefire.plugin.version}</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package pages; | ||
|
||
import com.codeborne.selenide.Selenide; | ||
|
||
public abstract class BasePage { | ||
|
||
protected String path; | ||
protected String title; | ||
|
||
protected BasePage(final String title, final String path) { | ||
this.path = path; | ||
this.title = title; | ||
} | ||
|
||
public void openPage() { | ||
Selenide.open(this.path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package pages; | ||
|
||
import com.codeborne.selenide.SelenideElement; | ||
|
||
import static com.codeborne.selenide.Selenide.$; | ||
|
||
public class HomePage extends BasePage { | ||
private static final String PATH = "/"; | ||
private static final String TITLE = "/"; | ||
public SelenideElement moreInformationLink = $("p > a").as("more information link"); | ||
|
||
public HomePage() { | ||
super(TITLE, PATH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package test; | ||
|
||
import com.codeborne.selenide.Configuration; | ||
import com.codeborne.selenide.Selenide; | ||
import com.codeborne.selenide.logevents.SelenideLogger; | ||
import io.qameta.allure.selenide.AllureSelenide; | ||
import org.testng.annotations.AfterSuite; | ||
import org.testng.annotations.BeforeSuite; | ||
import org.testng.annotations.Listeners; | ||
|
||
import static com.codeborne.selenide.FileDownloadMode.FOLDER; | ||
import static java.lang.Boolean.parseBoolean; | ||
import static java.lang.System.getProperty; | ||
|
||
@Listeners() | ||
public interface BaseTest { | ||
String baseUrl = getProperty("base.url", "https://example.com"); | ||
String browser = getProperty("browser", "chrome"); | ||
boolean headless = parseBoolean(getProperty("headless", "true")); | ||
|
||
@BeforeSuite | ||
public static void setUp() { | ||
SelenideLogger.addListener("AllureSelenide", new AllureSelenide().screenshots(true) | ||
.savePageSource(false)); | ||
Configuration.baseUrl = baseUrl; | ||
Configuration.browser = browser; // You can also use "firefox", "edge", etc. | ||
Configuration.pageLoadTimeout = 20000; | ||
Configuration.headless = headless; | ||
Configuration.browserSize = "1920x1200"; | ||
Configuration.screenshots = true; | ||
Configuration.fileDownload = FOLDER; | ||
} | ||
|
||
@AfterSuite | ||
|
||
public static void tearDown() { | ||
SelenideLogger.removeListener("AllureSelenide"); | ||
Selenide.closeWebDriver(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package test; | ||
|
||
import org.testng.annotations.Test; | ||
import pages.HomePage; | ||
|
||
public class ExampleTests implements BaseTest { | ||
HomePage homePage = new HomePage(); | ||
|
||
@Test(description = "Example test") | ||
public void openPageTest() { | ||
homePage.openPage(); | ||
homePage.moreInformationLink.click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package testng; | ||
|
||
import org.testng.IRetryAnalyzer; | ||
import org.testng.ITestResult; | ||
|
||
public class RetryAnalyzer implements IRetryAnalyzer { | ||
|
||
private int retryCount = 0; | ||
private static final int MAX_RETRY_COUNT = 3; | ||
|
||
@Override | ||
public boolean retry(ITestResult iTestResult) { | ||
if (retryCount < MAX_RETRY_COUNT) { | ||
retryCount++; | ||
return true; // Retry the test | ||
} | ||
return false; // No retry | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package testng; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
|
||
import org.testng.IAnnotationTransformer; | ||
import org.testng.annotations.ITestAnnotation; | ||
|
||
public class RetryTransformer implements IAnnotationTransformer { | ||
|
||
@Override | ||
public void transform(ITestAnnotation iTestAnnotation, Class aClass, Constructor constructor, Method method) { | ||
iTestAnnotation.setRetryAnalyzer(RetryAnalyzer.class); | ||
} | ||
} |
Oops, something went wrong.