[DSD-4749] updated ui-automation worflow (#1358)

* [DSD-4749]

Signed-off-by: bhumi46 <thisisbn46@gmail.com>

* [DSD-4749]

Signed-off-by: bhumi46 <thisisbn46@gmail.com>

* [DSD-4749]

Signed-off-by: bhumi46 <thisisbn46@gmail.com>

---------

Signed-off-by: bhumi46 <thisisbn46@gmail.com>
This commit is contained in:
bhumi46
2024-04-03 17:16:41 +05:30
committed by GitHub
parent ce2c349a47
commit 8785d59d96
2 changed files with 152 additions and 70 deletions

View File

@@ -5,27 +5,24 @@ on:
workflow_dispatch:
inputs:
runName:
description: 'Name the run for Actions & DeviceFarm'
required: true
description: 'Name the run for Actions'
default: 'Ex: Sanity/Regression[ENV]'
type: string
buildFor:
description: 'Trigger test case run for'
required: true
default: 'Both[Android and IOS]'
type: choice
options:
- Both[Android and IOS]
- Android
- IOS
testType:
description: 'Test type Sanity/Regression'
required: true
default: 'sanity'
default: 'Sanity'
type: choice
options:
- sanity
- regression
- Sanity
- Regression
backendServiceUrl:
description: 'Mimoto and Esignet backend service URL'
required: true
@@ -34,7 +31,7 @@ on:
jobs:
android-ui-automation:
if: ${{ github.event.inputs.buildFor == 'Both[Android and IOS]' || github.event.inputs.buildFor == 'Android'}}
if: ${{ github.event.inputs.buildFor == 'Android' }}
name: Trigger android run
runs-on: ubuntu-latest
@@ -75,45 +72,31 @@ jobs:
CREDENTIAL_REGISTRY_EDIT: 'false'
RELEASE_KEYSTORE_ALIAS: 'androidreleasekey'
RELEASE_KEYSTORE_PASSWORD: "${{ secrets.INJI_ANDROID_RELEASE_STOREPASS }}"
- name: Configure AWS CLI
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_DEVICE_FARM_ACCESS_KEY }}
aws configure set aws_secret_access_key ${{ secrets.AWS_DEVICE_FARM_SECRET_KEY }}
aws configure set region us-west-2
- name: Android - Automation
id: android-run
run: |
cd injitest/scripts/ui_automation
./automation_trigger.sh "Android" "$RUN_NAME-Android" "$TEST_TYPE"
env:
RUN_NAME: ${{ github.event.inputs.runName }}
TEST_TYPE: ${{ github.event.inputs.testType }}
- name: Download Android Artifacts
run: |
cd injitest/scripts/ui_automation
./download_artifacts.sh "$RUN_ARN" "Android"
- name: Upload Artifact to Actions
uses: actions/upload-artifact@v3.1.1
with:
name: Android-Artifacts
path: injitest/scripts/ui_automation/artifacts/android_artifacts/
name: residentapp
path: android/app/build/outputs/apk/residentapp/release/Inji_universal.apk
retention-days: 10
# - name: Update slack channel
# if: always()
# uses: 8398a7/action-slack@v3
# with:
# status: ${{ job.status }}
# fields: repo,message,author,commit,workflow,job
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_INJI_TEAM }}
- name: Run UI Automation Tests on BrowserStack
run: |
chmod +x injitest/automation_trigger.sh
./injitest/automation_trigger.sh "$BROWSERSTACK_USERNAME" "$BROWSERSTACK_ACCESS_KEY" "$TEST_TYPE" "$PLATFORM_NAME"
env:
PLATFORM_NAME: ${{ github.event.inputs.buildFor }}
TEST_TYPE: ${{ github.event.inputs.testType }}
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
- name: Save test reports
uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: test-reports
path: injitest/target/surefire-reports
ios-ui-automation:
if: ${{ github.event.inputs.buildFor == 'Both[Android and IOS]' || github.event.inputs.buildFor == 'IOS'}}
if: ${{ github.event.inputs.buildFor == 'IOS' }}
name: Trigger ios run
runs-on: macos-13
@@ -154,37 +137,19 @@ jobs:
APPLE_KEY_CONTENT: '${{ secrets.APPLE_KEY_CONTENT }}'
MATCH_PASSWORD: '${{ secrets.INJI_IOS_MATCH_PASSWORD }}'
- name: Configure AWS CLI
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_DEVICE_FARM_ACCESS_KEY }}
aws configure set aws_secret_access_key ${{ secrets.AWS_DEVICE_FARM_SECRET_KEY }}
aws configure set region us-west-2
- name: IOS - Automation
run: |
cd injitest/scripts/ui_automation
./automation_trigger.sh "IOS" "$RUN_NAME-IOS" "$TEST_TYPE"
env:
RUN_NAME: ${{ github.event.inputs.runName }}
TEST_TYPE: ${{ github.event.inputs.testType }}
- name: Download IOS Artifacts
run: |
cd injitest/scripts/ui_automation
./download_artifacts.sh "$RUN_ARN" "IOS"
- name: Upload Artifact to Actions
uses: actions/upload-artifact@v3.1.1
with:
name: IOS-Artifacts
path: injitest/scripts/ui_automation/artifacts/ios_artifacts/
name: residentapp
path: ios/fastlane/Inji_artifacts/Inji.ipa
retention-days: 10
# - name: Update slack channel
# if: always()
# uses: 8398a7/action-slack@v3
# with:
# status: ${{ job.status }}
# fields: repo,message,author,commit,workflow,job
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_INJI_TEAM }}
- name: Run UI Automation Tests on BrowserStack
run: |
chmod +x injitest/automation_trigger.sh
./injitest/automation_trigger.sh "$BROWSERSTACK_USERNAME" "$BROWSERSTACK_ACCESS_KEY" "$TEST_TYPE" "$PLATFORM_NAME"
env:
PLATFORM_NAME: ${{ github.event.inputs.buildFor }}
TEST_TYPE: ${{ github.event.inputs.testType }}
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}

117
injitest/automation_trigger.sh Executable file
View File

@@ -0,0 +1,117 @@
#!/bin/bash
# Function for generic error handling
handle_error() {
local error_message="$1"
echo "Error: $error_message"
exit 1
}
# Function to upload APK to BrowserStack and extract app_url
upload_apk_and_get_url() {
local username="$1"
local access_key="$2"
local project_path=$(pwd)
local apk_path="$project_path/android/app/build/outputs/apk/residentapp/release/Inji_universal.apk"
if [[ -f "$apk_path" ]]; then
response=$(curl -u "$username:$access_key" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@$apk_path")
# Add sleep for 5 seconds to allow the response to be processed
sleep 60
app_url=$(echo "$response" | jq -r '.app_url')
if [[ ! -z "$app_url" ]]; then
echo "$app_url"
else
handle_error "Failed to extract app_url from the response"
fi
else
handle_error "APK file not found at $apk_path"
fi
}
# Function to upload IPA to BrowserStack and extract app_url
upload_ipa_and_get_url() {
local username="$1"
local access_key="$2"
local project_path=$(pwd)
local ipa_path="$project_path/ios/fastlane/Inji_artifacts/Inji.ipa"
if [[ -f "$ipa_path" ]]; then
response=$(curl -u "$username:$access_key" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@$ipa_path")
# Add sleep for 5 seconds to allow the response to be processed
sleep 60
app_url=$(echo "$response" | jq -r '.app_url')
if [[ ! -z "$app_url" ]]; then
echo "$app_url"
else
handle_error "Failed to extract app_url from the response"
fi
else
handle_error "IPA file not found at $ipa_path"
fi
}
# Function to execute Android tests
execute_android_tests() {
local app_url="$1"
local username="$2"
local access_key="$3"
local test_type="$4"
cd injitest
# Update androidConfig.yml with the app_url obtained from BrowserStack
sed -i "s|app:.*|app: $app_url|" androidConfig.yml
sed -i "s|userName:.*|userName: $username|" androidConfig.yml
sed -i "s|accessKey:.*|accessKey: $access_key|" androidConfig.yml
# Run UI tests using Maven with the updated androidConfig.yml file and TestNG XML file based on the test type
mvn clean test -DtestngXmlFile="android${test_type^}.xml" -Dbrowserstack.config="androidConfig.yml"
}
# Function to execute iOS tests
execute_ios_tests() {
local app_url="$1"
local username="$2"
local access_key="$3"
local test_type="$4"
cd injitest
# Update iosConfig.yml with the app_url obtained from BrowserStack
sed -i "s|app:.*|app: $app_url|" iosConfig.yml
sed -i "s|userName:.*|userName: $username|" iosConfig.yml
sed -i "s|accessKey:.*|accessKey: $access_key|" iosConfig.yml
# Run UI tests using Maven with the updated iosConfig.yml file and TestNG XML file based on the test type
mvn clean test -DtestngXmlFile="ios${test_type^}.xml" -Dbrowserstack.config="iosConfig.yml"
}
# Check if the correct number of arguments are passed
if [ "$#" -ne 4 ]; then
echo "Expected arguments: $@"
handle_error "Usage: $0 <username> <access_key> <test_type> <platform>"
fi
# Assigning parameters to variables
username=$1
access_key=$2
test_type=$3
platform=$4
# Upload APK/IPA to BrowserStack and get app_url based on platform
if [ "$platform" = "Android" ]; then
app_url=$(upload_apk_and_get_url "$username" "$access_key")
execute_android_tests "$app_url" "$username" "$access_key" "$test_type"
elif [ "$platform" = "IOS" ]; then
app_url=$(upload_ipa_and_get_url "$username" "$access_key")
execute_ios_tests "$app_url" "$username" "$access_key" "$test_type"
else
handle_error "Invalid platform. Please use 'Android', 'IOS'."
fi