From 21d991b04e7b340e1693e3876ba3c80786fc7f9c Mon Sep 17 00:00:00 2001 From: Sefa Ilkimen Date: Sat, 14 Dec 2019 04:09:11 +0100 Subject: [PATCH] chore: setup testing android version on BrowserStack --- .github/workflows/ci.yml | 9 ++++- .travis.yml | 4 +-- scripts/upload-browserstack.sh | 33 +++++++++++++++++++ ...upload-artifact.sh => upload-saucelabs.sh} | 0 test/e2e-tooling/caps.js | 17 ++++++++++ test/e2e-tooling/server.js | 5 +++ test/e2e-tooling/test.js | 5 +-- 7 files changed, 68 insertions(+), 5 deletions(-) create mode 100755 scripts/upload-browserstack.sh rename scripts/{upload-artifact.sh => upload-saucelabs.sh} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 969a8f3d..eebf23de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,9 @@ jobs: build-android: runs-on: ubuntu-latest + env: + BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} + BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} steps: - uses: actions/checkout@v1 - name: Install Node.js ${{ env.nodejs }} @@ -53,4 +56,8 @@ jobs: - name: Add workaround for mipsel reference run: sudo mkdir -p $ANDROID_HOME/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/linux-x86_64 - name: Build test app - run: scripts/build-test-app.sh --android --emulator + run: scripts/build-test-app.sh --android --device + - name: Upload artifact to BrowserStack + run: scripts/upload-browserstack.sh --android + - name: Run e2e tests + run: scripts/test-app.sh --android --device diff --git a/.travis.yml b/.travis.yml index 1b2e4dd9..64be77cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ matrix: - npm run testjs && npm run updatecert && scripts/build-test-app.sh --ios --emulator && - scripts/upload-artifact.sh --ios && + scripts/upload-saucelabs.sh --ios && scripts/test-app.sh --ios --emulator; - name: "Android Build & Test" @@ -55,5 +55,5 @@ matrix: - npm run testjs && npm run updatecert && scripts/build-test-app.sh --android --emulator && - scripts/upload-artifact.sh --android && + scripts/upload-saucelabs.sh --android && scripts/test-app.sh --android --emulator; diff --git a/scripts/upload-browserstack.sh b/scripts/upload-browserstack.sh new file mode 100755 index 00000000..39bb1654 --- /dev/null +++ b/scripts/upload-browserstack.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -e + +PLATFORM=$([[ "${@#--android}" = "$@" ]] && echo "ios" || echo "android") +ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd ..; pwd )" +TEMP=$ROOT/temp + +if [ -z $BROWSERSTACK_USERNAME ] || [ -z $BROWSERSTACK_ACCESS_KEY ]; then + echo "Skipping uploading artifact, because BrowserStack credentials are not set."; + exit 0; +fi + +if [ $PLATFORM = "android" ]; then + curl -u $BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY \ + -X POST \ + https://api-cloud.browserstack.com/app-automate/upload \ + -F "file=@$TEMP/platforms/android/app/build/outputs/apk/debug/app-debug.apk" \ + -F "data={\"custom_id\": \"HttpTestAppAndroid\"}" +else + rm -rf $TEMP/HttpDemo.ipa + pushd $TEMP/platforms/ios/build/emulator + rm -rf ./Payload + mkdir -p ./Payload + cp -r ./HttpDemo.app ./Payload/HttpDemo.app + zip -r $TEMP/HttpDemo.ipa ./Payload + popd + + curl -u $BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY \ + -X POST \ + https://api-cloud.browserstack.com/app-automate/upload \ + -F "file=@$TEMP/HttpDemo.ipa" \ + -F "data={\"custom_id\": \"HttpTestAppIos\"}" +fi diff --git a/scripts/upload-artifact.sh b/scripts/upload-saucelabs.sh similarity index 100% rename from scripts/upload-artifact.sh rename to scripts/upload-saucelabs.sh diff --git a/test/e2e-tooling/caps.js b/test/e2e-tooling/caps.js index dff023ec..79660264 100644 --- a/test/e2e-tooling/caps.js +++ b/test/e2e-tooling/caps.js @@ -56,11 +56,28 @@ const configs = { deviceName: 'Android Emulator', autoWebview: true, app: 'sauce-storage:HttpDemo.apk' + }, + + // testing on BrowserStack + browserstackIosDevice: { + device: 'iPhone 7', + os_version: '10', + project: 'HTTP Test App', + autoWebview: true, + app: 'HttpTestAppAndroid' + }, + browserstackAndroidDevice: { + device: 'Google Nexus 9', + os_version: '5.1', + project: 'HTTP Test App', + autoWebview: true, + app: 'HttpTestAppAndroid' } }; function getCaps(environment, os, runtime) { const key = environment.toLowerCase() + capitalize(os) + capitalize(runtime); + console.log(key); const caps = configs[key]; caps.name = `cordova-plugin-advanced-http (${os})`; diff --git a/test/e2e-tooling/server.js b/test/e2e-tooling/server.js index d239ea9c..3328bd0d 100644 --- a/test/e2e-tooling/server.js +++ b/test/e2e-tooling/server.js @@ -9,6 +9,11 @@ const configs = { host: 'ondemand.saucelabs.com', port: 80, auth: process.env.SAUCE_USERNAME + ":" + process.env.SAUCE_ACCESS_KEY + }, + browserstack: { + host: 'hub-cloud.browserstack.com', + port: 80, + auth: process.env.BROWSERSTACK_USERNAME + ":" + process.env.BROWSERSTACK_ACCESS_KEY } } diff --git a/test/e2e-tooling/test.js b/test/e2e-tooling/test.js index ac2d0253..53ccdcdb 100644 --- a/test/e2e-tooling/test.js +++ b/test/e2e-tooling/test.js @@ -12,12 +12,13 @@ global.should = chai.should(); describe('Advanced HTTP e2e test suite', function () { const isSauceLabs = !!process.env.SAUCE_USERNAME; + const isBrowserStack = !!process.env.BROWSERSTACK_USERNAME; const isVerbose = process.argv.includes('--verbose'); const isDevice = process.argv.includes('--device'); const isAndroid = process.argv.includes('--android'); - const targetInfo = { isSauceLabs, isDevice, isAndroid }; - const environment = isSauceLabs ? 'saucelabs' : 'local'; + const targetInfo = { isSauceLabs, isBrowserStack, isDevice, isAndroid }; + const environment = isSauceLabs ? 'saucelabs' : isBrowserStack ? 'browserstack' : 'local'; let driver; let allPassed = true;