Skip to content

Instantly share code, notes, and snippets.

@cescoferraro
Last active September 17, 2020 08:04
Show Gist options
  • Save cescoferraro/2196382c88f6c0c50bd8f2f16cf4fb61 to your computer and use it in GitHub Desktop.
Save cescoferraro/2196382c88f6c0c50bd8f2f16cf4fb61 to your computer and use it in GitHub Desktop.
AWS FARM ios issue
import webdriverIO from "webdriverio";
import {dirname} from "path";
import {fileURLToPath} from "url";
import {loginLogoutFN, loginLogoutSingleFN, loginLogoutWithPassword} from "./tests/shared";
import {editPassword} from "./tests/password";
import {setSettings} from "./tests/settings";
import {editProfile} from "./tests/profile";
import {addRecipeToCookBook} from "./tests/recipe";
import {findAndShareRecipeFromCookBook} from "./tests/cookbook";
import {findAndRemoveRecipeFromCookBook} from "./tests/cookbook_share";
/*
Capabilities to place on Appium Inspector
{
"automationName": "XCUITest",
"platformName": "iOS",
"deviceName": "iPhone XR (13.7)",
"udid": "1E0EA359-50FD-4A6D-A542-48A3517AFC74",
"platformVersion": "13.7",
"app": "/Users/francescoantonelloferraro/go/src/github.com/tramontina/app/e2e/appium/App.app"
}
*/
const awsopts = {
path: '/wd/hub',
port: 4723,
capabilities: {
automationName: "XCUITest",
platformName: process.env.DEVICEFARM_DEVICE_PLATFORM_NAME,
deviceName: process.env.DEVICEFARM_DEVICE_NAME,
udid: process.env.DEVICEFARM_DEVICE_UDID,
app: process.env.DEVICEFARM_APP_PATH,
},
};
const opts = {
path: '/wd/hub',
port: 4723,
capabilities: {
automationName: "XCUITest",
platformName: "iOS",
deviceName: "iPhone XR (13.7)",
udid: "1E0EA359-50FD-4A6D-A542-48A3517AFC74",
app: (dirname(fileURLToPath(import.meta.url)) + "/App.app")
}
};
const ios = async () => {
try {
const platform= "ios";
const username = "[email protected]";
const password = "1234feijaonoprato";
const client = await webdriverIO.remote(process.env.ENV === "local" ? opts : awsopts);
await loginLogoutSingleFN(platform, client, username, password);
await loginLogoutWithPassword(platform, client, username, password, editPassword);
await loginLogoutFN(platform, client, username, password, setSettings);
await loginLogoutFN(platform, client, username, password, editProfile);
} catch (e){
console.log(e);
throw e;
}
};
void ios();
version: 0.1
# Phases are collection of commands that get executed on Device Farm.
phases:
# The install phase includes commands that install dependencies that your tests use.
# Default dependencies for testing frameworks supported on Device Farm are already installed.
install:
commands:
# This test execution environment uses Appium version 1.7.2 by default, however we enable you to change it using the Appium version manager (avm)
# An example "avm" command below changes the version to 1.14.2
# For your convenience, we have preinstalled the following versions: 1.9.1, 1.10.1, 1.11.1, 1.12.1, 1.13.0, 1.14.1, 1.14.2, 1.15.1, 1.16.0, and 1.17.1
# For iOS devices on OS version 13.4 and above, please use Appium version 1.17.1 for the best possible experience
# Additionally, for iOS devices on OS version 13.0 through 13.3, please use Appium version 1.16.0 or higher
# To use one of these Appium versions, change the version number in the "avm" command below to your desired version:
- export APPIUM_VERSION=1.17.1
- avm $APPIUM_VERSION
- ln -s /usr/local/avm/versions/$APPIUM_VERSION/node_modules/.bin/appium /usr/local/avm/versions/$APPIUM_VERSION/node_modules/appium/bin/appium.js
# Device farm provides 4 different pre-built versions of WebDriverAgent, and each is suggested for different versions of Appium:
# DEVICEFARM_WDA_DERIVED_DATA_PATH_V4: this version is suggested for Appium 1.17.1. V4 is built from the following source code: https://github.com/appium/WebDriverAgent/releases/tag/v2.14.1
# DEVICEFARM_WDA_DERIVED_DATA_PATH_V3: this version is suggested for Appium 1.16.0. V3 is built from the following source code: https://github.com/appium/WebDriverAgent/releases/tag/v2.3.2
# DEVICEFARM_WDA_DERIVED_DATA_PATH_V2: this version is suggested for Appium 1.15.1. V2 is built from the following source code: https://github.com/appium/WebDriverAgent/tree/v1.3.5
# DEVICEFARM_WDA_DERIVED_DATA_PATH_V1: this version is suggested for Appium 1.9.1 through 1.14.2. V1 is built from the following source code: https://github.com/appium/WebDriverAgent/tree/2dbbf917ec2e4707bae9260f701d43c82b55e1b9
# We will automatically configure your WebDriverAgent version based on your Appium version using the following code.
# For users of Appium versions 1.15.0 and higher, your Appium version requires that your UDID of the device not contain any "-" characters
# So, we will create a new environment variable of your UDID specifically for Appium based on your Appium version
- >-
if [ $(echo $APPIUM_VERSION | cut -d "." -f2) -ge 17 ];
then
DEVICEFARM_DEVICE_UDID_FOR_APPIUM=$(echo $DEVICEFARM_DEVICE_UDID | tr -d "-");
DEVICEFARM_WDA_DERIVED_DATA_PATH=$DEVICEFARM_WDA_DERIVED_DATA_PATH_V4;
elif [ $(echo $APPIUM_VERSION | cut -d "." -f2) -ge 16 ];
then
DEVICEFARM_DEVICE_UDID_FOR_APPIUM=$(echo $DEVICEFARM_DEVICE_UDID | tr -d "-");
DEVICEFARM_WDA_DERIVED_DATA_PATH=$DEVICEFARM_WDA_DERIVED_DATA_PATH_V3;
elif [ $(echo $APPIUM_VERSION | cut -d "." -f2) -ge 15 ];
then
DEVICEFARM_DEVICE_UDID_FOR_APPIUM=$(echo $DEVICEFARM_DEVICE_UDID | tr -d "-");
DEVICEFARM_WDA_DERIVED_DATA_PATH=$DEVICEFARM_WDA_DERIVED_DATA_PATH_V2;
else
DEVICEFARM_DEVICE_UDID_FOR_APPIUM=$DEVICEFARM_DEVICE_UDID;
DEVICEFARM_WDA_DERIVED_DATA_PATH=$DEVICEFARM_WDA_DERIVED_DATA_PATH_V1;
fi
# By default the node version installed is 10.9.0
# you can switch to an alternate node version using below command.
- nvm install 14.9.0
# Unpackage and install the node modules that you uploaded in the test phase.
- echo "Navigate to test package directory"
- cd $DEVICEFARM_TEST_PACKAGE_PATH
- npm install *.tgz
# The pre-test phase includes commands that setup your test environment.
pre_test:
commands:
# We recommend starting appium server process in the background using the command below.
# Appium server log will go to $DEVICEFARM_LOG_DIR directory.
# The environment variables below will be auto-populated during run time.
- echo "Start appium server"
- >-
appium --log-timestamp
--default-capabilities "{\"usePrebuiltWDA\": true, \"derivedDataPath\":\"$DEVICEFARM_WDA_DERIVED_DATA_PATH\",
\"deviceName\": \"$DEVICEFARM_DEVICE_NAME\", \"platformName\":\"$DEVICEFARM_DEVICE_PLATFORM_NAME\", \"app\":\"$DEVICEFARM_APP_PATH\",
\"automationName\":\"XCUITest\", \"udid\":\"$DEVICEFARM_DEVICE_UDID_FOR_APPIUM\", \"platformVersion\":\"$DEVICEFARM_DEVICE_OS_VERSION\"}"
>> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &
- >-
start_appium_timeout=0;
while [ true ];
do
if [ $start_appium_timeout -gt 60 ];
then
echo "appium server never started in 60 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;
# The test phase includes commands that start your test suite execution.
test:
commands:
# Your test package is downloaded in $DEVICEFARM_TEST_PACKAGE_PATH
# However, we must navigate to its subdirectory "node_modules/*", as this directory has your test code and dependency node modules
- echo "Navigate to test code directory"
- cd $DEVICEFARM_TEST_PACKAGE_PATH/node_modules/*
- echo "Start Appium Node test"
# Enter the command below to start the tests . The comamnd should be similar to what you use to run the tests locally.
# For e.g. assuming you run your tests locally using command "node YOUR_TEST_FILENAME.js.", enter the same command below:
- npm run ios
# The post test phase includes commands that are run after your tests are executed.
post_test:
commands:
# The artifacts phase lets you specify the location where your tests logs, device logs will be stored.
# And also let you specify the location of your test logs and artifacts which you want to be collected by Device Farm.
# These logs and artifacts will be available through ListArtifacts API in Device Farm.
artifacts:
# By default, Device Farm will collect your artifacts from following directories
- $DEVICEFARM_LOG_DIR
{
"name": "tramontina-app-tester",
"version": "0.0.13",
"description": "",
"type": "module",
"main": "android.mjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"android": "node --experimental-modules --es-module-specifier-resolution=node android.mjs",
"ios": "node --experimental-modules --es-module-specifier-resolution=node ios.mjs",
"clean": "rm -rf *.zip && rm -rf *.tgz",
"bundle": "npm run clean && npm-bundle && zip -r bundle-$npm_package_version.zip *.tgz && rm -rf *.tgz"
},
"author": "",
"license": "ISC",
"dependencies": {
"@wdio/cli": "6.4.0",
"webdriverio": "6.4.0"
},
"bundledDependencies": [
"@wdio/cli",
"webdriverio"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment