Skip to content

Commit

Permalink
Android Emulator (#61)
Browse files Browse the repository at this point in the history
### To be filled by the PR creator:

* A brief description of the changes made - 

* Do we have clean latest run report (Docker or Browserstack) attached
with this PR?
  * [ ] Yes
  * [ ] No (Please explain why)

* Does the PR contain changes to any core file?
  * [ ] Yes (Needs approval from at least 1 people)
  * [ ] No

* Is it
  * [ ] New Testcase
  * [ ] Fix


### To be filled by the PR reviewer:

* [ ] Verify the attached run report passed in GitHub Actions (Docker or
Browserstack run)

* General
    * [ ] Use the best strategy to locate the elements
    * [ ] Comments wherever the code is not readable by itself
    * [ ] Use of the right data structure for the use case
    * [ ] Reuse logic/functionality as much as possible
    * [ ] Cleanup of any test data that is generated by the tests
    * [ ] No static waits
  • Loading branch information
Tauqir Sarwar authored Mar 22, 2024
2 parents a2a4b61 + 5f03d22 commit 9faa169
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 28 deletions.
125 changes: 97 additions & 28 deletions .github/workflows/docker_android_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,105 @@ jobs:
sleep 10
appium -v
# - name: Android Emulator Runner Without SDK Setup
# uses: RandyLutcavich/[email protected]
# - name: Android Emulator Runner Without SDK Setup
# uses: RandyLutcavich/[email protected]

# - name: AVD cache
# uses: actions/cache@v4
# id: avd-cache
# with:
# path: |
# ~/.android/avd/*
# ~/.android/adb*
# key: avd-test
#
# - name: Run Android Emulator
# id: run_emulator
# if: steps.setup_dependencies.outcome == 'success'
# uses: ReactiveCircus/android-emulator-runner@v2
# with:
# api-level: 30
# force-avd-creation: false
# emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
# disable-animations: true
# target: default
# arch: x86_64
# script: echo "Generated AVD Started"
#
# - name: Run Android Emulator Again
# id: run_emulator_again
# if: steps.run_emulator.outcome == 'success'
# run: |
# echo "Running Emulator Again"
# cd ~/Library/Android/sdk/emulator
# ./emulator -list-avds
# ./emulator -avd test -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none

# - name: set up JDK 17
# uses: actions/setup-java@v3
# with:
# java-version: '17'
# distribution: 'temurin'
#
# - name: Setup Android SDK
# uses: android-actions/setup-android@v3
#
# - name: Create Android emulator
# run: |
# sdkmanager --install "system-images;android-31;google_apis;x86_64"
# echo "no" | avdmanager --verbose create avd --force --name testAVD --abi google_apis/x86_64 --package 'system-images;android-31;google_apis;x86_64'
#
# - name: Launch Emulator
# run: |
# $ANDROID_SDK_ROOT/emulator/emulator -avd testAVD

- name: Create Android emulator
run: |
brew install intel-haxm
# Install AVD files
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-27;default;x86_64'
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --licenses
# Create emulator
$ANDROID_HOME/tools/bin/avdmanager create avd -n Pixel_API_29_AOSP -d pixel --package 'system-images;android-27;default;x86_64'
$ANDROID_HOME/emulator/emulator -list-avds
if false; then
emulator_config=~/.android/avd/Pixel_API_29_AOSP.avd/config.ini
sed -i .bak 's/hw.lcd.density=.*/hw.lcd.density=480/' "$emulator_config"
sed -i .bak 's/hw.lcd.height=.*/hw.lcd.height=2220/' "$emulator_config"
sed -i .bak 's/hw.lcd.width=.*/hw.lcd.width=1080/' "$emulator_config"
# Or, add new config
if ! grep -q "hw.lcd.density" "$emulator_config"; then
echo "hw.lcd.density=480" >> "$emulator_config"
fi
if ! grep -q "hw.lcd.height" "$emulator_config"; then
echo "hw.lcd.height=2220" >> "$emulator_config"
fi
if ! grep -q "hw.lcd.width" "$emulator_config"; then
echo "hw.lcd.width=1080" >> "$emulator_config"
fi
echo "Emulator settings ($emulator_config)"
cat "$emulator_config"
fi
- name: Start Android emulator
id: start_emulator
run: |
echo "Starting emulator and waiting for boot to complete...."
ls -la $ANDROID_HOME/emulator
nohup $ANDROID_HOME/tools/emulator -avd Pixel_API_29_AOSP -gpu host -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 2>&1 &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do echo "wait..."; sleep 1; done; input keyevent 82'
echo "Emulator has finished booting"
$ANDROID_HOME/platform-tools/adb devices
sleep 30
screencapture screenshot.jpg
$ANDROID_HOME/platform-tools/adb exec-out screencap -p > emulator.png
- name: Check out code
id: co_code
if: steps.install_driver.outcome == 'success'
if: steps.start_emulator.outcome == 'success'
uses: actions/checkout@v4

- name: Setup dependencies
Expand All @@ -147,33 +240,9 @@ jobs:
run: |
sh setup_install.sh
- name: Run Android Emulator
id: run_emulator
if: steps.setup_dependencies.outcome == 'success'
uses: ReactiveCircus/android-emulator-runner@v2
with:
api-level: 30
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -grpc-use-jwt -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
target: default
arch: x86_64
script: echo "Generated AVD Started"

- name: Run Android Emulator Again
id: run_emulator_again
if: steps.run_emulator.outcome == 'success'
run: |
echo "Running Emulator Again"
cd ~/Library/Android/sdk/emulator
sleep 5
./emulator -list-avds
sleep 5
./emulator -avd test -no-snapshot-save -no-window -grpc-use-jwt -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
- name: Run Tests
id: run_manual_job
if: steps.run_emulator_again.outcome == 'success'
if: steps.setup_dependencies.outcome == 'success'
run: |
TAGS="${{ github.event.inputs.tags }}"
env
Expand Down
5 changes: 5 additions & 0 deletions frontend/test_project/features/mobile/android_login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Feature: Basic App functionality
When The element 'Android > _mob > MyDemoApp > item_sl_backpack' is displayed
And I swipe down '50' % each time for '4' times
And I click on element 'Android > _mob > an-items > Sauce_Labs_Onesie'
And I swipe down '50' % each time for '1' times
And The element 'Android > _mob > MyDemoApp > add_to_cart' is displayed
And I click on element 'Android > _mob > MyDemoApp > add_to_cart'
When I click on element 'Android > _mob > MyDemoApp > add_to_cart'
Expand All @@ -56,6 +57,7 @@ Feature: Basic App functionality
When The element 'Android > _mob > MyDemoApp > item_sl_backpack' is displayed
And I swipe down '50' % each time for '4' times
And I click on element 'Android > _mob > an-items > Sauce_Labs_Onesie'
And I swipe down '50' % each time for '1' times
Then The element 'Android > _mob > MyDemoApp > add_to_cart' is displayed
When I click on element 'Android > _mob > MyDemoApp > add_to_cart'
And I click on element 'Android > _mob > MyDemoApp > add_to_cart'
Expand All @@ -68,10 +70,12 @@ Feature: Basic App functionality
Then The element 'Android > _mob > an-Shipping_Info > Full_name' is displayed
When I set text 'Tauqir Sarwar' to field 'Android > _mob > an-Shipping_Info > Full_name'
And I set text 'Main Cantt' to field 'Android > _mob > an-Shipping_Info > Address_line_1'
And I swipe down '50' % each time for '1' times
And I set text 'Lahore' to field 'Android > _mob > an-Shipping_Info > City'
And I swipe down '50' % each time for '2' times
And I set text '102040' to field 'Android > _mob > an-Shipping_Info > Zip_code'
And I set text 'Pakistan' to field 'Android > _mob > an-Shipping_Info > Country'
And I swipe down '50' % each time for '1' times
And I click on element 'Android > _mob > an-Payment_Detail > Payment'
Then The element 'Android > _mob > an-Payment_Detail > Full_name' is displayed
When I set text 'Tauqir Sarwar' to field 'Android > _mob > an-Payment_Detail > Full_name'
Expand All @@ -80,6 +84,7 @@ Feature: Basic App functionality
And I swipe down '50' % each time for '1' times
And I set text '0325' to field 'Android > _mob > an-Payment_Detail > expired_card'
And I set text '123' to field 'Android > _mob > an-Payment_Detail > CVV'
And I swipe down '50' % each time for '1' times
Then The element 'Android > _mob > an-Review_Order > Review' is displayed
When I click on element 'Android > _mob > an-Review_Order > Review'
And I swipe down '50' % each time for '2' times
Expand Down

0 comments on commit 9faa169

Please sign in to comment.