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

selenium template init #1

Merged
merged 26 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
175 changes: 175 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?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>
<driver>chrome</driver>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<aspectj.version>1.9.7</aspectj.version>
<domain>https://jdi-testing.github.io/jdi-light/</domain>
<testng.version>7.8.0</testng.version>
<!-- <allure.testng>2.23.0</allure.testng>-->
AlexeyGirin marked this conversation as resolved.
Show resolved Hide resolved
<!-- <allure.maven>2.12.0</allure.maven>-->
<jetty.version>9.4.12.RC2</jetty.version>
<driver.remote.url />
<log.level>INFO</log.level>
<!-- for JDK 16+ use profile jdk16 -->
</properties>

<profiles>
<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>

<profile>
<id>ci</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<driver.remote.url>http://localhost:4444/wd/hub</driver.remote.url>
<log.level>INFO</log.level>
</properties>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
<!-- Log4j2 Dependency -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.22.0</version>
</dependency>
<!-- WebDriverManager Dependency -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.6.3</version>
</dependency>
<!--Allure-->
<!-- <dependency>-->
<!-- <groupId>io.qameta.allure</groupId>-->
<!-- <artifactId>allure-testng</artifactId>-->
<!-- <version>${allure.testng}</version>-->
<!-- <scope>test</scope>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.testng</groupId>-->
<!-- <artifactId>testng</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <groupId>io.qameta.allure</groupId>-->
<!-- <artifactId>allure-java-commons</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </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>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
<scope>compile</scope>
</dependency>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</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/general.xml</suiteXmlFile>
</suiteXmlFiles>
<argLine>
${aspectj.args}
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<!-- <groupId>io.qameta.allure</groupId>-->
<!-- <artifactId>allure-maven</artifactId>-->
<!-- <version>${allure.maven}</version>-->
<!-- <configuration>-->
<!-- <reportVersion>2.10.0</reportVersion>-->
<!-- </configuration>-->
</plugin>
</plugins>

<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

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

import org.openqa.selenium.WebDriver;
import utilities.ConfigReader;

public abstract class BasePage {

protected WebDriver driver;
protected String baseUrl;
protected String path;
ConfigReader configReader;

public BasePage(WebDriver driver, String path) {
this.driver = driver;
this.configReader = new ConfigReader();
this.baseUrl = configReader.getBaseUrl();
this.path = path;
}

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

import org.openqa.selenium.WebDriver;

// This is an example of Page Object definition. To be removed
public class FirstPage extends BasePage {
private static final String PATH = "/";
private static final String TITLE = "/";

public FirstPage(final WebDriver driver) {
super(driver, PATH);
}
}
23 changes: 23 additions & 0 deletions src/main/java/utilities/ConfigReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package utilities;

import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;

public class ConfigReader {

Configurations configs = new Configurations();
Configuration config;

public ConfigReader() {
try {
config = configs.properties("src/test/resources/config.properties");
} catch (ConfigurationException cex) {
// Something went wrong
}
}

public String getBaseUrl() {
return config.getString("baseUrl");
}
}
31 changes: 31 additions & 0 deletions src/main/java/utilities/DriverFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package utilities;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class DriverFactory {

public static WebDriver createDriver(String browserType) {

WebDriver driver = null;

if(browserType.equalsIgnoreCase("firefox")){
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();

}else if(browserType.equalsIgnoreCase("chrome")){
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();

}else if(browserType.equalsIgnoreCase("edge")){
WebDriverManager.edgedriver().setup();
driver = new EdgeDriver();
}

return driver;
}
}
29 changes: 29 additions & 0 deletions src/main/test/java/test/BaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package test;

import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import utilities.DriverFactory;

@Listeners()
public abstract class BaseTest {

protected WebDriver driver;

@BeforeMethod
public void setUp() {
driver = DriverFactory.createDriver("chrome");
}

@AfterMethod
public void tearDown() {
if (driver != null) {
driver.quit();
}
}

// You can also include other setup and teardown methods,
// logging methods, or other utilities your tests might need.
}

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

import jdk.jfr.Description;
import org.testng.annotations.Test;
import site.pages.FirstPage;

public class ExampleTests extends BaseTest {
FirstPage firstPage = new FirstPage(driver);

@Test
@Description("Test case description for Google Chrome")
public void testMethod() {
firstPage.open();
}
}
27 changes: 27 additions & 0 deletions src/main/test/java/testng/RetryFailedTestCases.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package testng;

import lombok.extern.log4j.Log4j2;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;


@Log4j2
public class RetryFailedTestCases implements IRetryAnalyzer {
private int retryCnt = 0;

// This method will be called everytime a test fails.
// It will return TRUE if a test fails and need to be retried, else it returns FALSE
public boolean retry(ITestResult result) {
// You could mention maxRetryCnt (Maximiun Retry Count) as per your requirement.
// Here I took 2, If any failed testcases then it runs two times
int maxRetryCnt = 1;
if (retryCnt < maxRetryCnt) {
log.info("Retrying " + result.getName() + " again and the count is " + (retryCnt+1));
retryCnt++;
return true;
}
return false;
}

}

19 changes: 19 additions & 0 deletions src/main/test/java/testng/RetryListenerClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package testng;

import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class RetryListenerClass implements IAnnotationTransformer {

@Override
public void transform(ITestAnnotation testannotation, Class testClass, Constructor testConstructor, Method testMethod) {
Class<?> retry = testannotation.getRetryAnalyzerClass();
if (retry == null) {
testannotation.setRetryAnalyzer(RetryFailedTestCases.class);
}

}
}
1 change: 1 addition & 0 deletions src/main/test/resources/config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
baseUrl=https://www.example.com
Loading