Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
vinsguru committed Sep 9, 2023
2 parents 2374dee + 41655b4 commit 2e8bae7
Show file tree
Hide file tree
Showing 73 changed files with 2,598 additions and 3 deletions.
Binary file added .doc/selenium-docker-aws-jenkins.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions 03-automation-framework/dependencies.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Application URLs

- [Flight Reservation](https://d1uh9e7cu07ukd.cloudfront.net/selenium-docker/reservation-app/index.html)
- [Vendor Portal](https://d1uh9e7cu07ukd.cloudfront.net/selenium-docker/vendor-app/index.html)

# Maven Dependencies

```
Expand Down
15 changes: 13 additions & 2 deletions 04-selenium-grid/docker-images.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Docker Images

## First check your CPU architecture

- MAC/Linux users
`uname -m`
- Windows Users
`echo %PROCESSOR_ARCHITECTURE%`

If you see "arm", then use ARM images.

Use this docker images for creating selenium grid

| Image | ARM | Others |
Expand All @@ -8,7 +17,9 @@ Use this docker images for creating selenium grid
| Chrome | seleniarm/node-chromium:4.10 | selenium/node-chrome:4.10 |
| Firefox | seleniarm/node-firefox:4.10 | selenium/node-firefox:4.10 |

## Docker Hub Reference:
## References:

- [Selenium](https://hub.docker.com/u/selenium)
- [Seleniarm](https://hub.docker.com/u/seleniarm)
- [Seleniarm](https://hub.docker.com/u/seleniarm)
- [Seleniarm to Selenium Namespace](https://github.com/SeleniumHQ/docker-selenium/issues/1847)
- [Edge does not work in arm](https://techcommunity.microsoft.com/t5/discussions/edge-for-linux-arm64/m-p/1532272)
1 change: 0 additions & 1 deletion 06-jenkins-ci-cd/selenium-docker
Submodule selenium-docker deleted from d9df05
49 changes: 49 additions & 0 deletions 06-jenkins-ci-cd/selenium-docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Created by .ignore support plugin (hsz.mobi)
### Java template
# Compiled class file
**/*.class

# Log file
**/*.log

# BlueJ files
**/*.ctxt

# Mobile Tools for Java (J2ME)
**/.mtj.tmp/

# Package Files #
**/*.jar
**/*.war
**/*.nar
**/*.ear
**/*.zip
**/*.tar.gz
**/*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
**/hs_err_pid*

### Maven template
**/target/
**/pom.xml.tag
**/pom.xml.releaseBackup
**/pom.xml.versionsBackup
**/pom.xml.next
**/release.properties
**/dependency-reduced-pom.xml
**/buildNumber.properties
**/.mvn/timing.properties
**/.mvn/wrapper/maven-wrapper.jar

**/*.iml

**/.idea/


**/HELP.md
**/.mvn/
**/mvnw
**/mvnw.cmd
**/node_modules/

14 changes: 14 additions & 0 deletions 06-jenkins-ci-cd/selenium-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM java47

# Install curl jq
RUN apk add curl jq

# workspace
WORKDIR /home/selenium-docker

# Add the required files
ADD target/docker-resources ./
ADD runner.sh runner.sh

# Start the runner.sh
ENTRYPOINT sh runner.sh
39 changes: 39 additions & 0 deletions 06-jenkins-ci-cd/selenium-docker/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pipeline{

agent any

stages{

stage('Build Jar'){
steps{
sh 'mvn clean package -DskipTests'
}
}

stage('Build Image'){
steps{
sh 'docker build -t=vinsdocker/selenium:latest .'
}
}

stage('Push Image'){
environment{
DOCKER_HUB = credentials('dockerhub-creds')
}
steps{
sh 'echo ${DOCKER_HUB_PSW} | docker login -u ${DOCKER_HUB_USR} --password-stdin'
sh 'docker push vinsdocker/selenium:latest'
sh "docker tag vinsdocker/selenium:latest vinsdocker/selenium:${env.BUILD_NUMBER}"
sh "docker push vinsdocker/selenium:${env.BUILD_NUMBER}"
}
}

}

post {
always {
sh 'docker logout'
}
}

}
159 changes: 159 additions & 0 deletions 06-jenkins-ci-cd/selenium-docker/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress VulnerableLibrariesLocal -->
<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.vinsguru</groupId>
<artifactId>selenium-docker</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<selenium.java.version>4.11.0</selenium.java.version>
<logback.version>1.4.8</logback.version>
<webdriver.manager.version>5.4.0</webdriver.manager.version>
<testng.version>7.8.0</testng.version>
<jackson.version>2.12.0</jackson.version>
<!-- plugins versions -->
<maven.compiler.version>3.11.0</maven.compiler.version>
<maven.dependency.version>3.6.0</maven.dependency.version>
<maven.jar.version>3.3.0</maven.jar.version>
<maven.surefire.version>3.1.2</maven.surefire.version>
<maven.resources.plugin>3.3.1</maven.resources.plugin>
<!-- output directory -->
<package.directory>${project.build.directory}/docker-resources</package.directory>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.java.version}</version>
</dependency>
<!-- logging library -->
<!-- https://www.baeldung.com/logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- web-driver manager for local testing -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>${webdriver.manager.version}</version>
<scope>test</scope>
</dependency>
<!-- To deserialize json into Java object or vice versa -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<!-- Test framework -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>selenium-docker</finalName>
<plugins>
<!-- To compile the source code using specific java version. also to force IDE to change the settings -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<!-- To run the tests using specific parameters, change thread count, testng report output directory etc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<!-- mvn clean test -Dbrowser=chrome -Dselenium.grid.enabled=true -->
<systemPropertyVariables>
<browser>firefox</browser>
<selenium.grid.enabled>true</selenium.grid.enabled>
</systemPropertyVariables>
<suiteXmlFiles>
<file>src/test/resources/test-suites/vendor-portal.xml</file>
<file>src/test/resources/test-suites/flight-reservation.xml</file>
</suiteXmlFiles>
<threadCount>4</threadCount>
<reportsDirectory>target/test-output</reportsDirectory>
</configuration>
</plugin>
<!-- To copy all the dependencies to run our tests as part of "mvn package" -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven.dependency.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${package.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- To package our page objects, test classes into jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.version}</version>
<configuration>
<outputDirectory>${package.directory}/libs</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<includes>**/*.class</includes>
</configuration>
</execution>
</executions>
</plugin>
<!-- To copy resources into the output directory -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven.resources.plugin}</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${package.directory}</outputDirectory>
<resources>
<resource>
<directory>src/test/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
44 changes: 44 additions & 0 deletions 06-jenkins-ci-cd/selenium-docker/runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

#-------------------------------------------------------------------
# This script expects the following environment variables
# HUB_HOST
# BROWSER
# THREAD_COUNT
# TEST_SUITE
#-------------------------------------------------------------------

# Let's print what we have received
echo "-------------------------------------------"
echo "HUB_HOST : ${HUB_HOST:-hub}"
echo "BROWSER : ${BROWSER:-chrome}"
echo "THREAD_COUNT : ${THREAD_COUNT:-1}"
echo "TEST_SUITE : ${TEST_SUITE}"
echo "-------------------------------------------"

# Do not start the tests immediately. Hub has to be ready with browser nodes
echo "Checking if hub is ready..!"
count=0
while [ "$( curl -s http://${HUB_HOST:-hub}:4444/status | jq -r .value.ready )" != "true" ]
do
count=$((count+1))
echo "Attempt: ${count}"
if [ "$count" -ge 30 ]
then
echo "**** HUB IS NOT READY WITHIN 30 SECONDS ****"
exit 1
fi
sleep 1
done

# At this point, selenium grid should be up!
echo "Selenium Grid is up and running. Running the test...."

# Start the java command
java -cp 'libs/*' \
-Dselenium.grid.enabled=true \
-Dselenium.grid.hubHost="${HUB_HOST:-hub}" \
-Dbrowser="${BROWSER:-chrome}" \
org.testng.TestNG \
-threadcount "${THREAD_COUNT:-1}" \
test-suites/"${TEST_SUITE}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.vinsguru.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public abstract class AbstractPage {

protected final WebDriver driver;
protected final WebDriverWait wait;

public AbstractPage(WebDriver driver){
this.driver = driver;
this.wait = new WebDriverWait(driver, Duration.ofSeconds(30));
PageFactory.initElements(driver, this);
}

public abstract boolean isAt();

}
Loading

0 comments on commit 2e8bae7

Please sign in to comment.