Skip to content

Instantly share code, notes, and snippets.

@martinschneider
Created May 5, 2019 05:21
Show Gist options
  • Save martinschneider/39fb8fc937b1c3c4f5d5dfb798a7118a to your computer and use it in GitHub Desktop.
Save martinschneider/39fb8fc937b1c3c4f5d5dfb798a7118a to your computer and use it in GitHub Desktop.
version: 0.1
phases:
install:
commands:
# AWS still only supports Java 8, so we install Java 12 ourselves
# https://forums.aws.amazon.com/thread.jspa?threadID=299604
- wget -q https://download.java.net/java/GA/jdk12/GPL/openjdk-12_linux-x64_bin.tar.gz
- tar -xzf openjdk-12_linux-x64_bin.tar.gz
- export JAVA_HOME=$(pwd)/jdk-12
- export PATH=$(pwd)/jdk-12/bin:$PATH
- which java
- java -version
# Required for image recognition but AWS doesn't support it yet (https://forums.aws.amazon.com/thread.jspa?threadID=300720)
#- npm i -g opencv4nodejs
- export APPIUM_VERSION=1.9.1
- avm $APPIUM_VERSION
pre_test:
commands:
- echo "whoami `whoami`"
- aws --version
# Starting Appium server
- echo "Starting appium server"
- >-
appium --log-timestamp --chromedriver-executable $DEVICEFARM_CHROMEDRIVER_EXECUTABLE >> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &
- >-
start_appium_timeout=0;
while [ true ];
do
if [ $start_appium_timeout -gt 30 ];
then
echo "appium server never started in 30 seconds. Exiting";
exit 1;
fi;
grep -i "Appium REST http interface listener started on 0.0.0.0:4723" $DEVICEFARM_LOG_DIR/appiumlog.txt >> /dev/null 2>&1;
if [ $? -eq 0 ];
then
echo "Appium REST http interface listener started on 0.0.0.0:4723";
break;
else
echo "Waiting for appium server to start. Sleeping for 1 second";
sleep 1;
start_appium_timeout=$((start_appium_timeout+1));
fi;
done;
test:
commands:
# Prepare the test code
- cd $DEVICEFARM_TEST_PACKAGE_PATH
- echo "Extracting JAR files"
- mkdir classes
- cd classes
# Unpack everything into `classes` (hacky!)
- unzip -o ../\*.jar
- cd ..
# Copy the feature files to `src/test/resources` (so we don't need to change the `features.directory` parameter)
- mkdir -p src/test/resources/features
- cp -r classes/features src/test/resources
# Remove `justtestlah.properties` from the classpath to avoid conflicts during property resolution
- rm classes/justtestlah.properties
- echo "Writing justtestlah.properties"
# We base64 encode the run configuration (`justtestlah.properties`) into
# this template (see
# io.github.martinschneider.justtestlah.awsdevicefarm.TestSpecFactory).
# During the execution we decode it and write it back to a file which is
# then passed to the test execution. The alternative would be to put it
# into the test package but we don't want to re-upload this for every
# change of configuration.
- echo "I2p1c3R0ZXN0bGFoIHByb3BlcnRpZXMKI1N1biBNYXkgMDUgMDk6MTY6MTggU0dUIDIwMTkKZmVhdHVyZXMuZGlyZWN0b3J5PXNyYy90ZXN0L3Jlc291cmNlcy9mZWF0dXJlcy9zdGFja292ZXJmbG93CnBsYXRmb3JtPWFuZHJvaWQKb3BlbmN2Lm1vZGU9c2VydmVyCmN1Y3VtYmVyLnJlcG9ydC5kaXJlY3Rvcnk9dGFyZ2V0L3JlcG9ydC9jdWN1bWJlcgpwYWdlcy5wYWNrYWdlPWlvLmdpdGh1Yi5tYXJ0aW5zY2huZWlkZXIuanVzdHRlc3RsYWguZXhhbXBsZXMuc3RhY2tvdmVyZmxvdy5wYWdlcwp0YWdzPW5vdCBAb3BlbmN2CnN0ZXBzLnBhY2thZ2U9aW8uZ2l0aHViLm1hcnRpbnNjaG5laWRlci5qdXN0dGVzdGxhaC5leGFtcGxlcy5zdGFja292ZXJmbG93LnN0ZXBzCmFuZHJvaWQuYXBwQWN0aXZpdHk9Y29tLnN0YWNrZXhjaGFuZ2Uuc3RhY2tvdmVyZmxvdy5NYWluQWN0aXZpdHkKYW5kcm9pZC5hcHBQYWNrYWdlPWNvbS5zdGFja2V4Y2hhbmdlLnN0YWNrb3ZlcmZsb3cKbW9iaWxlLmFwcGl1bVVybD1odHRwXDovLzEyNy4wLjAuMVw6NDcyMy93ZC9odWIK" | base64 --decode > justtestlah.properties
# Set the path to the app package (we don't care about the platform, we
# just set both and ignore the other).
- echo "android.appPath=$DEVICEFARM_APP_PATH" >> justtestlah.properties
- echo "ios.appPath=$DEVICEFARM_APP_PATH" >> justtestlah.properties
# When executing the code on AWS `cloudprovider=local`
# Only when we trigger the tests on our machine we set
# `cloudprovider=aws`.
- echo "cloudprovider=local" >> justtestlah.properties
- cat justtestlah.properties
# Finally...
- echo "Executing test scenarios"
- java -Dappium.screenshots.dir=$DEVICEFARM_SCREENSHOT_PATH -Djusttestlah.properties=$(pwd)/justtestlah.properties -Dlogback.configurationFile=classes/logback-aws.xml -cp classes:dependency-jars/* org.junit.runner.JUnitCore TestRunner
post_test:
commands:
artifacts:
- $DEVICEFARM_LOG_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment