├── reports
└── .gitkeep
├── screenshot
└── .gitkeep
├── test_data.xlsx
├── .gitignore
├── src
├── main
│ ├── java
│ │ └── base
│ │ │ ├── extentPkg
│ │ │ ├── Extent.java
│ │ │ ├── BTest.java
│ │ │ ├── ExtentTestSample1.java
│ │ │ ├── ExtentManager.java
│ │ │ └── ExtentTestSample.java
│ │ │ ├── T1.java
│ │ │ ├── ExtentReport.java
│ │ │ ├── App.java
│ │ │ ├── ExtentManager.java
│ │ │ ├── driver
│ │ │ ├── PageDriver.java
│ │ │ ├── BaseTest.java
│ │ │ └── DriverFactory.java
│ │ │ ├── Util.java
│ │ │ └── ExcelReader.java
│ └── resources
│ │ └── logback.xml
└── test
│ └── java
│ ├── testCases
│ ├── TestLogin_invalid.java
│ ├── TestLogin.java
│ └── TestProductItems.java
│ ├── old
│ ├── SampleSelenium.java
│ └── SamplePF.java
│ └── pages
│ ├── BasePage.java
│ ├── LoginPage.java
│ └── ProductsPage.java
├── testng.xml
├── docker
├── docker-compose-standalone.yml
└── docker-compose-hubnode.yml
├── testng_dockerC_parallel.xml
├── jenkins
└── jenkinsfile
├── README.md
├── .github
└── workflows
│ └── maven.yml
└── pom.xml
/reports/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/screenshot/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test_data.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunilpatro1985/SeleniumJavaFramework/HEAD/test_data.xlsx
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | /target
3 | /.settings
4 | .classpath
5 | .factorypath
6 | .project
7 | /test-output/
8 | /reports/
9 | /screenshot/
--------------------------------------------------------------------------------
/src/main/java/base/extentPkg/Extent.java:
--------------------------------------------------------------------------------
1 | package base.extentPkg;
2 |
3 | import com.aventstack.extentreports.ExtentTest;
4 |
5 | public class Extent {
6 |
7 | private static ExtentTest test;
8 |
9 | public static ExtentTest getTest(){
10 | return test;
11 | }
12 |
13 | public static void setTest(ExtentTest test){
14 | Extent.test = test;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/base/T1.java:
--------------------------------------------------------------------------------
1 | package base;
2 |
3 | import org.slf4j.Logger;
4 | import java.lang.invoke.MethodHandles;
5 | import org.slf4j.LoggerFactory;
6 |
7 | public class T1 {
8 |
9 | public static void main(String []args) {
10 | final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
11 | //final Logger logger = LoggerFactory.getLogger(T1.class);
12 |
13 | logger.info("this is info message");
14 | logger.error("this is error message");
15 | logger.info("this is info");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/testng.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/main/java/base/ExtentReport.java:
--------------------------------------------------------------------------------
1 | package base;
2 |
3 | import base.extentPkg.Extent;
4 | import com.aventstack.extentreports.ExtentTest;
5 |
6 | public class ExtentReport {
7 | //private static ExtentTest test;
8 | private static final ThreadLocal extentTest
9 | = new ThreadLocal();
10 |
11 | public static ExtentTest getTest(){
12 | return extentTest.get();
13 | }
14 |
15 | public static void setTest(ExtentTest test){
16 | extentTest.set(test);
17 | //Extent.test = test;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/base/extentPkg/BTest.java:
--------------------------------------------------------------------------------
1 | package base.extentPkg;
2 |
3 | import com.aventstack.extentreports.ExtentTest;
4 | import org.testng.ITestResult;
5 | import org.testng.annotations.AfterSuite;
6 | import org.testng.annotations.BeforeMethod;
7 |
8 | public class BTest {
9 |
10 | @BeforeMethod
11 | public void setUp(ITestResult result){
12 | ExtentTest test = ExtentManager.getInstance().createTest(result.getMethod().getMethodName());
13 | Extent.setTest(test);
14 | }
15 |
16 | @AfterSuite
17 | public void tearDown(){
18 | ExtentManager.getInstance().flush();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/base/App.java:
--------------------------------------------------------------------------------
1 | package base;
2 |
3 | public class App {
4 |
5 | public static String browser = System.getProperty("browser", "chrome");
6 | public static String stage = System.getProperty("stage", "qa");
7 | public static String validUserName = System.getProperty("validUserName", "standard_user");
8 | public static String validPassword = System.getProperty("validPassword", "secret_sauce");
9 | public static String inValidpassword = System.getProperty("inValidpassword", "chrome");
10 | public static String platform = System.getProperty("platform", "local");
11 | public static String enableBrowserOptions = System.getProperty("enableBrowserOptions", "false");
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/base/extentPkg/ExtentTestSample1.java:
--------------------------------------------------------------------------------
1 | package base.extentPkg;
2 |
3 | import com.aventstack.extentreports.Status;
4 | import org.testng.annotations.Test;
5 |
6 | public class ExtentTestSample1 extends BTest{
7 |
8 | @Test
9 | public void MainTest1(){
10 |
11 |
12 | //ExtentTest test = ExtentManager.getInstance().createTest("MyTest1111");
13 | Extent.getTest().log(Status.INFO, "launching browser FF");
14 |
15 | //verify
16 | Extent.getTest().log(Status.FAIL, "Test spelling not correct bb");
17 |
18 | //verify
19 | Extent.getTest().log(Status.WARNING, "alert test not correct");
20 |
21 | //to-dox`
22 | //verify
23 | //test.pass("Test case passed");
24 | Extent.getTest().pass("");
25 |
26 |
27 |
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/base/extentPkg/ExtentManager.java:
--------------------------------------------------------------------------------
1 | package base.extentPkg;
2 |
3 | import com.aventstack.extentreports.ExtentReports;
4 | import com.aventstack.extentreports.reporter.ExtentSparkReporter;
5 |
6 | public class ExtentManager {
7 | static ExtentReports report;
8 | public static ExtentReports getInstance(){
9 | if(report == null){
10 | ExtentSparkReporter spark = new ExtentSparkReporter("spark.html");
11 | report = new ExtentReports();
12 |
13 | //spark.config().setTheme(Theme.DARK);
14 | spark.config().setDocumentTitle("My own report");
15 | spark.config().setEncoding("utf-8");
16 | spark.config().setReportName("My report");
17 |
18 | report.attachReporter(spark);
19 | }
20 |
21 |
22 | return report;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/docker/docker-compose-standalone.yml:
--------------------------------------------------------------------------------
1 | version: '3.8'
2 |
3 | services:
4 | chrome:
5 | image: selenium/standalone-chrome:4.7.2
6 | hostname: chrome
7 | privileged: true
8 | shm_size: 2g
9 | ports:
10 | - "4441:4444"
11 | - "7900:7900"
12 | environment:
13 | - SE_VNC_NO_PASSWORD=1
14 | - SE_NODE_MAX_SESSIONS=3
15 |
16 | firefox:
17 | image: selenium/standalone-firefox:4.7.2
18 | hostname: firefox
19 | privileged: true
20 | shm_size: 2g
21 | ports:
22 | - "4442:4444"
23 | - "7901:7900"
24 | environment:
25 | - SE_VNC_NO_PASSWORD=1
26 | - SE_NODE_MAX_SESSIONS=3
27 |
28 |
29 | #Turn ON docker - docker must be running
30 | #docker-compose -f docker/docker-compose-standalone.yml up -d --scale chrome=3
31 | #mvn test -Dplatform=remote
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/testng_dockerC_parallel.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/java/base/ExtentManager.java:
--------------------------------------------------------------------------------
1 | package base;
2 |
3 | import com.aventstack.extentreports.ExtentReports;
4 | import com.aventstack.extentreports.reporter.ExtentSparkReporter;
5 | import com.aventstack.extentreports.reporter.configuration.Theme;
6 |
7 | public class ExtentManager {
8 | private static ExtentReports report;
9 |
10 | public static ExtentReports getInstance(){
11 | if(report == null){
12 | ExtentSparkReporter spark = new ExtentSparkReporter("./reports/spark.html");
13 | report = new ExtentReports();
14 |
15 | spark.config().setTheme(Theme.DARK);
16 | spark.config().setDocumentTitle("My own report");
17 | spark.config().setEncoding("utf-8");
18 | spark.config().setReportName("My report");
19 |
20 | report.attachReporter(spark);
21 | }
22 |
23 |
24 | return report;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/test/java/testCases/TestLogin_invalid.java:
--------------------------------------------------------------------------------
1 | package testCases;
2 |
3 | import base.App;
4 | import base.driver.BaseTest;
5 | import base.ExtentReport;
6 | import com.aventstack.extentreports.Status;
7 | import org.openqa.selenium.support.ui.WebDriverWait;
8 | import org.testng.Assert;
9 | import org.testng.annotations.Test;
10 | import pages.LoginPage;
11 |
12 | public class TestLogin_invalid extends BaseTest {
13 | WebDriverWait wait;
14 |
15 | @Test
16 | public void verifyInvalidLogin() throws InterruptedException {
17 |
18 | LoginPage loginPage = new LoginPage();
19 | loginPage.login(App.validUserName,App.inValidpassword);
20 | Thread.sleep(2000);
21 | Assert.assertEquals(loginPage.getInvalidPasswordErrorText(), "Epic sadface: Username and password do not match any user in this serv");
22 | ExtentReport.getTest().log(Status.INFO, "login error");
23 |
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/java/testCases/TestLogin.java:
--------------------------------------------------------------------------------
1 | package testCases;
2 |
3 | import base.App;
4 | import base.driver.BaseTest;
5 | import base.ExtentReport;
6 | import com.aventstack.extentreports.Status;
7 |
8 | import org.openqa.selenium.support.ui.WebDriverWait;
9 | import org.testng.annotations.Test;
10 | import pages.LoginPage;
11 | import pages.ProductsPage;
12 |
13 | public class TestLogin extends BaseTest {
14 | WebDriverWait wait;
15 |
16 | @Test
17 | public void VeirfyValidLogin() throws InterruptedException {
18 | ProductsPage productPage = new ProductsPage();
19 |
20 | LoginPage loginPage = new LoginPage();
21 | loginPage.login(App.validUserName,App.validPassword);
22 | Thread.sleep(2000);
23 | productPage.waitForProduct();
24 | ExtentReport.getTest().log(Status.INFO, "login Successful");
25 | Thread.sleep(2000);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/base/extentPkg/ExtentTestSample.java:
--------------------------------------------------------------------------------
1 | package base.extentPkg;
2 |
3 | import com.aventstack.extentreports.MediaEntityBuilder;
4 | import com.aventstack.extentreports.Status;
5 | import org.apache.commons.codec.binary.Base64;
6 | import org.apache.commons.io.FileUtils;
7 | import org.testng.annotations.Test;
8 |
9 | import java.io.*;
10 | import java.nio.charset.StandardCharsets;
11 |
12 | public class ExtentTestSample extends BTest{
13 |
14 | @Test
15 | public void MainTest() throws IOException {
16 |
17 |
18 | //ExtentTest test = ExtentManager.getInstance().createTest("MyTest");
19 | Extent.getTest().log(Status.INFO, "launching browser");
20 |
21 | //verify
22 | Extent.getTest().log(Status.FAIL, "Test spelling not correct");
23 |
24 | //verify
25 | Extent.getTest().log(Status.WARNING, "alert test not correct");
26 |
27 | //Extent.getTest().addScreenCaptureFromPath("filepath.jpg");
28 |
29 |
30 | //to-dox`
31 | //verify
32 | //test.pass("Test case passed");
33 | Extent.getTest().pass("");
34 |
35 |
36 |
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/base/driver/PageDriver.java:
--------------------------------------------------------------------------------
1 | package base.driver;
2 |
3 | import org.openqa.selenium.WebDriver;
4 |
5 | public class PageDriver {
6 |
7 | private static final ThreadLocal webDriver = new ThreadLocal<>();
8 | private static PageDriver instance = null;
9 |
10 | private PageDriver(){
11 |
12 | }
13 |
14 | public static PageDriver getInstance(){
15 | if(instance == null){
16 | instance = new PageDriver();
17 | }
18 | return instance;
19 | }
20 |
21 | public WebDriver getDriver(){
22 | return webDriver.get();
23 | }
24 |
25 | public void setDriver(WebDriver driver){
26 | webDriver.set(driver);
27 | }
28 |
29 | public static WebDriver getCurrentDriver(){
30 | return getInstance().getDriver();
31 | }
32 |
33 |
34 | /*private static final ThreadLocal str = new ThreadLocal<>();
35 | public static String getStr(){
36 | return str.get();
37 | }
38 |
39 | public static void setStr(String string){
40 | str.set(string);
41 | }
42 |
43 | public static void main(String []args){
44 | PageDriver.setStr("qavbox");
45 | System.out.println(PageDriver.getStr());
46 |
47 | PageDriver.setStr("qavalidation");
48 | System.out.println(PageDriver.getStr());
49 | }*/
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/docker/docker-compose-hubnode.yml:
--------------------------------------------------------------------------------
1 | version: "3"
2 | services:
3 | chrome:
4 | image: selenium/node-chrome:4.7.1-20221208
5 | shm_size: 2gb
6 | depends_on:
7 | - selenium-hub
8 | environment:
9 | - SE_EVENT_BUS_HOST=selenium-hub
10 | - SE_EVENT_BUS_PUBLISH_PORT=4442
11 | - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
12 | - SE_VNC_NO_PASSWORD=1
13 | - SE_NODE_MAX_SESSIONS=3
14 |
15 | edge:
16 | image: selenium/node-edge:4.7.1-20221208
17 | shm_size: 2gb
18 | depends_on:
19 | - selenium-hub
20 | environment:
21 | - SE_EVENT_BUS_HOST=selenium-hub
22 | - SE_EVENT_BUS_PUBLISH_PORT=4442
23 | - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
24 | - SE_VNC_NO_PASSWORD=1
25 |
26 | firefox:
27 | image: selenium/node-firefox:4.7.1-20221208
28 | shm_size: 2gb
29 | depends_on:
30 | - selenium-hub
31 | environment:
32 | - SE_EVENT_BUS_HOST=selenium-hub
33 | - SE_EVENT_BUS_PUBLISH_PORT=4442
34 | - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
35 | - SE_VNC_NO_PASSWORD=1
36 | - SE_NODE_MAX_SESSIONS=3
37 |
38 | selenium-hub:
39 | image: selenium/hub:4.7.1-20221208
40 | container_name: selenium-hub
41 | ports:
42 | - "4442:4442"
43 | - "4443:4443"
44 | - "4444:4444"
45 |
46 |
47 | #cd docker
48 | #docker-compose -f docker-compose-hubNode.yml up -d
49 | # To stop the execution, hit Ctrl+C, and then `docker-compose -f docker-compose-v3.yml down`
50 |
--------------------------------------------------------------------------------
/src/main/java/base/Util.java:
--------------------------------------------------------------------------------
1 | package base;
2 |
3 | import base.driver.PageDriver;
4 | import org.apache.commons.codec.binary.Base64;
5 | import org.apache.commons.io.FileUtils;
6 | import org.openqa.selenium.OutputType;
7 | import org.openqa.selenium.TakesScreenshot;
8 |
9 | import java.io.File;
10 | import java.io.IOException;
11 |
12 | public class Util {
13 |
14 | //applicable for all browser, but takes screnshot only the visible portion of the browser
15 | public static String getScreenshot(String imagename) throws IOException, IOException {
16 | TakesScreenshot ts = (TakesScreenshot) PageDriver.getCurrentDriver();
17 | File f = ts.getScreenshotAs(OutputType.FILE);
18 | String filePath = "./screenshot/"+imagename;
19 | FileUtils.copyFile(f, new File(filePath));
20 | return filePath;
21 | }
22 |
23 | public static String convertImg_Base64(String screenshotPath) throws IOException {
24 | /*File f = new File(screenshotPath);
25 | FileInputStream fis = new FileInputStream(f);
26 | byte[] bytes = new byte[(int)f.length()];
27 | fis.read(bytes);
28 | String base64Img =
29 | new String(Base64.encodeBase64(bytes), StandardCharsets.UTF_8);
30 | */
31 |
32 | byte[] file = FileUtils.readFileToByteArray(new File(screenshotPath));
33 | String base64Img = Base64.encodeBase64String(file);
34 | return base64Img;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/jenkins/jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline {
2 | agent any
3 | parameters {
4 | string defaultValue: 'chrome', description: 'select a browser', name: 'browser', trim: false
5 | string defaultValue: 'local', description: 'select a platform', name: 'platform', trim: false
6 | }
7 |
8 | tools
9 | {
10 | maven 'maven_home'
11 | }
12 | stages
13 | {
14 | stage('checkout stage')
15 | {
16 | steps{
17 | echo "checkingout stage"
18 | echo "${params.browser}"
19 | deleteDir()
20 | git branch: 'main', credentialsId: 'c5aef89d-c4bf-4c43-8aa6-7def9b90e32c', url: 'https://github.com/sunilpatro1985/SeleniumJavaFramework.git'
21 | }
22 | }
23 | stage('Test'){
24 | steps{
25 | catchError{
26 | echo "Test stage"
27 | sh "mvn test -Dbrowser=${params.browser} -Dplatform=${params.platform} -Dmaven.test.failure.ignore=true"
28 | }
29 | echo currentBuild.result
30 | }
31 |
32 | }
33 | stage('deploy'){
34 | steps{
35 | echo "deploy stage"
36 | }
37 | }
38 | }
39 | post{
40 | always{
41 | echo "artifact"
42 | archiveArtifacts artifacts: 'reports/spark.html', followSymlinks: false
43 | archiveArtifacts artifacts: 'target/surefire-reports/emailable-report.html'
44 | junit allowEmptyResults: true, skipMarkingBuildUnstable: true, skipPublishingChecks: true, testResults: 'target/surefire-reports/*.xml'
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/src/test/java/old/SampleSelenium.java:
--------------------------------------------------------------------------------
1 | package old;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.chrome.ChromeDriver;
6 | import org.openqa.selenium.firefox.FirefoxDriver;
7 | import org.openqa.selenium.support.ui.WebDriverWait;
8 | import org.testng.annotations.Test;
9 |
10 | import java.time.Duration;
11 |
12 | public class SampleSelenium {
13 | WebDriver driver = null;
14 | WebDriverWait wait;
15 |
16 | //@Test
17 | public void MavenParamTest() throws InterruptedException {
18 |
19 | String browser = System.getProperty("browser", "chrome");
20 |
21 | if(browser.contains("chrome")){
22 | System.setProperty("webdriver.chrome.driver","/Users/skpatro/sel/chromedriver");
23 | driver = new ChromeDriver();
24 | }else
25 | if(browser.contains("firefox")){
26 | System.setProperty("webdriver.gecko.driver","/Users/skpatro/sel/geckodriver");
27 | driver = new FirefoxDriver();
28 | }
29 |
30 | if(driver != null){
31 | wait = new WebDriverWait(driver, Duration.ofSeconds(15));
32 | driver.get("https://www.saucedemo.com/");
33 |
34 | driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(20));
35 |
36 | driver.findElement(By.id("user-name")).sendKeys("standard_user");
37 |
38 | driver.findElement(By.id("password")).sendKeys("secret_sauce");
39 |
40 | driver.findElement(By.id("login-button")).click();
41 | Thread.sleep(2000);
42 | driver.quit();
43 | }
44 | }
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Selenium Java framework with maven testNG
2 |
3 |
4 | Refer [step by step tutorial](https://www.youtube.com/playlist?list=PLPO0LFyCaSo1lEiEFxT97x-CSn-J1omzZ )
5 | for detailed explanation.
6 |
7 |
8 | ### Highlights on this framework
9 | * How to create maven build project
10 | * Write tests using testNG
11 | * Implement page object model
12 | * Singleton pattern for driver instantiation and getter / setter
13 | * Running the tests using maven surefire plugin
14 | * Run tests in command prompt
15 | * Run tests in Docker containers
16 |
17 |
18 | Refer below links for basic understanding of selenium, Maven & testNG
19 | * [Selenium java topics](https://youtube.com/playlist?list=PLPO0LFyCaSo22dffCqWdwyxOxdA1KgtJ7)
20 | * [TestNG features](https://youtube.com/playlist?list=PLPO0LFyCaSo3gshbTOWezIzAqiJSHc2H-)
21 |
22 | -----------------
23 | Open command prompt, navigate to project directory & run below command
24 |
25 | ### Run tests in local
26 | `mvn test` //default runs in chrome browser
27 | `mvn test -Dbrowser=firefox`
28 |
29 | ### Run tests in remote / docker
30 |
31 | **Note -**
32 | Make sure you have docker desktop installed
33 | Docker is currently running
34 | Navigate to docker directory `cd docker`
35 | Run below command to run the docker conntainers
36 | `docker-compose -f docker-compose-hubNode.yml up -d`
37 |
38 | Now in another terminal, run any of below command to run the tests inside the container
39 | `mvn test -Dplatform=remote` //default runs in chrome browser
40 | `mvn test -Dbrowser=firefox -Dplatform=remote`
41 |
42 | See the tests running insider container
43 | Navigate to browser and load this url `localhost:4444`
44 |
45 | After running the tests, stop the containers
46 | `docker-compose -f docker-compose-hubNode.yml down`
--------------------------------------------------------------------------------
/src/test/java/testCases/TestProductItems.java:
--------------------------------------------------------------------------------
1 | package testCases;
2 |
3 | import base.driver.BaseTest;
4 | import base.ExcelReader;
5 | import org.openqa.selenium.support.ui.WebDriverWait;
6 | import org.testng.Assert;
7 | import org.testng.annotations.Test;
8 | import pages.LoginPage;
9 | import pages.ProductsPage;
10 |
11 | public class TestProductItems extends BaseTest {
12 | WebDriverWait wait;
13 |
14 | @Test
15 | public void Test_TestProductItems() throws Exception {
16 | ProductsPage productPage = new ProductsPage();
17 | LoginPage loginPage = new LoginPage();
18 |
19 | loginPage.login(); //valid login
20 | Thread.sleep(2000);
21 |
22 | productPage.waitForProduct();
23 | Thread.sleep(2000);
24 | Assert.assertEquals(productPage.getItemsSize(), 6);
25 |
26 | productPage.add_All_items_ToCart();
27 | Assert.assertEquals(productPage.getCartCount(), "6");
28 | Thread.sleep(2000);
29 |
30 | ExcelReader excelreader = new ExcelReader();
31 | excelreader.setExcelFile("./test_data.xlsx", "prodsort");
32 |
33 | Object obj[][] = excelreader.to2DArray();
34 |
35 | Thread.sleep(30);
36 |
37 | //productPage.select_sortOption("name (Z to A)");
38 | Assert.assertEquals(
39 | productPage.select_sortOption("Name (Z to A)").getFirstItemName()
40 | ,"Test.allTheThings() T-Shirt (Red)"
41 | );
42 | Thread.sleep(3000);
43 | Assert.assertEquals(
44 | productPage.select_sortOption("Price (low to high)").getFirstItemName()
45 | ,"Sauce Labs Onesie"
46 | );
47 | Thread.sleep(3000);
48 | }
49 |
50 |
51 | }
52 |
53 |
54 | //mvn test -Dtest=testCases.TestProductItems
--------------------------------------------------------------------------------
/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
10 | UTF-8
11 | %d %-5level %logger{45} - %msg%n
12 |
13 |
14 |
15 |
16 |
17 | /Users/skpatro/MyProjects/SelFramework_Sept21/app.log
18 |
19 | logs/employee-%i.log.gz
20 | 1
21 | 2
22 |
23 |
24 | 2MB
25 |
26 |
27 | UTF-8
28 |
29 | %d %-5level %logger{45} - %msg%n
30 |
31 |
32 |
33 |
34 |
35 |
36 |
40 |
41 |
--------------------------------------------------------------------------------
/.github/workflows/maven.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3 |
4 | # This workflow uses actions that are not certified by GitHub.
5 | # They are provided by a third-party and are governed by
6 | # separate terms of service, privacy policy, and support
7 | # documentation.
8 |
9 | name: Java CI with Maven
10 |
11 | on:
12 | workflow_dispatch:
13 | inputs:
14 | browsername:
15 | type: string
16 | description: 'browser name'
17 | default: 'chrome'
18 | testname:
19 | description: 'enter the regex to run the tests'
20 | type: string
21 | xmlsname:
22 | type: string
23 | description: 'enter on or multiple xmls to run'
24 | push:
25 | branches: [ "main" ]
26 | pull_request:
27 | branches: [ "main" ]
28 |
29 | jobs:
30 | build:
31 |
32 | runs-on: ubuntu-latest
33 |
34 | steps:
35 | - uses: actions/checkout@v3
36 | - name: Set up JDK 11
37 | uses: actions/setup-java@v3
38 | with:
39 | java-version: '11'
40 | distribution: 'temurin'
41 | cache: maven
42 | - name: run test with xml files
43 | if: ${{inputs.xmlsname}}
44 | run: >
45 | mvn clean test
46 | -Dsurefire.suiteXmlFile=${{inputs.xmlsname}}
47 | -DenableBrowserOptions=true -Dmaven.test.failure.ignore=true
48 | - name: run specific tests with regex
49 | if: ${{inputs.testname}}
50 | run: >
51 | mvn clean test
52 | -Dtest=${{inputs.testname}}
53 | -Dbrowser=${{inputs.browsername}}
54 | -DenableBrowserOptions=true -Dmaven.test.failure.ignore=true
55 | - name: archive artifact
56 | uses: actions/upload-artifact@v3
57 | with:
58 | name: sparkHtml
59 | path: ./reports/*.html
--------------------------------------------------------------------------------
/src/test/java/old/SamplePF.java:
--------------------------------------------------------------------------------
1 | package old;
2 |
3 | import io.github.bonigarcia.wdm.WebDriverManager;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.support.FindBy;
8 | import org.openqa.selenium.support.PageFactory;
9 | import org.openqa.selenium.support.ui.ExpectedCondition;
10 | import org.openqa.selenium.support.ui.ExpectedConditions;
11 | import org.openqa.selenium.support.ui.WebDriverWait;
12 | import org.testng.annotations.Test;
13 |
14 | import java.time.Duration;
15 |
16 | public class SamplePF {
17 | WebDriver driver;
18 | WebDriverWait wait;
19 |
20 | @FindBy(name = "commit1")
21 | public WebElement TryMe;
22 |
23 | @FindBy(id = "delay")
24 | public WebElement delayText;
25 |
26 | //@Test
27 | public void setUp() throws InterruptedException {
28 | WebDriverManager.chromedriver().setup();
29 | driver = new ChromeDriver();
30 |
31 | driver.get("https://qavbox.github.io/demo/delay/");
32 |
33 | PageFactory.initElements(driver, this);
34 |
35 | this.TryMe.click();
36 |
37 |
38 | wait = new WebDriverWait(driver, Duration.ofSeconds(6));
39 | wait.until(waitForElement(delayText));
40 |
41 | System.out.println(delayText.getText());
42 |
43 | Thread.sleep(5000);
44 |
45 | driver.quit();
46 |
47 | }
48 |
49 | public static ExpectedCondition waitForElement(WebElement el) {
50 | return new ExpectedCondition() {
51 | public Boolean apply(WebDriver driver) {
52 | boolean flag = false;
53 | try {
54 | if (el.isDisplayed()) {
55 | flag = true;
56 | }
57 | } catch (Exception e) {
58 | System.out.println("inside catch block " + e.getMessage());
59 | }
60 | return flag;
61 | }
62 | };
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/pages/BasePage.java:
--------------------------------------------------------------------------------
1 | package pages;
2 |
3 | import base.driver.PageDriver;
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.support.ui.ExpectedConditions;
7 | import org.openqa.selenium.support.ui.Select;
8 | import org.openqa.selenium.support.ui.WebDriverWait;
9 |
10 | import java.time.Duration;
11 | import java.util.List;
12 |
13 | public class BasePage {
14 |
15 | WebDriverWait wait;
16 |
17 | public void type(By byLocator, String text){
18 | PageDriver.getCurrentDriver()
19 | .findElement(byLocator)
20 | .sendKeys(text);
21 |
22 | //wait = new WebDriverWait(PageDriver.getCurrentDriver(), Duration.ofSeconds(15));
23 | //wait.until(ExpectedConditions.presenceOfElementLocated(byLocator)).sendKeys();
24 | }
25 |
26 | public void click(By byLocator){
27 | //waitForEl(byLocator);
28 | PageDriver.getCurrentDriver()
29 | .findElement(byLocator)
30 | .click();
31 |
32 | //wait = new WebDriverWait(PageDriver.getCurrentDriver(), Duration.ofSeconds(15));
33 | //wait.until(ExpectedConditions.presenceOfElementLocated(byLocator)).click();
34 | }
35 |
36 | public int size(By byLocator){
37 | return PageDriver.getCurrentDriver()
38 | .findElements(byLocator)
39 | .size();
40 | }
41 |
42 | public String getText(By byLocator){
43 | return PageDriver.getCurrentDriver()
44 | .findElement(byLocator)
45 | .getText();
46 | }
47 |
48 | public List getEls(By byLocator){
49 | return PageDriver.getCurrentDriver()
50 | .findElements(byLocator);
51 | }
52 |
53 | public void selectByOption(By byLocator, String option){
54 | Select select = new Select(PageDriver.getCurrentDriver().findElement(byLocator));
55 | select.selectByVisibleText(option);
56 | }
57 |
58 | public void waitForEl(By byLocator){
59 | wait = new WebDriverWait(PageDriver.getCurrentDriver(), Duration.ofSeconds(10));
60 | wait.until(ExpectedConditions.presenceOfElementLocated(byLocator));
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/pages/LoginPage.java:
--------------------------------------------------------------------------------
1 | package pages;
2 |
3 | import base.App;
4 | import base.ExtentReport;
5 | import com.aventstack.extentreports.Status;
6 | import org.openqa.selenium.By;
7 | import org.openqa.selenium.WebDriver;
8 | import org.openqa.selenium.WebElement;
9 |
10 | public class LoginPage extends BasePage{
11 | WebDriver driver;
12 |
13 | /*public LoginPage(){
14 | //driver = PageDriver.getDriver();
15 | driver = PageDriver.getCurrentDriver();
16 |
17 | PageFactory.initElements(driver, this);
18 | }
19 |
20 | @FindBy(how = How.ID, using = "user-name")
21 | public WebElement userName;
22 |
23 | @FindBy(id = "password")
24 | @CacheLookup
25 | public WebElement password;
26 |
27 | @FindBy(how = How.ID, using = "login-button")
28 | public WebElement signIn;*/
29 |
30 | /*@FindBy(how = How.ID, using = "name")
31 | public List items_name;
32 |
33 | @FindBys( //and operator
34 | {
35 | @FindBy(id="x"),
36 | @FindBy(css="y")
37 | }
38 | )
39 | public List items;
40 |
41 | @FindAll( //or operator
42 | {
43 | @FindBy(id="x"),
44 | @FindBy(css="y")
45 | }
46 | )
47 | public List itemsList;*/
48 |
49 |
50 | By userName = By.id("user-name");
51 | By password = By.id("password");
52 | By signIn = By.id("login-button");
53 | By invalidPasswordError = By.cssSelector("[data-test='error']");
54 |
55 | public void login(String username, String Password){
56 | /*userName = driver.findElement(By.id("user-name"));
57 | password = driver.findElement(By.id("password"));
58 | signIn = driver.findElement(By.id("login-button"));*/
59 | //driver.findElement(userName).sendKeys(username);
60 | //driver.findElement(password).sendKeys(Password);
61 | //userName.sendKeys(username);
62 | //password.sendKeys(Password);
63 | //signIn.click();
64 |
65 | type(userName, username);
66 | ExtentReport.getTest().log(Status.INFO, "entered username");
67 | type(password, Password);
68 | click(signIn);
69 | }
70 |
71 | public void login(){
72 | type(userName, App.validUserName);
73 | type(password, App.validPassword);
74 | click(signIn);
75 | }
76 |
77 | public WebElement getElementBasedOntext(String text){
78 | return driver.findElement(By.xpath("//[contains(text(), '"+text+"']"));
79 | }
80 |
81 | public String getInvalidPasswordErrorText(){
82 | return getText(invalidPasswordError);
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/test/java/pages/ProductsPage.java:
--------------------------------------------------------------------------------
1 | package pages;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.support.ui.WebDriverWait;
7 |
8 | public class ProductsPage extends BasePage{
9 | WebDriver driver;
10 | WebDriverWait wait;
11 |
12 | /*public ProductsPage() {
13 | driver = PageDriver.getCurrentDriver();
14 | PageFactory.initElements(driver, this);
15 | }
16 |
17 | @FindBy(css = ".title")
18 | public WebElement productsTest;*/
19 |
20 | By productsText = By.cssSelector(".title");
21 | By inventoryItems = By.cssSelector(".inventory_item");
22 | By addToCartButtons = By.cssSelector(".inventory_item button");
23 | By cartCount = By.cssSelector(".shopping_cart_badge");
24 | By sort_selector = By.cssSelector(".product_sort_container");
25 | By first_item_name = By.cssSelector(".inventory_item:nth-child(1) .inventory_item_name");
26 | By first_item_price = By.cssSelector(".inventory_item:nth-child(1) .inventory_item_price");
27 | //public WebElement productsText = driver.findElement(By.cssSelector(".title"));
28 |
29 |
30 | public void waitForProduct(){
31 | waitForEl(productsText);
32 | }
33 |
34 | public int getItemsSize(){
35 | return size(inventoryItems);
36 | }
37 |
38 | public String getCartCount(){
39 | return getText(cartCount);
40 | }
41 |
42 | public ProductsPage select_sortOption(String option){
43 | selectByOption(sort_selector, option);
44 | return this;
45 | }
46 |
47 | public String getFirstItemName(){
48 | return getText(first_item_name);
49 | }
50 |
51 | public String getFirstItemPrice(){
52 | return getText(first_item_price);
53 | }
54 |
55 | public void add_All_items_ToCart(){
56 | for(WebElement el : getEls(addToCartButtons)){
57 | el.click();
58 | }
59 | }
60 |
61 |
62 |
63 | /*public void waitForProduct() {
64 | wait = new WebDriverWait(driver, Duration.ofSeconds(15));
65 | wait.until(ExpectedConditions.visibilityOf(productsTest));
66 | }
67 |
68 | public void waitForEl() {
69 | wait = new WebDriverWait(driver, Duration.ofSeconds(15));
70 | //wait.until(ExpectedConditions.visibilityOfElementLocated(productsTest))
71 | wait.until(waitForElement(productsTest));
72 | }*/
73 |
74 | /*public static ExpectedCondition waitForElement(WebElement el) {
75 | return new ExpectedCondition() {
76 | public Boolean apply(WebDriver driver) {
77 | boolean flag = false;
78 | try {
79 | if (el.isDisplayed()) {
80 | flag = true;
81 | }
82 | } catch (Exception e) {
83 | System.out.println("inside catch block " + e.getMessage());
84 | }
85 | return flag;
86 | }
87 | };
88 | }*/
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/base/driver/BaseTest.java:
--------------------------------------------------------------------------------
1 | package base.driver;
2 |
3 | import base.*;
4 | import com.aventstack.extentreports.ExtentTest;
5 | import com.aventstack.extentreports.MediaEntityBuilder;
6 | import com.aventstack.extentreports.Status;
7 | import org.openqa.selenium.remote.RemoteWebDriver;
8 | import org.openqa.selenium.support.ui.WebDriverWait;
9 | import org.testng.ITestResult;
10 | import org.testng.annotations.*;
11 |
12 | import java.io.IOException;
13 | import java.net.MalformedURLException;
14 |
15 | public class BaseTest {
16 | WebDriverWait wait;
17 | //WebDriver driver = null;
18 |
19 | @Parameters({"browser"})
20 | @BeforeClass
21 | public void setUp(@Optional String browser) throws MalformedURLException {
22 | //public void setUp() throws MalformedURLException {
23 |
24 | /*browser will be null if we don't run the test from testNG.xml file
25 | *so if the browser is null, then get the browser value from App.java file
26 | *You can change the default value of browser=chrome by passing the browser
27 | * from maven command line as mvn test -Dbrowser=firefox
28 | */
29 | if(browser == null){
30 | browser = App.browser;
31 | }
32 |
33 | DriverFactory.openBrowser(browser);
34 |
35 |
36 | System.out.println("");
37 | System.out.println("------driver initiated------");
38 | System.out.println("Running on thread - " + Thread.currentThread().getId());
39 | System.out.println("Tests running on " +
40 | ((RemoteWebDriver) PageDriver.getCurrentDriver()).getCapabilities().getBrowserName());
41 |
42 | //cap.getBrowserName());
43 | }
44 |
45 | @BeforeMethod
46 | public void setUpSparktest(ITestResult result){
47 | ExtentTest test = ExtentManager.getInstance().createTest(result.getMethod().getMethodName());
48 | ExtentReport.setTest(test);
49 | }
50 |
51 | @AfterMethod
52 | public void SparktestResult(ITestResult result) throws IOException {
53 | if(!result.isSuccess()){
54 | ExtentReport.getTest().log(Status.FAIL, "test case failed as - " +
55 | result.getThrowable());
56 | String screenshotPath = Util.getScreenshot(result.getMethod().getMethodName()+".jpg");
57 |
58 | /*ExtentReport.getTest()
59 | .addScreenCaptureFromPath(screenshotPath)
60 | .fail(MediaEntityBuilder.createScreenCaptureFromPath(screenshotPath).build());
61 | */
62 | ExtentReport.getTest().fail(MediaEntityBuilder
63 | .createScreenCaptureFromBase64String(Util.convertImg_Base64(screenshotPath)).build());
64 | }
65 | }
66 |
67 | @AfterClass
68 | public void tearDown(){
69 | //PageDriver.getInstance().getDriver().quit();
70 | //PageDriver.getDriver().quit();
71 | if(PageDriver.getInstance() != null) {
72 | PageDriver.getCurrentDriver().quit();
73 | }
74 | }
75 |
76 | @AfterSuite
77 | public void sparkFlush(){
78 | ExtentManager.getInstance().flush();
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/base/ExcelReader.java:
--------------------------------------------------------------------------------
1 | package base;
2 |
3 | import org.apache.poi.ss.usermodel.*;
4 |
5 | import java.awt.Color;
6 | import java.io.File;
7 | import java.io.FileInputStream;
8 | import java.io.FileOutputStream;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | public class ExcelReader {
13 |
14 | private FileInputStream fis;
15 | private FileOutputStream fileOut;
16 | private Workbook wb;
17 | private Sheet sh;
18 | private Cell cell;
19 | private Row row;
20 | private CellStyle cellstyle;
21 | private Color mycolor;
22 | private String excelFilePath;
23 | private Map columns = new HashMap<>();
24 |
25 | public void setExcelFile(String ExcelPath, String SheetName) throws Exception {
26 | try {
27 | File fis = new File(ExcelPath);
28 | wb = WorkbookFactory.create(fis);
29 | sh = wb.getSheet(SheetName);
30 | //sh = wb.getSheetAt(0); //0 - index of 1st sheet
31 | /*if (sh == null) {
32 | sh = wb.createSheet(SheetName);
33 | }*/
34 |
35 | this.excelFilePath = ExcelPath;
36 | //adding all the column header names to the map 'columns'
37 | sh.getRow(0).forEach(cell -> {
38 | columns.put(cell.getStringCellValue(), cell.getColumnIndex());
39 | });
40 |
41 | } catch (Exception e) {
42 | System.out.println(e.getMessage());
43 | }
44 | }
45 |
46 | public String getCellData(int rownum, int colnum) throws Exception {
47 | try {
48 | cell = sh.getRow(rownum).getCell(colnum);
49 | String CellData = null;
50 | switch (cell.getCellType()) {
51 | case STRING:
52 | CellData = cell.getStringCellValue();
53 | break;
54 | case NUMERIC:
55 | if (DateUtil.isCellDateFormatted(cell)) {
56 | CellData = String.valueOf(cell.getDateCellValue());
57 | } else {
58 | CellData = String.valueOf((long) cell.getNumericCellValue());
59 | }
60 | break;
61 | case BOOLEAN:
62 | CellData = Boolean.toString(cell.getBooleanCellValue());
63 | break;
64 | case BLANK:
65 | CellData = "";
66 | break;
67 | }
68 | return CellData;
69 | } catch (Exception e) {
70 | return "";
71 | }
72 | }
73 |
74 | public String getCellData(String columnName, int rownum) throws Exception {
75 | return getCellData(rownum, columns.get(columnName));
76 | }
77 |
78 | public static void main(String[] args) throws Exception {
79 | ExcelReader excel = new ExcelReader();
80 | /*excel.setExcelFile("./testData.xlsx", "Sheet1");
81 | System.out.println(excel.getCellData("fullname", 1));
82 | System.out.println(excel.getCellData("email", 1));
83 | System.out.println(excel.getCellData("telephone", 1));*/
84 | //excel.getCellData(1,1);
85 | excel.setExcelFile("./test_data.xlsx", "prodsort");
86 | Object obj[][] = excel.to2DArray();
87 |
88 | //excel.setExcelFile("./testData.xlsx", "Sheet1");
89 | for(int i=0; i< obj.length;i++){
90 | for(int j=0;j
2 |
5 | 4.0.0
6 |
7 | org.qavbox
8 | SelFramework_Sept21
9 | 1.0-SNAPSHOT
10 |
11 |
12 | UTF-8
13 | 11
14 | 11
15 |
16 |
17 |
18 |
19 | 1.7.30
20 | false
21 |
22 |
23 |
24 |
25 |
26 | org.seleniumhq.selenium
27 | selenium-java
28 | 4.11.0
29 |
30 |
31 |
32 |
33 | org.testng
34 | testng
35 | 7.3.0
36 | compile
37 |
38 |
39 |
40 |
41 | org.apache.poi
42 | poi
43 | 5.0.0
44 |
45 |
46 |
47 |
48 | org.apache.poi
49 | poi-ooxml
50 | 5.1.0
51 |
52 |
53 |
54 |
55 |
56 |
57 | org.freemarker
58 | freemarker
59 | 2.3.30
60 |
61 |
62 |
63 |
64 |
65 | ch.qos.logback
66 | logback-classic
67 | 1.3.0-alpha10
68 |
69 |
70 |
71 |
72 | org.slf4j
73 | slf4j-api
74 | 1.7.32
75 |
76 |
77 |
78 |
79 | org.slf4j
80 | slf4j-jdk14
81 | 1.7.32
82 |
83 |
84 |
85 | io.github.bonigarcia
86 | webdrivermanager
87 | 5.1.0
88 |
89 |
90 |
91 |
92 | io.rest-assured
93 | rest-assured
94 | 4.4.0
95 | test
96 |
97 |
98 |
99 |
100 | com.aventstack
101 | extentreports
102 | 5.0.9
103 |
104 |
105 |
106 | commons-io
107 | commons-io
108 | 2.11.0
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 | org.apache.maven.plugins
118 | maven-compiler-plugin
119 | 3.8.1
120 |
124 |
125 |
126 | org.apache.maven.plugins
127 | maven-surefire-plugin
128 | 3.0.0-M5
129 |
132 |
133 |
136 |
138 |
139 |
140 |
141 |
142 |
143 |
--------------------------------------------------------------------------------
/src/main/java/base/driver/DriverFactory.java:
--------------------------------------------------------------------------------
1 | package base.driver;
2 |
3 | import base.App;
4 | import io.github.bonigarcia.wdm.WebDriverManager;
5 | import org.openqa.selenium.Platform;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.chrome.ChromeDriver;
8 | import org.openqa.selenium.chrome.ChromeOptions;
9 | import org.openqa.selenium.firefox.FirefoxDriver;
10 | import org.openqa.selenium.firefox.FirefoxOptions;
11 | import org.openqa.selenium.remote.DesiredCapabilities;
12 | import org.openqa.selenium.remote.RemoteWebDriver;
13 |
14 | import java.net.MalformedURLException;
15 | import java.net.URL;
16 |
17 | public class DriverFactory {
18 | //static
19 |
20 | public static void openBrowser(String browser) throws MalformedURLException {
21 | WebDriver driver = null;
22 | //DesiredCapabilities cap = new DesiredCapabilities();
23 |
24 |
25 | if(browser.contains("chrome")){
26 | ChromeOptions coptions = new ChromeOptions();
27 |
28 | //System.setProperty("webdriver.chrome.driver","/Users/skpatro/sel/chromedriver");
29 | //WebDriverManager.chromedriver().browserVersion("92");
30 | //WebDriverManager.chromedriver().driverVersion("93.0.4577.63");
31 |
32 | if(App.enableBrowserOptions.equalsIgnoreCase("true")){
33 | coptions = getChromeOptions();
34 | }
35 |
36 | if(App.platform.equalsIgnoreCase("local")){
37 | //WebDriverManager.chromedriver().setup();
38 | //System.setProperty("webdriver.chrome.driver", "path of chrome driver")
39 | driver = new ChromeDriver(coptions);
40 | }
41 | else if(App.platform.equalsIgnoreCase("remote")){
42 | //If you run on docker
43 | //cap.setBrowserName("chrome");
44 | //cap.setPlatform(Platform.LINUX);
45 | coptions.setPlatformName("linux");
46 | driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), coptions);
47 | }
48 | }else
49 | if(browser.contains("firefox")){
50 | FirefoxOptions foptions = new FirefoxOptions();
51 | if(App.enableBrowserOptions.equalsIgnoreCase("true")){
52 | foptions = getFFOptions();
53 | }
54 | //System.setProperty("webdriver.gecko.driver","/Users/skpatro/sel/geckodriver");
55 | if(App.platform.equalsIgnoreCase("local")){
56 | //WebDriverManager.firefoxdriver().setup();
57 | driver = new FirefoxDriver(foptions);
58 | }
59 |
60 | else if(App.platform.equalsIgnoreCase("remote")){
61 | //If you run on docker
62 | //cap.setBrowserName("firefox");
63 | // cap.setPlatform(Platform.LINUX);
64 | foptions.setPlatformName("linux");
65 | driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), foptions);
66 | //System.out.println("Tests running on " + cap.getBrowserName());
67 | }
68 | }
69 |
70 | driver.get("https://www.saucedemo.com/"); //prod
71 | /*if(App.stage.equals("qa")){
72 | driver.get("https://www.qa.saucedemo.com/");
73 | }*/
74 |
75 | //PageDriver.setDriver(driver);
76 | PageDriver.getInstance().setDriver(driver);
77 |
78 | }
79 |
80 | static ChromeOptions getChromeOptions(){
81 | ChromeOptions co = new ChromeOptions();
82 | co.addArguments("--headless=new"); //when on githubActions
83 | co.addArguments("--disable-gpu");
84 | co.addArguments("--no-sandbox");
85 | //co.setBinary("path of chrome app");
86 | //co.setBrowserVersion("116.0");
87 | //cap.setCapability(ChromeOptions.CAPABILITY, co);
88 | //co.merge(cap);
89 | return co;
90 | }
91 |
92 | static FirefoxOptions getFFOptions(){
93 | FirefoxOptions fo = new FirefoxOptions();
94 | fo.addArguments("--headless"); //when on githubActions
95 | fo.addArguments("--disable-gpu");
96 | fo.addArguments("--no-sandbox");
97 | //cap.setCapability(ChromeOptions.CAPABILITY, co);
98 | //co.merge(cap);
99 | return fo;
100 | }
101 |
102 | }
103 |
104 |
105 |
106 |
107 |
108 |
109 | /*
110 |
111 | selenium standalone chrome & firefox dockers
112 | docker-compose-standalone.yml
113 |
114 |
115 | if(browser.contains("chrome")){
116 | //System.setProperty("webdriver.chrome.driver","/Users/skpatro/sel/chromedriver");
117 | //WebDriverManager.chromedriver().browserVersion("92");
118 | //WebDriverManager.chromedriver().driverVersion("93.0.4577.63");
119 |
120 | if(App.platform.equalsIgnoreCase("local")){
121 | WebDriverManager.chromedriver().setup();
122 | driver = new ChromeDriver();
123 | }
124 | else if(App.platform.equalsIgnoreCase("remote")){
125 | //If you run on docker
126 | cap.setBrowserName("chrome");
127 | cap.setPlatform(Platform.LINUX);
128 | driver = new RemoteWebDriver(new URL("http://localhost:4441/wd/hub"), cap);
129 | }
130 | }else
131 | if(browser.contains("firefox")){
132 | //System.setProperty("webdriver.gecko.driver","/Users/skpatro/sel/geckodriver");
133 | if(App.platform.equalsIgnoreCase("local")){
134 | WebDriverManager.firefoxdriver().setup();
135 | driver = new FirefoxDriver();
136 | }
137 | else if(App.platform.equalsIgnoreCase("remote")){
138 | //If you run on docker
139 | cap.setBrowserName("firefox");
140 | cap.setPlatform(Platform.LINUX);
141 | driver = new RemoteWebDriver(new URL("http://localhost:4442/wd/hub"), cap);
142 | //System.out.println("Tests running on " + cap.getBrowserName());
143 | }
144 | }
145 | */
--------------------------------------------------------------------------------