Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(appium): update client and CI to appium v2 #318

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
4 changes: 2 additions & 2 deletions examples/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
}
}
10 changes: 5 additions & 5 deletions packages/plugins/appium-helper/AppiumDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/appium-helper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ 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();
await driver.findElementByText("Welcome");
});
```

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand Down
15 changes: 7 additions & 8 deletions packages/plugins/aws-device-farm/src/buildYmlSpec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
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: [
'echo "Navigate to test package directory"',
"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
Expand All @@ -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";
Expand Down
1 change: 0 additions & 1 deletion packages/plugins/aws-device-farm/src/createTestSpecFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [])],
Expand Down