Skip to content

Commit

Permalink
feat: Add doctor checks (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jan 6, 2024
1 parent cd59a62 commit bb153f4
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/functional-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
distribution: 'temurin'
java-version: '11'
- run: |
npm install -g appium@next
npm install -g appium
npm install --chromedriver_version="${{ matrix.chromedriverVersion }}"
npm install --no-save mjpeg-consumer
name: Install dev dependencies
Expand All @@ -72,6 +72,7 @@ jobs:
pushd "$cwd"
cd ~
appium driver install --source=local "$cwd"
appium driver doctor espresso
nohup appium server \
--port=$APPIUM_TEST_SERVER_PORT \
--address=$APPIUM_TEST_SERVER_HOST \
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ On top of standard Appium requirements Espresso driver also expects the followin
- Both the server package and the application under test must be signed with the same digital signature. Appium does sign them automatically upon session creation, so this could only be an issue if one wants to test an application, which is already installed on the device (using `noReset=true` capability).
- The package under test must not have mangled class names (e.g. [Proguard](https://developer.android.com/studio/build/shrink-code) must not be enabled for it)

### Doctor

Since driver version 2.31.0 you can automate the validation for the most of the above
requirements as well as various optional ones needed by driver extensions by running the
`appium driver doctor espresso` server command.


## Scripts

Expand Down
4 changes: 4 additions & 0 deletions lib/doctor/optional-checks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { doctor } from 'appium-android-driver';

export const optionalBundletoolCheck = doctor.optionalBundletoolCheck;
export const optionalFfmpegCheck = doctor.optionalFfmpegCheck;
51 changes: 51 additions & 0 deletions lib/doctor/required-checks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { doctor as doctorCommon } from 'appium-android-driver';
import { exec } from 'teen_process';
import { fs, system, doctor } from '@appium/support';
import path from 'node:path';

export const androidHomeCheck = doctorCommon.androidHomeCheck;
export const javaHomeCheck = doctorCommon.javaHomeCheck;
export const javaHomeValueCheck = doctorCommon.javaHomeValueCheck;
export const androidSdkCheck = doctorCommon.androidSdkCheck;

/** @satisfies {import('@appium/types').IDoctorCheck} */
export class JavaVersionCheck {
MIN_JAVA_VERSION = 11;
JAVA_VERSION_PATTERN = /^\s*java\.version\s*=\s*([\d.]+)/m;

async diagnose() {
const javaHome = process.env.JAVA_HOME;
const fullJavaPath = path.join(javaHome ?? '', 'bin', `java${system.isWindows() ? '.exe' : ''}`);
if (!javaHome || !await fs.exists(fullJavaPath)) {
return doctor.nok(`Cannot retrieve Java version. Is Java installed and JAVA_HOME set to a proper path?`);
}
let javaVerMatch;
try {
const {stderr} = await exec(fullJavaPath, ['-XshowSettings:properties', '-version']);
javaVerMatch = this.JAVA_VERSION_PATTERN.exec(stderr);
} catch (e) {
return doctor.nok(`Cannot retrieve Java version: ${e.stderr || e.message}`);
}
if (!javaVerMatch) {
return doctor.nok(`The actual Java version cannot be retrieved`);
}
const majorVer = parseInt(javaVerMatch[1], 10);
return majorVer < this.MIN_JAVA_VERSION
? doctor.nok(`The active Java version ${javaVerMatch[1]} is older than the required one`)
: doctor.ok(`The active Java version matches (${majorVer} >= ${this.MIN_JAVA_VERSION})`);
}

async fix() {
return `Upgrade to Java ${this.MIN_JAVA_VERSION}+ or update ` +
`the JAVA_HOME environment variable if it is already instsalled`;
}

hasAutofix() {
return false;
}

isOptional() {
return false;
}
}
export const javaVersionCheck = new JavaVersionCheck();
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
"scripts": {
"print-espresso-path": "./scripts/print-espresso-path.js",
"build-espresso": "./scripts/build-espresso.js"
},
"doctor": {
"checks": [
"./build/lib/doctor/required-checks.js",
"./build/lib/doctor/optional-checks.js"
]
}
},
"main": "./build/index.js",
Expand Down Expand Up @@ -72,7 +78,7 @@
],
"dependencies": {
"appium-adb": "^11.0.1",
"appium-android-driver": "^7.4.0",
"appium-android-driver": "^7.5.1",
"asyncbox": "^3.0.0",
"bluebird": "^3.5.0",
"lodash": "^4.17.11",
Expand Down Expand Up @@ -106,7 +112,7 @@
"precommit-lint"
],
"peerDependencies": {
"appium": "^2.0.0"
"appium": "^2.4.1"
},
"devDependencies": {
"@appium/eslint-config-appium": "^8.0.4",
Expand Down

0 comments on commit bb153f4

Please sign in to comment.