-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
22 changed files
with
1,299 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Workflows of the `connect` subcommand | ||
|
||
**Syntax** | ||
```sh | ||
npx @nightwatch/mobile-helper android connect FLAG [configs] | ||
``` | ||
|
||
### 1. Connect a real device wirelessly | ||
|
||
> Note: Only devices with Android version 11 or higher are supported. | ||
Run the below command to connect to a real device wirelessly: | ||
```sh | ||
npx @nightwatch/mobile-helper android connect --wireless | ||
``` |
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,32 @@ | ||
## Workflows of the `install` subcommand | ||
|
||
**Syntax** | ||
```sh | ||
npx @nightwatch/mobile-helper android install FLAG [configs] | ||
``` | ||
|
||
### 1. Install an APK | ||
|
||
Run the below command to install an APK on a real device or an AVD: | ||
|
||
```sh | ||
npx @nightwatch/mobile-helper android install --app | ||
|
||
# with configs | ||
npx @nightwatch/mobile-helper android install --app [--deviceId <device_id>] [--path <path_to_apk>] | ||
``` | ||
|
||
**Configs** | ||
|
||
| Config | Description | | ||
| ------------------------------ | -------------------------------------------------------------- | | ||
| --deviceId \| -s <device_id> | Id of the device to install the APK to | | ||
| --path \| -p <path_to_apk> | Path to the APK file relative to the current working directory | | ||
|
||
### 2. Create a new Android Virtual Device | ||
|
||
Run the below command to create a new AVD: | ||
|
||
```sh | ||
npx @nightwatch/mobile-helper android install --avd | ||
``` |
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,23 @@ | ||
## Workflows of the `list` subcommand | ||
|
||
**Syntax** | ||
|
||
```sh | ||
npx @nightwatch/mobile-helper android list [flags] | ||
``` | ||
|
||
### 1. Show a list of connected devices | ||
|
||
Run the below command to show a list of all the connected real devices and running AVDs: | ||
|
||
```sh | ||
npx @nightwatch/mobile-helper android list --device | ||
``` | ||
|
||
### 2. Show a list of installed AVDs | ||
|
||
Run the below command to show a list of all the currently installed AVDs | ||
|
||
```sh | ||
npx @nightwatch/mobile-helper android list --avd | ||
``` |
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,15 @@ | ||
## Workflows of the `uninstall` subcommand | ||
|
||
**Syntax** | ||
|
||
```sh | ||
npx @nightwatch/mobile-helper android uninstall FLAG [configs] | ||
``` | ||
|
||
### 1. Delete an Android Virtual Device (AVD) | ||
|
||
Run the below command to delete an AVD: | ||
|
||
```sh | ||
npx @nightwatch/mobile-helper android uninstall --avd | ||
``` |
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,96 @@ | ||
import colors from 'ansi-colors'; | ||
import {spawnSync} from 'child_process'; | ||
import * as dotenv from 'dotenv'; | ||
import path from 'path'; | ||
|
||
import {ANDROID_DOTCOMMANDS} from '../../constants'; | ||
import Logger from '../../logger'; | ||
import {getPlatformName} from '../../utils'; | ||
import {Platform, SdkBinary} from './interfaces'; | ||
import {checkJavaInstallation, getBinaryLocation, getBinaryNameForOS, getSdkRootFromEnv} from './utils/common'; | ||
|
||
export class AndroidDotCommand { | ||
dotcmd: string; | ||
args: string[]; | ||
sdkRoot: string; | ||
rootDir: string; | ||
platform: Platform; | ||
androidHomeInGlobalEnv: boolean; | ||
|
||
constructor(dotcmd: string, argv: string[], rootDir = process.cwd()) { | ||
this.dotcmd = dotcmd; | ||
this.args = argv.slice(1); | ||
this.sdkRoot = ''; | ||
this.rootDir = rootDir; | ||
this.platform = getPlatformName(); | ||
this.androidHomeInGlobalEnv = false; | ||
} | ||
|
||
async run(): Promise<boolean> { | ||
if (!ANDROID_DOTCOMMANDS.includes(this.dotcmd)) { | ||
Logger.log(colors.red(`Unknown dot command passed: ${this.dotcmd}\n`)); | ||
|
||
Logger.log('Run Android SDK command line tools using the following command:'); | ||
Logger.log(colors.cyan('npx @nightwatch/mobile-helper <DOTCMD> [options|args]\n')); | ||
|
||
Logger.log(`Available Dot Commands: ${colors.magenta(ANDROID_DOTCOMMANDS.join(', '))}`); | ||
Logger.log(`(Example command: ${colors.gray('npx @nightwatch/mobile-helper android.emulator @nightwatch-android-11')})\n`); | ||
|
||
return false; | ||
} | ||
|
||
const javaInstalled = checkJavaInstallation(this.rootDir); | ||
if (!javaInstalled) { | ||
return false; | ||
} | ||
|
||
this.loadEnvFromDotEnv(); | ||
|
||
const sdkRootEnv = getSdkRootFromEnv(this.rootDir, this.androidHomeInGlobalEnv); | ||
if (!sdkRootEnv) { | ||
Logger.log(`Run: ${colors.cyan('npx @nightwatch/mobile-helper android --standalone')} to fix this issue.`); | ||
Logger.log(`(Remove the ${colors.gray('--standalone')} flag from the above command if using the tool for testing.)\n`); | ||
|
||
return false; | ||
} | ||
this.sdkRoot = sdkRootEnv; | ||
|
||
return this.executeDotCommand(); | ||
} | ||
|
||
loadEnvFromDotEnv(): void { | ||
this.androidHomeInGlobalEnv = 'ANDROID_HOME' in process.env; | ||
dotenv.config({path: path.join(this.rootDir, '.env')}); | ||
} | ||
|
||
buildCommand(): string { | ||
const binaryName = this.dotcmd.split('.')[1] as SdkBinary; | ||
const binaryLocation = getBinaryLocation(this.sdkRoot, this.platform, binaryName, true); | ||
|
||
let cmd: string; | ||
if (binaryLocation === 'PATH') { | ||
const binaryFullName = getBinaryNameForOS(this.platform, binaryName); | ||
cmd = `${binaryFullName}`; | ||
} else { | ||
const binaryFullName = path.basename(binaryLocation); | ||
const binaryDirPath = path.dirname(binaryLocation); | ||
cmd = path.join(binaryDirPath, binaryFullName); | ||
} | ||
|
||
return cmd; | ||
} | ||
|
||
executeDotCommand(): boolean { | ||
const cmd = this.buildCommand(); | ||
const result = spawnSync(cmd, this.args, {stdio: 'inherit'}); | ||
|
||
if (result.error) { | ||
console.error(result.error); | ||
|
||
return false; | ||
} | ||
|
||
return result.status === 0; | ||
} | ||
} | ||
|
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
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
Oops, something went wrong.