Selenium TestNG CI #135
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
# | |
# | |
## * * * * * | |
## | | | | | | |
## | | | | +---- Day of the week (0 - 7) (Sunday is both 0 and 7) | |
## | | | +------ Month (1 - 12) | |
## | | +-------- Day of the month (1 - 31) | |
## | +---------- Hour (0 - 23) | |
## +------------ Minute (0 - 59) | |
# | |
# | |
# | |
# | |
#name: Selenium TestNG CI | |
# | |
#on: | |
# push: | |
# branches: | |
# - main | |
# pull_request: | |
# branches: | |
# - main | |
# schedule: | |
# - cron: '30 23 * * *' # This will run every day at 5 AM IST (11:30 PM UTC) | |
# | |
#jobs: | |
# build: | |
# runs-on: ubuntu-latest | |
# | |
# steps: | |
# # Step 1: Checkout the code | |
# - name: Checkout repository | |
# uses: actions/checkout@v2 | |
# | |
# # Step 2: Set up JDK 16 (Ensure you are using Java 16) | |
# - name: Set up JDK 16 | |
# uses: actions/setup-java@v2 | |
# with: | |
# distribution: 'adopt' | |
# java-version: '16' | |
# | |
# # Step 3: Cache Maven dependencies for faster builds | |
# - name: Cache Maven dependencies | |
# uses: actions/cache@v2 | |
# with: | |
# path: ~/.m2 | |
# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
# restore-keys: | | |
# ${{ runner.os }}-maven- | |
# | |
# # Step 4: Install Maven dependencies | |
# - name: Install dependencies | |
# run: mvn install -DskipTests | |
# | |
# # Step 5: Clean Temporary Reports Directory | |
# - name: Clean Temp Reports Directory | |
# run: | | |
# if [ -d "/tmp/reports" ]; then | |
# rm -rf /tmp/reports/* | |
# echo "Old temporary reports cleaned." | |
# else | |
# mkdir -p /tmp/reports | |
# echo "Created temporary reports directory." | |
# fi | |
# | |
# # Step 6: Run UI-Automation tests with Chrome browser | |
## - name: Run UI-Automation tests with Chrome browser | |
## run: mvn test -Dthread=3 -Dlaunch=remote # Adjust as necessary for your project | |
# | |
# | |
# # Step 5: Run multiple UI-Automation tests with Chrome browser | |
# - name: Run UI-Automation tests | |
# run: | | |
# mvn test -DsuiteXmlFile=suite1.xml | |
# mvn test -DsuiteXmlFile=suite2.xml | |
# mvn test -DsuiteXmlFile=testng.xml | |
# | |
# # Step 7: Upload Extent Report from Temporary Directory | |
# - name: Upload Extent Report as Artifact | |
# if: always() | |
# uses: actions/upload-artifact@v3 # Updated to v3 to avoid deprecation | |
# with: | |
# name: extent-report | |
# path: /tmp/reports/*.html # Upload from the temporary directory | |
# if-no-files-found: warn | |
# | |
# # Step 8: Send email with Extent Reports | |
# - name: Send email with Extent Reports | |
# if: always() # Ensure this step runs whether the build succeeds or fails | |
# uses: dawidd6/action-send-mail@v3 | |
# with: | |
# server_address: smtp.gmail.com | |
# server_port: 465 | |
# username: ${{ secrets.EMAIL_USERNAME }} | |
# password: ${{ secrets.EMAIL_PASSWORD }} | |
# subject: "Extent Report - Build ${{ github.run_number }}: ${{ job.status }}" | |
# body: | | |
# Hello, | |
# | |
# The UI Automation build ${{ github.run_number }} has completed with status: **${{ job.status }}**. | |
# | |
# Please find the attached Extent Reports. | |
# | |
# Regards, | |
# CI System | |
# to: "[email protected], [email protected]" | |
# from: "CI System <${{ secrets.EMAIL_USERNAME }}>" | |
# attachments: /tmp/reports/*.html # Attach reports from the temporary directory | |
# | |
# | |
# | |
# | |
# | |
## * * * * * | |
## | | | | | | |
## | | | | +---- Day of the week (0 - 7) (Sunday is both 0 and 7) | |
## | | | +------ Month (1 - 12) | |
## | | +-------- Day of the month (1 - 31) | |
## | +---------- Hour (0 - 23) | |
## +------------ Minute (0 - 59) | |
# | |
# | |
# | |
# | |
name: Selenium TestNG CI | |
on: | |
push: | |
branches: | |
- main | |
schedule: | |
# Schedule to run every day at 5 AM Indian time (IST) | |
- cron: '30 23 * * *' # 5:00 AM IST = 11:30 PM UTC | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the code | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
# Step 2: Set up JDK 16 | |
- name: Set up JDK 16 | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'adopt' | |
java-version: '16' | |
# Step 3: Cache Maven dependencies for faster builds | |
- name: Cache Maven dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
# Step 4: Install Maven dependencies | |
- name: Install dependencies | |
run: mvn install -DskipTests | |
# Step 5: Clean Temporary Reports Directory | |
- name: Clean Temp Reports Directory | |
run: | | |
if [ -d "/tmp/reports" ]; then | |
rm -rf /tmp/reports/* | |
echo "Old temporary reports cleaned." | |
else | |
mkdir -p /tmp/reports/suite1 | |
mkdir -p /tmp/reports/suite2 | |
mkdir -p /tmp/reports/testng | |
echo "Created temporary reports directories." | |
fi | |
# Step 6: Run tests for Suite 1 and generate report | |
- name: Run UI-Automation tests for Suite 1 | |
run: | | |
mvn test -DsuiteXmlFile=suite1.xml | |
mvn site -DsuiteXmlFile=suite1.xml -DreportOutputDirectory=/tmp/reports/suite1/ | |
# Step 7: Run tests for Suite 2 and generate report | |
- name: Run UI-Automation tests for Suite 2 | |
run: | | |
mvn test -DsuiteXmlFile=suite2.xml | |
mvn site -DsuiteXmlFile=suite2.xml -DreportOutputDirectory=/tmp/reports/suite2/ | |
# Step 8: Run TestNG tests and generate report | |
- name: Run UI-Automation tests for TestNG | |
run: | | |
mvn test -DsuiteXmlFile=testng.xml | |
mvn site -DsuiteXmlFile=testng.xml -DreportOutputDirectory=/tmp/reports/testng/ | |
# Step 9: Upload all reports as artifacts | |
- name: Upload Extent Report as Artifact for Suite 1 | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: extent-report-suite1 | |
path: /tmp/reports/suite1/*.html | |
- name: Upload Extent Report as Artifact for Suite 2 | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: extent-report-suite2 | |
path: /tmp/reports/suite2/*.html | |
- name: Upload Extent Report as Artifact for TestNG | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: extent-report-testng | |
path: /tmp/reports/testng/*.html | |
# Step 10: Send email with multiple reports attached | |
- name: Send email with Extent Reports | |
if: always() # Ensure this step runs whether the build succeeds or fails | |
uses: dawidd6/action-send-mail@v3 | |
with: | |
server_address: smtp.gmail.com | |
server_port: 465 | |
username: ${{ secrets.EMAIL_USERNAME }} | |
password: ${{ secrets.EMAIL_PASSWORD }} | |
subject: "Extent Report - Build ${{ github.run_number }}: ${{ job.status }}" | |
body: | | |
Hello, | |
The UI Automation build ${{ github.run_number }} has completed with status: **${{ job.status }}**. | |
Please find the attached Extent Reports or view them at the deployed location. | |
Regards, | |
CI System | |
to: [email protected], [email protected], [email protected] | |
from: CI System <[email protected]> | |
attachments: | | |
/tmp/reports/suite1/*.html | |
/tmp/reports/suite2/*.html | |
/tmp/reports/testng/*.html |