-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
530d528
commit c256614
Showing
5 changed files
with
196 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* eslint-disable require-await */ | ||
import {system, fs, doctor} from '@appium/support'; | ||
import {getAndroidBinaryPath, getSdkRootFromEnv} from 'appium-adb'; | ||
|
||
const ENVIRONMENT_VARS_TUTORIAL_URL = | ||
'https://github.com/appium/java-client/blob/master/docs/environment.md'; | ||
const ANDROID_SDK_LINK1 = 'https://developer.android.com/studio#cmdline-tools'; | ||
const ANDROID_SDK_LINK2 = 'https://developer.android.com/studio/intro/update#sdk-manager'; | ||
|
||
/** | ||
* @typedef EnvVarCheckOptions | ||
* @property {boolean} [expectDir] If set to true then | ||
* the path is expected to be a valid folder | ||
* @property {boolean} [expectFile] If set to true then | ||
* the path is expected to be a valid file | ||
*/ | ||
|
||
/** @satisfies {import('@appium/types').IDoctorCheck} */ | ||
class EnvVarAndPathCheck { | ||
/** | ||
* @param {string} varName | ||
* @param {EnvVarCheckOptions} [opts={}] | ||
*/ | ||
constructor(varName, opts = {}) { | ||
this.varName = varName; | ||
this.opts = opts; | ||
} | ||
|
||
async diagnose() { | ||
const varValue = process.env[this.varName]; | ||
if (!varValue) { | ||
return doctor.nokOptional(`${this.varName} environment variable is NOT set!`); | ||
} | ||
|
||
if (!(await fs.exists(varValue))) { | ||
let errMsg = `${this.varName} is set to '${varValue}' but this path does not exist!`; | ||
if (system.isWindows() && varValue.includes('%')) { | ||
errMsg += ` Consider replacing all references to other environment variables with absolute paths.`; | ||
} | ||
return doctor.nokOptional(errMsg); | ||
} | ||
|
||
const stat = await fs.stat(varValue); | ||
if (this.opts.expectDir && !stat.isDirectory()) { | ||
return doctor.nokOptional( | ||
`${this.varName} is expected to be a valid folder, got a file path instead`, | ||
); | ||
} | ||
if (this.opts.expectFile && stat.isDirectory()) { | ||
return doctor.nokOptional( | ||
`${this.varName} is expected to be a valid file, got a folder path instead`, | ||
); | ||
} | ||
|
||
return doctor.okOptional(`${this.varName} is set to: ${varValue}`); | ||
} | ||
|
||
async fix() { | ||
return ( | ||
`Make sure the environment variable ${this.varName} is properly configured for the Appium process. ` + | ||
`Android SDK is required if you want to run your tests on an Android device. ` + | ||
`Refer ${ENVIRONMENT_VARS_TUTORIAL_URL} for more details.` | ||
); | ||
} | ||
|
||
hasAutofix() { | ||
return false; | ||
} | ||
|
||
isOptional() { | ||
return true; | ||
} | ||
} | ||
export const androidHomeCheck = new EnvVarAndPathCheck('ANDROID_HOME', {expectDir: true}); | ||
|
||
/** @satisfies {import('@appium/types').IDoctorCheck} */ | ||
export class AndroidSdkCheck { | ||
/** @type {import('@appium/types').AppiumLogger} */ | ||
log; | ||
|
||
TOOL_NAMES = ['adb', 'emulator']; | ||
|
||
async diagnose() { | ||
const listOfTools = this.TOOL_NAMES.join(', '); | ||
const sdkRoot = getSdkRootFromEnv(); | ||
if (!sdkRoot) { | ||
return doctor.nokOptional(`${listOfTools} could not be found because ANDROID_HOME is NOT set!`); | ||
} | ||
|
||
this.log.info(` Checking ${listOfTools}`); | ||
const missingBinaries = []; | ||
for (const binary of this.TOOL_NAMES) { | ||
try { | ||
this.log.info(` '${binary}' exists in ${await getAndroidBinaryPath(binary)}`); | ||
} catch (e) { | ||
missingBinaries.push(binary); | ||
} | ||
} | ||
|
||
if (missingBinaries.length > 0) { | ||
return doctor.nokOptional(`${missingBinaries.join(', ')} could NOT be found in '${sdkRoot}'!`); | ||
} | ||
|
||
return doctor.okOptional(`${listOfTools} exist in '${sdkRoot}'`); | ||
} | ||
|
||
async fix() { | ||
return ( | ||
`Manually install Android SDK and set ANDROID_HOME enviornment variable. ` + | ||
`Android SDK is required if you want to run your tests on an Android device. ` + | ||
`Read ${[ANDROID_SDK_LINK1, ANDROID_SDK_LINK2].join(' and ')}.` | ||
); | ||
} | ||
|
||
hasAutofix() { | ||
return false; | ||
} | ||
|
||
isOptional() { | ||
return true; | ||
} | ||
} | ||
export const androidSdkCheck = new AndroidSdkCheck(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable require-await */ | ||
import {resolveExecutablePath} from './utils'; | ||
import {system, doctor} from '@appium/support'; | ||
|
||
const GD_DOWNLOAD_LINK = 'https://github.com/mozilla/geckodriver/releases'; | ||
const GD_BINARY = `geckodriver${system.isWindows() ? '.exe' : ''}`; | ||
|
||
/** @satisfies {import('@appium/types').IDoctorCheck} */ | ||
export class GeckodriverCheck { | ||
async diagnose() { | ||
const gdPath = await resolveExecutablePath(GD_BINARY); | ||
return gdPath | ||
? doctor.ok(`${GD_BINARY} is installed at: ${gdPath}`) | ||
: doctor.nok(`${GD_BINARY} cannot be found`); | ||
} | ||
|
||
async fix() { | ||
return ( | ||
`${GD_BINARY} is required to pass W3C commands to the remote browser. ` + | ||
`Please download the binary from ${GD_DOWNLOAD_LINK} and store it ` + | ||
`to any folder listed in the PATH environment variable. Folders that ` + | ||
`are currently present in PATH: ${process.env.PATH}` | ||
); | ||
} | ||
|
||
hasAutofix() { | ||
return false; | ||
} | ||
|
||
isOptional() { | ||
return false; | ||
} | ||
} | ||
export const geckodriverCheck = new GeckodriverCheck(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {fs} from '@appium/support'; | ||
|
||
/** | ||
* Return an executable path of cmd | ||
* | ||
* @param {string} cmd Standard output by command | ||
* @return {Promise<string?>} The full path of cmd. `null` if the cmd is not found. | ||
*/ | ||
export async function resolveExecutablePath(cmd) { | ||
try { | ||
const executablePath = await fs.which(cmd); | ||
if (executablePath && (await fs.exists(executablePath))) { | ||
return executablePath; | ||
} | ||
} catch (err) {} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters