Skip to content

Commit

Permalink
feat: add integration tst
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoweii committed Jan 20, 2024
1 parent 2bd2962 commit 7cef6a0
Show file tree
Hide file tree
Showing 7 changed files with 661 additions and 14 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Integration Test

on:
pull_request:
branches: [ "*" ]
push:
branches: [ "*" ]

jobs:
test:
runs-on: macos-13-xl
permissions:
contents: write
checks: write
pull-requests: write
id-token: write
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 }}
clickstream_app_id: ${{ secrets.CLICKSTREAM_APP_ID }}
clickstream_endpoint: ${{ secrets.CLICKSTREAM_ENDPOINT }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PROJECT_TOKEN }}
- name: Modify SDK for integration test
run: |
sed -i "s#private(set) var bundleSequenceId: Int#private(set) var bundleSequenceId: Int\n var allEventJson: String = \"\"#g" Sources/Clickstream/Dependency/Clickstream/Analytics/EventRecorder.swift
sed -i "s#toPrettierJsonString())\")#toPrettierJsonString())\")\n allEventJson.append(\"Saved event /\(event.eventType):/\(eventObject.toJsonString())/\n\")\n UIPasteboard.general.string = allEventJson#g" Sources/Clickstream/Dependency/Clickstream/Analytics/EventRecorder.swift
sed -i "s#batchEvent.eventCount) events\")#batchEvent.eventCount) events\")\n allEventJson.append(\"Saved event /\(event.eventType):/\(eventObject.toJsonString())/\n\")\n UIPasteboard.general.string = allEventJson#g" Sources/Clickstream/Dependency/Clickstream/Analytics/EventRecorder.swift
cat Sources/Clickstream/Dependency/Clickstream/Analytics/EventRecorder.swift
echo "git diff"
git diff
git config user.name "github-actions"
git config user.email "[email protected]"
git checkout -b pastboard
git push
# - name: Build sample iOS app
# run: |
# git clone https://github.com/aws-samples/clickstream-sdk-samples
# mkdir clickstream-sdk-samples/android/app/libs/
# cp -f clickstream/build/outputs/aar/clickstream-release.aar clickstream-sdk-samples/android/app/libs/
# cd clickstream-sdk-samples/android
# sed -i "s#\"appId\": \"your appId\"#\"appId\": \"${{ env.clickstream_app_id }}\"#g" app/src/main/res/raw/amplifyconfiguration.json
# sed -i "s#\"endpoint\": \"your endpoint\"#\"endpoint\": \"${{ env.clickstream_endpoint }}\"#g" app/src/main/res/raw/amplifyconfiguration.json
# cat app/src/main/res/raw/amplifyconfiguration.json
# sed -i "s#implementation 'software.aws.solution:clickstream:0.10.0'#implementation(files(\"libs/clickstream-release.aar\"))\n implementation(\"com.amplifyframework:core:1.37.2\")\n implementation(\"com.amazonaws:aws-android-sdk-mobile-client:2.51.0\")\n implementation(\"com.squareup.okhttp3:okhttp:4.9.1\")#g" app/build.gradle
# cat app/build.gradle
# ./gradlew assembleDebug
# - name: Build Device Farm test file
# run: |
# cd integrationtest
# pip install virtualenv
# virtualenv --help
# 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
# ls
# cd ..
- 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: Execute device farm test
# run: |
# cd integrationtest
# pip install -r requirements.txt
# cd devicefarm
# cp ../../clickstream-sdk-samples/android/app/build/outputs/apk/debug/app-debug.apk ./
# cp ../workspace/test_bundle.zip ./
# ls
# python -u -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 }}')"
# - name: Execute logcat test
# run: |
# cd integrationtest/devicefarm
# pytest logcat_test.py -s --junitxml=report/logcat_test_report.xml --html=report/logcat_test_report.html
# - name: Publish Test Report
# uses: mikepenz/action-junit-report@v4
# if: success() || failure()
# with:
# report_paths: 'integrationtest/devicefarm/report/*.xml'
# require_tests: true
# detailed_summary: true
# include_passed: true
# fail_on_failure: true
# job_name: integration test
# - name: Upload test result
# uses: actions/upload-artifact@v4
# if: success() || failure()
# with:
# name: test-result
# path: |
# integrationtest/devicefarm/report/
# integrationtest/devicefarm/MyAndroidAppTest-*/**
44 changes: 30 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
Expand All @@ -22,17 +22,33 @@ jobs:
chmod +x release.sh
./release.sh ${{ env.NEW_VERSION }}
git diff
git config user.name '${{ vars.USER_NAME }}'
git config user.email '${{ vars.USER_EMAIL }}'
git add .
git commit -m 'release: clickstream Swift ${{ env.NEW_VERSION }}'
git push
git tag ${{ env.NEW_VERSION }}
git push origin ${{ env.NEW_VERSION }}
- name: Create GitHub release
uses: softprops/action-gh-release@v1
git config user.name "github-actions"
git config user.email "[email protected]"
- name: Create Pull Request
id: create-pr
uses: peter-evans/create-pull-request@v5
with:
name: "Clickstream Swift ${{ env.NEW_VERSION }}"
tag_name: "${{ env.NEW_VERSION }}"
prerelease: true
generate_release_notes: true
token: ${{ secrets.PROJECT_TOKEN }}
commit-message: 'release: clickstream Swift ${{ env.NEW_VERSION }}'
title: 'release: clickstream Swift ${{ env.NEW_VERSION }}'
author: github-actions <[email protected]>
committer: github-actions <[email protected]>
signoff: true
body: |
## Description
1. release: clickstream Swift ${{ env.NEW_VERSION }}
## General Checklist
<!-- Check or cross out if not relevant -->
- [x] Added new tests to cover change, if needed
- [x] Build succeeds using Swift Package Manager
- [x] All unit tests pass
- [x] Documentation update for the change if required
- [x] PR title conforms to conventional commit style
- [x] If breaking change, documentation/changelog update with migration instructions
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
labels: release
branch: release_${{ env.NEW_VERSION }}
35 changes: 35 additions & 0 deletions .github/workflows/tag_and_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Create Tag And Release
on:
push:
branches: [ "main" ]

jobs:
release:
if: ${{ startsWith(github.event.head_commit.message, 'release:') }}
runs-on: ubuntu-latest
env:
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ secrets.PROJECT_TOKEN }}
- name: Create new tag
run: |
echo "${{ env.COMMIT_MESSAGE }}"
version=$(echo "${{ env.COMMIT_MESSAGE }}" | grep -oP 'Swift \K\d+\.\d+\.\d+')
echo $version
git config user.name '${{ vars.USER_NAME }}'
git config user.email '${{ vars.USER_EMAIL }}'
git tag v$version
git push origin v$version
- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
name: "Clickstream Swift ${{ env.NEW_VERSION }}"
tag_name: "${{ env.NEW_VERSION }}"
prerelease: true
generate_release_notes: true
70 changes: 70 additions & 0 deletions IntegrationTest/appium/shopping_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
with the License. A copy of the License is located at
http://www.apache.org/licenses/LICENSE-2.0
or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
and limitations under the License.
"""
import pytest
from time import sleep

from appium import webdriver
from appium.options.ios import XCUITestOptions
from appium.webdriver.common.appiumby import AppiumBy

capabilities = dict(
platformName='ios',
automationName='xcuitest',
deviceName='iPhone',
bundleId='software.aws.solution.ModerneShopping',
language='en',
locale='US',
)

appium_server_url = 'http://0.0.0.0:4723/wd/hub'


class TestShopping:
def setup_method(self):
self.driver = webdriver.Remote(appium_server_url, options=XCUITestOptions().load_capabilities(capabilities))
self.driver.implicitly_wait(10)

def teardown_method(self):
if self.driver:
self.driver.quit()

@pytest.mark.parametrize("test_suite", [
"test suite 1",
"test suite 2"
])
def test_shopping(self, test_suite):
sleep(3)
self.perform_click_element('Profile')
self.perform_click_element('sign_in')
sleep(3)
self.perform_click_element('Cart')
self.perform_click_element('check_out')
self.perform_click_element('purchase')
self.perform_click_element('Profile')
self.perform_click_element("sign_out")
self.driver.execute_script('mobile: backgroundApp', {"seconds": 5})
sleep(1)
self.perform_click_element("show_log_text")
event_log = self.driver.find_element(by=AppiumBy.ID, value="event_log")
self.driver.log_event("app_event_log", event_log.text)
print(event_log.text)
sleep(1)

def perform_click_element(self, element_id):
element = self.driver.find_element(by=AppiumBy.ID, value=element_id)
element.click()
sleep(2)


if __name__ == '__main__':
TestShopping.test_shopping()
Loading

0 comments on commit 7cef6a0

Please sign in to comment.