-
Notifications
You must be signed in to change notification settings - Fork 4
Implement cloud driver #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
f7c0c58
a6c4fe8
87f28fd
1aeccb8
bc9410d
f7a693d
f10ca60
dad3cac
02d3cb6
931ccc4
36ee9cd
4e635dc
0838833
7c319b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| class CloudArtifactsManager { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have created this ArtifactsManager class because artifacts are being managed by us and we don't want any logs related to artifacts management in our tester logs. |
||
| constructor() { | ||
| this._idlePromise = Promise.resolve(); | ||
| this._artifactPlugins = {}; | ||
| } | ||
|
|
||
| async onBootDevice(deviceInfo) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onBeforeLaunchApp(appLaunchInfo) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onLaunchApp(appLaunchInfo) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onAppReady(appInfo) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onBeforeTerminateApp(appInfo) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onTerminateApp(appInfo) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onBeforeUninstallApp(appInfo) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onBeforeShutdownDevice(deviceInfo) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onShutdownDevice(deviceInfo) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onCreateExternalArtifact({ pluginId, artifactName, artifactPath }) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onRunDescribeStart(suite) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onTestStart(testSummary) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onHookFailure(testSummary) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onTestFnFailure(testSummary) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onTestDone(testSummary) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onRunDescribeFinish(suite) { | ||
| return this._idlePromise; | ||
| } | ||
|
|
||
| async onBeforeCleanup() { | ||
| return this._idlePromise; | ||
| } | ||
| } | ||
|
|
||
| module.exports = CloudArtifactsManager; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ class Login extends Action { | |
| } | ||
|
|
||
| get timeout() { | ||
| return 1000; | ||
| return 240000; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This timeout is increased because in cloud sessions, we do device allocation/app installation, etc after receiving this message and then return the reponse to it. |
||
| } | ||
|
|
||
| async handle(response) { | ||
|
|
@@ -179,6 +179,26 @@ class Cleanup extends Action { | |
| } | ||
| } | ||
|
|
||
| class CloudPlatform extends Action { | ||
| constructor(params) { | ||
| super('CloudPlatform', params); | ||
| } | ||
|
|
||
| get isAtomic() { | ||
| return true; | ||
| } | ||
|
|
||
| get timeout() { | ||
| return 90000; | ||
| } | ||
|
|
||
| async handle(response) { | ||
| this.expectResponseOfType(response, 'CloudPlatform'); | ||
| return response; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| class Invoke extends Action { | ||
| constructor(params) { | ||
| super('invoke', params); | ||
|
|
@@ -336,4 +356,5 @@ module.exports = { | |
| SetOrientation, | ||
| SetInstrumentsRecordingState, | ||
| CaptureViewHierarchy, | ||
| CloudPlatform | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,7 @@ function composeBehaviorConfig({ | |
| isCloudSession | ||
| }) { | ||
| if (isCloudSession) { | ||
| cliConfig.reuse = false; | ||
| cliConfig.cleanup = false; | ||
| cliConfig.reuse = true; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed default value for reuse to |
||
| logger.warn(`[BehaviorConfig] The 'Behaviour' config section is not supported for device type android.cloud and will be ignored.`); | ||
| } | ||
| return _.chain({}) | ||
|
|
@@ -28,7 +27,7 @@ function composeBehaviorConfig({ | |
| reinstallApp: cliConfig.reuse ? false : undefined, | ||
| }, | ||
| cleanup: { | ||
| shutdownDevice: cliConfig.cleanup ? true : undefined | ||
| shutdownDevice: isCloudSession ? false : cliConfig.cleanup ? true : undefined | ||
| }, | ||
| launchApp: isCloudSession ? 'auto' : undefined | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,19 +51,19 @@ async function composeSessionConfig(options) { | |
| if (isCloudSession) { | ||
| if (session.build != null) { | ||
| const value = session.build; | ||
| if (typeof value !== 'string' || value.length === 0) { | ||
| if (typeof value !== 'string') { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can allow empty string for build/project/name options. |
||
| throw errorComposer.invalidCloudSessionProperty('build'); | ||
| } | ||
| } | ||
| if (session.project != null) { | ||
| const value = session.project; | ||
| if (typeof value !== 'string' || value.length === 0) { | ||
| if (typeof value !== 'string') { | ||
| throw errorComposer.invalidCloudSessionProperty('project'); | ||
| } | ||
| } | ||
| if (session.name != null) { | ||
| const value = session.name; | ||
| if (typeof value !== 'string' || value.length === 0) { | ||
| if (typeof value !== 'string') { | ||
| throw errorComposer.invalidCloudSessionProperty('name'); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| /* eslint @typescript-eslint/no-unused-vars: ["error", { "args": "none" }] */ | ||
| // @ts-nocheck | ||
| const _ = require('lodash'); | ||
|
|
||
| const DetoxApi = require('../../../../../android/espressoapi/Detox'); | ||
| const EspressoDetoxApi = require('../../../../../android/espressoapi/EspressoDetox'); | ||
| const UiDeviceProxy = require('../../../../../android/espressoapi/UiDeviceProxy'); | ||
| const logger = require('../../../../../utils/logger'); | ||
| const DeviceDriverBase = require('../../DeviceDriverBase'); | ||
|
|
||
| const log = logger.child({ cat: 'device' }); | ||
|
|
||
| /** | ||
| * @typedef { DeviceDriverDeps } CloudAndroidDriverDeps | ||
| * @property invocationManager { InvocationManager } | ||
| */ | ||
|
|
||
| class CloudAndroidDriver extends DeviceDriverBase { | ||
| /** | ||
| * @param deps { CloudAndroidDriverDeps } | ||
| * @param props { CloudAndroidDriverProps } | ||
| */ | ||
| constructor(deps) { | ||
| super(deps); | ||
|
|
||
| this.invocationManager = deps.invocationManager; | ||
| this.instrumentation = false; | ||
|
|
||
| this.uiDevice = new UiDeviceProxy(this.invocationManager).getUIDevice(); | ||
| } | ||
|
|
||
| async launchApp(bundleId, launchArgs, languageAndLocale) { | ||
| return await this._handleLaunchApp({ | ||
| manually: false, | ||
| bundleId, | ||
| launchArgs, | ||
| languageAndLocale, | ||
| }); | ||
| } | ||
|
|
||
| async _handleLaunchApp({ manually, bundleId, launchArgs }) { | ||
| const response = await this._launchApp( bundleId, launchArgs); | ||
| const pid = _.get(response, 'response.success'); | ||
| return pid; | ||
| } | ||
|
|
||
| async deliverPayload(params) { | ||
| if (params.delayPayload) { | ||
| return; | ||
| } | ||
|
|
||
| const { url } = params; | ||
| if (url) { | ||
| await this._startActivityWithUrl(url); | ||
| } | ||
| } | ||
|
|
||
| async waitUntilReady() { | ||
| try { | ||
| await super.waitUntilReady(); | ||
| } catch (e) { | ||
| log.warn({ error: e }, 'An error occurred while waiting for the app to become ready. Waiting for disconnection...'); | ||
| await this.client.waitUntilDisconnected(); | ||
| log.warn('The app disconnected.'); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| async pressBack() { | ||
| await this.uiDevice.pressBack(); | ||
| } | ||
|
|
||
| async sendToHome(params) { | ||
| await this.uiDevice.pressHome(); | ||
| } | ||
|
|
||
| async terminate(bundleId) { | ||
| return await this._terminateInstrumentation(); | ||
| } | ||
|
|
||
| async cleanup(bundleId) { | ||
| await super.cleanup(bundleId); | ||
| } | ||
|
|
||
| getPlatform() { | ||
| return 'android'; | ||
| } | ||
|
|
||
| getUiDevice() { | ||
| return this.uiDevice; | ||
| } | ||
|
|
||
| async enableSynchronization() { | ||
| await this.invocationManager.execute(EspressoDetoxApi.setSynchronization(true)); | ||
| } | ||
|
|
||
| async disableSynchronization() { | ||
| await this.invocationManager.execute(EspressoDetoxApi.setSynchronization(false)); | ||
| } | ||
|
|
||
| async takeScreenshot(screenshotName) { | ||
|
|
||
| return ''; | ||
| } | ||
|
|
||
| async setOrientation(orientation) { | ||
| const orientationMapping = { | ||
| landscape: 1, // top at left side landscape | ||
| portrait: 0 // non-reversed portrait. | ||
| }; | ||
|
|
||
| const call = EspressoDetoxApi.changeOrientation(orientationMapping[orientation]); | ||
| await this.invocationManager.execute(call); | ||
| } | ||
|
|
||
| async _launchApp( bundleId, launchArgs) { | ||
| if (!this.instrumentation) { | ||
| const response = await this.invocationManager.executeCloudPlatform({ | ||
| 'method': 'launchApp', | ||
| 'args': { | ||
| 'launchArgs': launchArgs | ||
| } | ||
| }); | ||
| const status = _.get(response, 'response.success'); | ||
| this.instrumentation = status && status.toString() == 'true'; | ||
| } else if (launchArgs.detoxURLOverride) { | ||
| await this._startActivityWithUrl(launchArgs.detoxURLOverride); | ||
| } else { | ||
| await this._resumeMainActivity(); | ||
| } | ||
| } | ||
|
|
||
| async _terminateInstrumentation(bundleId) { | ||
| const response = await this.invocationManager.executeCloudPlatform({ | ||
| 'method': 'terminateApp', | ||
| 'args': {} | ||
| }); | ||
| const status = _.get(response, 'response.success'); | ||
| this.instrumentation = !(status && status.toString() == 'true'); | ||
| } | ||
|
|
||
| _startActivityWithUrl(url) { | ||
| return this.invocationManager.execute(DetoxApi.startActivityFromUrl(url)); | ||
| } | ||
|
|
||
| _resumeMainActivity() { | ||
| return this.invocationManager.execute(DetoxApi.launchMainActivity()); | ||
| } | ||
| } | ||
|
|
||
| module.exports = CloudAndroidDriver; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When multiple test suites are present in a session, web socket connection is closed after the execution of each test suite, and a new web socket connection is created, thus web socket id changes, but session id remains constant for each test suite. Therefore, to ensure that the same device is used for all the test suites in a test, we want this unique identifier(session_id). Thus, we cannot let users define this.