-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xiaoweii
committed
Jan 4, 2024
1 parent
392f94a
commit c0de016
Showing
5 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Integration Test | ||
|
||
on: | ||
push: | ||
branches: [ "*" ] | ||
pull_request: | ||
branches: [ "*" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
iam_role_to_assume: ${{ secrets.ROLE_ARN }} | ||
device_farm_project_arn: ${{ secrets.DEVICE_FARM_PROJECT_ARN }} | ||
device_farm_pool_arn: ${{ secrets.DEVICE_FARM_POOL_ARN }} | ||
device_farm_test_spec_arn: ${{ secrets.DEVICE_FARM_TEST_SPEC_ARN }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: set up JDK 8 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '8' | ||
distribution: 'corretto' | ||
cache: gradle | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
- name: Configure AWS Credentials | ||
if: ${{ env.iam_role_to_assume != '' }} | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ env.iam_role_to_assume }} | ||
aws-region: us-west-2 | ||
- name: Build release aar | ||
run: ./gradlew assembleRelease | ||
- name: Build apk | ||
run: | | ||
git clone https://github.com/zhu-xiaowei/shopping-android | ||
cd shopping-android | ||
./gradlew assembleDebug | ||
cd .. | ||
- name: Build device farm test file | ||
run: | | ||
cd integrationtest | ||
virtualenv workspace | ||
cd workspace | ||
source bin/activate | ||
pip install pytest | ||
pip install Appium-Python-Client | ||
mkdir tests | ||
cp ../appium/shopping_test.py tests/ | ||
find tests/ | ||
py.test --collect-only tests/ | ||
find . -name '__pycache__' -type d -exec rm -r {} + | ||
find . -name '*.pyc' -exec rm -f {} + | ||
find . -name '*.pyo' -exec rm -f {} + | ||
find . -name '*~' -exec rm -f {} + | ||
pip freeze > requirements.txt | ||
zip -r test_bundle.zip tests/ requirements.txt | ||
cd .. | ||
- name: Execute device farm test | ||
run: | | ||
pip install -r requirements.txt | ||
cd devicefarm | ||
cp ../../shopping-android/app/build/output/apk/debug/app-debug.apk ./ | ||
cp ../workspace/test_bundle.zip ./ | ||
ls | ||
python -c "from automate_device_farm import upload_and_test_android; upload_and_test_android('app-debug.apk', 'test_bundle.zip', '${{ env.device_farm_project_arn }}', '${{ env.device_farm_test_spec_arn }}', '${{ env.device_farm_pool_arn }}')" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,3 +101,7 @@ build-artifacts.tar.gz | |
|
||
# add ignore for jenv | ||
.java-version | ||
|
||
# python | ||
venv | ||
*.idea |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import pytest | ||
from time import sleep | ||
|
||
from appium import webdriver | ||
from appium.options.android import UiAutomator2Options | ||
from appium.webdriver.common.appiumby import AppiumBy | ||
|
||
capabilities = dict( | ||
platformName='Android', | ||
automationName='uiautomator2', | ||
deviceName='Android', | ||
appPackage='com.kanyideveloper.joomia', | ||
appActivity='.core.presentation.MainActivity', | ||
language='en', | ||
locale='US', | ||
) | ||
|
||
appium_server_url = 'http://0.0.0.0:4723/wd/hub' | ||
|
||
|
||
class TestShopping: | ||
def setup(self): | ||
self.driver = webdriver.Remote(appium_server_url, options=UiAutomator2Options().load_capabilities(capabilities)) | ||
self.driver.implicitly_wait(10) | ||
|
||
def teardown(self): | ||
if self.driver: | ||
self.driver.quit() | ||
|
||
@pytest.mark.parametrize("user_name,password", [ | ||
("user1", "password1"), | ||
("user2", "password2"), | ||
]) | ||
def test_shopping(self, user_name, password): | ||
# login | ||
username_et = self.find_element("userName") | ||
username_et.send_keys(user_name) | ||
password_et = self.find_element("password") | ||
password_et.send_keys(password) | ||
signin_bt = self.find_element("signIn") | ||
signin_bt.click() | ||
sleep(3) | ||
|
||
# add 2 product to cart | ||
product_1 = self.find_element('product0') | ||
sleep(1) | ||
product_1.click() | ||
add_to_cart1 = self.find_element('add_to_cart_button') | ||
sleep(1) | ||
add_to_cart1.click() | ||
sleep(1) | ||
self.driver.press_keycode(4) | ||
|
||
product_2 = self.find_element('product1') | ||
sleep(1) | ||
product_2.click() | ||
add_to_cart2 = self.find_element('add_to_cart_button') | ||
sleep(1) | ||
add_to_cart2.click() | ||
sleep(1) | ||
self.driver.press_keycode(4) | ||
|
||
# click 1 product to wishlist | ||
product_3 = self.find_element('product2') | ||
sleep(1) | ||
product_3.click() | ||
like_button = self.find_element('like_button') | ||
sleep(1) | ||
like_button.click() | ||
sleep(1) | ||
self.driver.press_keycode(4) | ||
sleep(1) | ||
wishlist_tab = self.find_element('homeTab1') | ||
wishlist_tab.click() | ||
sleep(1) | ||
|
||
cart_tab = self.find_element('homeTab2') | ||
cart_tab.click() | ||
checkout_bt = self.find_element('check_out_button') | ||
sleep(1) | ||
checkout_bt.click() | ||
|
||
profile_tab = self.find_element('homeTab3') | ||
sleep(1) | ||
profile_tab.click() | ||
sign_out_bt = self.find_element('sign_out_button') | ||
sleep(1) | ||
sign_out_bt.click() | ||
self.driver.press_keycode(3) | ||
sleep(2) | ||
|
||
def find_element(self, name): | ||
return self.driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, | ||
value='new UiSelector().resourceId("' + name + '")') | ||
|
||
|
||
if __name__ == '__main__': | ||
TestShopping.test_shopping() |
Oops, something went wrong.