diff --git a/.husky/pre-commit b/.husky/pre-commit index 36af2198..3b608ae6 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,3 @@ #!/bin/sh -. "$(dirname "$0")/_/husky.sh" npx lint-staged diff --git a/examples/e2e/package.json b/examples/e2e/package.json index b9b83f88..8544eecd 100644 --- a/examples/e2e/package.json +++ b/examples/e2e/package.json @@ -11,7 +11,7 @@ "test": "tsc && yarn test:e2e" }, "dependencies": { - "@bam.tech/appium-helper": "^0.5.4", - "@perf-profiler/e2e": "^0.11.3" + "@bam.tech/appium-helper": "*", + "@perf-profiler/e2e": "*" } } diff --git a/packages/plugins/appium-helper/AppiumDriver.ts b/packages/plugins/appium-helper/AppiumDriver.ts index 4127bc49..89cdfd50 100644 --- a/packages/plugins/appium-helper/AppiumDriver.ts +++ b/packages/plugins/appium-helper/AppiumDriver.ts @@ -69,17 +69,17 @@ export class AppiumDriver { const capabilities = { platformName: "Android", "appium:automationName": "UiAutomator2", - appPackage, + "appium:appPackage": appPackage, // See https://github.com/appium/appium/blob/1e30207ec4e413c64396420fbb0388392e88cc54/docs/en/writing-running-appium/other/reset-strategies.md "appium:noReset": true, - autoLaunch: false, - appActivity, - newCommandTimeout: TEN_MINUTES, + "appium:autoLaunch": false, + "appium:appActivity": appActivity, + "appium:newCommandTimeout": TEN_MINUTES, ...clientCapabilities, }; const client = await webdriver.remote({ - path: "/wd/hub", + path: "/", port: 4723, logLevel: "warn", capabilities, diff --git a/packages/plugins/appium-helper/README.md b/packages/plugins/appium-helper/README.md index 277931db..1020bedc 100644 --- a/packages/plugins/appium-helper/README.md +++ b/packages/plugins/appium-helper/README.md @@ -35,8 +35,8 @@ import { AppiumDriver } from "@bam.tech/appium-helper"; test("e2e", async () => { const driver = await AppiumDriver.create({ // `npx @perf-profiler/profiler getCurrentApp` will display info for the current app - appPackage: com.example, - appActivity: com.example.MainActivity, + appPackage: "com.example", + appActivity: "com.example.MainActivity", }); driver.startApp(); @@ -44,7 +44,7 @@ test("e2e", async () => { }); ``` -3. Run the appium server `npx appium` in a terminal +3. Run the appium server `npx appium` in a terminal. If you just installed Appium, you may need to install a driver, e.g., by running `npx appium driver install uiautomator2`. 4. Run your test file in a separate terminal `yarn jest appium.test.ts` ### API diff --git a/packages/plugins/aws-device-farm/src/__tests__/__snapshots__/createTestSpecFile.ts.snap b/packages/plugins/aws-device-farm/src/__tests__/__snapshots__/createTestSpecFile.ts.snap index f59325c9..24055797 100644 --- a/packages/plugins/aws-device-farm/src/__tests__/__snapshots__/createTestSpecFile.ts.snap +++ b/packages/plugins/aws-device-farm/src/__tests__/__snapshots__/createTestSpecFile.ts.snap @@ -11,21 +11,17 @@ phases: - echo "Navigate to test package directory" - cd $DEVICEFARM_TEST_PACKAGE_PATH - npm install *.tgz - - export APPIUM_VERSION=1.22.2 - - 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 - npm install --global yarn pre_test: commands: - echo "Start appium server" + - npx appium@2.11.4 driver install uiautomator2 - >- - appium --log-timestamp --default-capabilities "{\\"deviceName\\": - \\"$DEVICEFARM_DEVICE_NAME\\", - \\"platformName\\":\\"$DEVICEFARM_DEVICE_PLATFORM_NAME\\",\\"app\\":\\"$DEVICEFARM_APP_PATH\\", - \\"udid\\":\\"$DEVICEFARM_DEVICE_UDID\\", - \\"platformVersion\\":\\"$DEVICEFARM_DEVICE_OS_VERSION\\",\\"chromedriverExecutable\\":\\"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE\\"}" + npx appium@2.11.4 --log-timestamp --default-capabilities + "{\\"appium:deviceName\\": \\"$DEVICEFARM_DEVICE_NAME\\", + \\"appium:platformName\\":\\"$DEVICEFARM_DEVICE_PLATFORM_NAME\\",\\"appium:app\\":\\"$DEVICEFARM_APP_PATH\\", + \\"appium:udid\\":\\"$DEVICEFARM_DEVICE_UDID\\", + \\"appium:platformVersion\\":\\"$DEVICEFARM_DEVICE_OS_VERSION\\",\\"appium:chromedriverExecutable\\":\\"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE\\"}" >> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 & - |- start_appium_timeout=0; @@ -36,10 +32,10 @@ phases: 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; + grep -i "Appium REST http interface listener started on http://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"; + echo "Appium REST http interface listener started on http://0.0.0.0:4723"; break; else echo "Waiting for appium server to start. Sleeping for 1 second"; @@ -72,20 +68,16 @@ phases: - echo "Navigate to test package directory" - cd $DEVICEFARM_TEST_PACKAGE_PATH - npm install *.tgz - - export APPIUM_VERSION=1.22.2 - - 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 pre_test: commands: - echo "Start appium server" + - npx appium@2.11.4 driver install uiautomator2 - >- - appium --log-timestamp --default-capabilities "{\\"deviceName\\": - \\"$DEVICEFARM_DEVICE_NAME\\", - \\"platformName\\":\\"$DEVICEFARM_DEVICE_PLATFORM_NAME\\",\\"app\\":\\"$DEVICEFARM_APP_PATH\\", - \\"udid\\":\\"$DEVICEFARM_DEVICE_UDID\\", - \\"platformVersion\\":\\"$DEVICEFARM_DEVICE_OS_VERSION\\",\\"chromedriverExecutable\\":\\"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE\\"}" + npx appium@2.11.4 --log-timestamp --default-capabilities + "{\\"appium:deviceName\\": \\"$DEVICEFARM_DEVICE_NAME\\", + \\"appium:platformName\\":\\"$DEVICEFARM_DEVICE_PLATFORM_NAME\\",\\"appium:app\\":\\"$DEVICEFARM_APP_PATH\\", + \\"appium:udid\\":\\"$DEVICEFARM_DEVICE_UDID\\", + \\"appium:platformVersion\\":\\"$DEVICEFARM_DEVICE_OS_VERSION\\",\\"appium:chromedriverExecutable\\":\\"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE\\"}" >> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 & - |- start_appium_timeout=0; @@ -96,10 +88,10 @@ phases: 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; + grep -i "Appium REST http interface listener started on http://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"; + echo "Appium REST http interface listener started on http://0.0.0.0:4723"; break; else echo "Waiting for appium server to start. Sleeping for 1 second"; diff --git a/packages/plugins/aws-device-farm/src/buildYmlSpec.ts b/packages/plugins/aws-device-farm/src/buildYmlSpec.ts index 8374c248..29a4800e 100644 --- a/packages/plugins/aws-device-farm/src/buildYmlSpec.ts +++ b/packages/plugins/aws-device-farm/src/buildYmlSpec.ts @@ -1,4 +1,7 @@ import yaml from "js-yaml"; + +const APPIUM_VERSION = "2.11.4"; + export const Commands = { INSTALL_NODE: ["devicefarm-cli use node 18", "node -v"], UNPACKAGE_TEST_PACKAGE: [ @@ -6,14 +9,10 @@ export const Commands = { "cd $DEVICEFARM_TEST_PACKAGE_PATH", "npm install *.tgz", ], - INSTALL_APPIUM: [ - "export APPIUM_VERSION=1.22.2", - "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", - ], START_APPIUM: [ 'echo "Start appium server"', - `appium --log-timestamp --default-capabilities "{\\"deviceName\\": \\"$DEVICEFARM_DEVICE_NAME\\", \\"platformName\\":\\"$DEVICEFARM_DEVICE_PLATFORM_NAME\\",\\"app\\":\\"$DEVICEFARM_APP_PATH\\", \\"udid\\":\\"$DEVICEFARM_DEVICE_UDID\\", \\"platformVersion\\":\\"$DEVICEFARM_DEVICE_OS_VERSION\\",\\"chromedriverExecutable\\":\\"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE\\"}" >> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &`, + `npx appium@${APPIUM_VERSION} driver install uiautomator2`, + `npx appium@${APPIUM_VERSION} --log-timestamp --default-capabilities "{\\"appium:deviceName\\": \\"$DEVICEFARM_DEVICE_NAME\\", \\"appium:platformName\\":\\"$DEVICEFARM_DEVICE_PLATFORM_NAME\\",\\"appium:app\\":\\"$DEVICEFARM_APP_PATH\\", \\"appium:udid\\":\\"$DEVICEFARM_DEVICE_UDID\\", \\"appium:platformVersion\\":\\"$DEVICEFARM_DEVICE_OS_VERSION\\",\\"appium:chromedriverExecutable\\":\\"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE\\"}" >> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &`, `start_appium_timeout=0; while [ true ]; do @@ -22,10 +21,10 @@ do 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; + grep -i "Appium REST http interface listener started on http://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"; + echo "Appium REST http interface listener started on http://0.0.0.0:4723"; break; else echo "Waiting for appium server to start. Sleeping for 1 second"; diff --git a/packages/plugins/aws-device-farm/src/createTestSpecFile.ts b/packages/plugins/aws-device-farm/src/createTestSpecFile.ts index b31c4ad5..ad5c914a 100644 --- a/packages/plugins/aws-device-farm/src/createTestSpecFile.ts +++ b/packages/plugins/aws-device-farm/src/createTestSpecFile.ts @@ -13,7 +13,6 @@ const buildAppiumYmlSpec = (commands: { installCommands: [ ...Commands.INSTALL_NODE, ...Commands.UNPACKAGE_TEST_PACKAGE, - ...Commands.INSTALL_APPIUM, ...(commands.installCommands || []), ], preTestCommands: [...Commands.START_APPIUM, ...(commands.preTestCommands || [])],