Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template project for JDN with Selenide #1

Merged
merged 28 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# jdn-template-selenide
Template project for JDN with Selenide

Setup test configs in "src/test/java/test/BaseTest.java"
129 changes: 129 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?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>
</properties>

<profiles>
AlexeyGirin marked this conversation as resolved.
Show resolved Hide resolved
<profile>
<id>jdk16</id>
<activation>
<jdk>[16, 20]</jdk>
</activation>
<properties>
<aspectj.args>--add-opens java.base/java.lang=ALL-UNNAMED</aspectj.args>
</properties>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.7</version>
</dependency>
<!-- Log4j2 Dependency -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.22.0</version>
</dependency>
<!-- Selenide Dependency -->
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>7.0.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide-core</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.13.6</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-selenide</artifactId>
<version>2.13.6</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>8</source>
<target>8</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>
18 changes: 18 additions & 0 deletions src/main/java/site/pages/BasePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package site.pages;

import com.codeborne.selenide.Selenide;
public abstract class BasePage {


protected String PATH;
protected String TITLE;

public BasePage(final String title, final String path) {
this.PATH = path;
this.TITLE = title;
}

public void openPage() {
Selenide.open(this.PATH);
}
}
15 changes: 15 additions & 0 deletions src/main/java/site/pages/HomePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package site.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);
}
}
33 changes: 33 additions & 0 deletions src/test/java/test/BaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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;

@Listeners()
public interface BaseTest {
@BeforeSuite
public static void setUp() {
SelenideLogger.addListener("AllureSelenide", new AllureSelenide().screenshots(true)
.savePageSource(false));
Configuration.baseUrl = "https://www.example.com";
pnatashap marked this conversation as resolved.
Show resolved Hide resolved
Configuration.browser = "chrome"; // You can also use "firefox", "edge", etc.
pnatashap marked this conversation as resolved.
Show resolved Hide resolved
Configuration.pageLoadTimeout = 20000;
Configuration.headless = false;
Configuration.browserSize = "1920x1200";
Configuration.screenshots = true;
Configuration.fileDownload = FOLDER;
}

@AfterSuite
public static void tearDown() {
SelenideLogger.removeListener("AllureSelenide");
Selenide.closeWebDriver();
}
}
16 changes: 16 additions & 0 deletions src/test/java/test/ExampleTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test;

import io.qameta.allure.Description;
import org.testng.annotations.Test;
import site.pages.HomePage;

public class ExampleTests implements BaseTest {
HomePage homePage = new HomePage();

@Test
@Description("Example Test")
public void openPageTest() {
homePage.openPage();
homePage.moreInformationLink.click();
}
}
19 changes: 19 additions & 0 deletions src/test/java/testng/RetryAnalyzer.java
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
}
}
15 changes: 15 additions & 0 deletions src/test/java/testng/RetryTransformer.java
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);
}
}
61 changes: 61 additions & 0 deletions src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="30" status="warn">

<Properties>
<Property name="logFileName">jdiEvents</Property>
<Property name="baseDir">./target/.logs</Property>
</Properties>

<Appenders>
<Console name="consoleAppender" target="SYSTEM_OUT" ignoreExceptions="false">
<PatternLayout pattern="%d{mm:ss.SS} [%c:%p]: %m%n"/>
</Console>

<RollingFile name="fileAppender" fileName="${baseDir}/${logFileName}.log">
<FilePattern>${baseDir}/${logFileName}_%d{yyyy-MM-dd__HH-mm}_%i.log</FilePattern>
<PatternLayout>
<Pattern>%d{HH:mm:ss} [%t] %-5level %logger{6} - %msg%n</Pattern>
</PatternLayout>

<Policies>
<TimeBasedTriggeringPolicy interval="10" modulate="true"/>
<SizeBasedTriggeringPolicy size="250 MB"/>

</Policies>
<DefaultRolloverStrategy min="1" max="5" fileIndex="max">
<Delete basePath="${baseDir}" maxDepth="5">
<IfFileName glob="${logFileName}_*.log"/>
<testMode>false</testMode>
<IfAccumulatedFileCount exceeds="2"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>

<RollingFile name="htmlFileLogger" fileName="${baseDir}/app-info.html"
filePattern="${baseDir}/app-info-%d{yyyy-MM-dd}.html">
<HTMLLayout charset="UTF-8" title="Info Logs" locationInfo="true"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
</Appenders>


<Loggers>
<!-- Every configuration must have a root logger. If one is not configured the default root LoggerConfig is ERROR with Console appender attached. -->
<Root level="INFO">
<AppenderRef ref="fileAppender"/>
<AppenderRef ref="htmlFileLogger"/>
<AppenderRef ref="consoleAppender"/>
</Root>

<!-- additivity means, that parent-logger (in every case the root-logger) will also get the chance to log this stuff -->
<Logger name="JDI" additivity="FALSE" level="INFO">
<AppenderRef ref="fileAppender"/>
<AppenderRef ref="htmlFileLogger"/>
<AppenderRef ref="consoleAppender"/>
</Logger>

</Loggers>
</Configuration>
15 changes: 15 additions & 0 deletions src/test/resources/testng.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="WINDOWS-1251"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
AlexeyGirin marked this conversation as resolved.
Show resolved Hide resolved
<suite name="Site test" parallel="classes" thread-count="6">
<test name="Tests">
<packages>
<package name="test" />
</packages>
<classes>
<class name="test.ExampleTests" />
</classes>
</test>
<listeners>
<listener class-name="testng.RetryTransformer" />
<listener class-name="io.qameta.allure.testng.AllureTestNg" />
</listeners>
</suite>