Skip to content
Open
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
2 changes: 1 addition & 1 deletion detox/src/DetoxWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class DetoxWorker {
this._deviceConfig = deviceConfig;
this._sessionConfig = sessionConfig;
// @ts-ignore
this._sessionConfig.sessionId = sessionConfig.sessionId || uuid.UUID();
Copy link
Owner Author

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.

this._sessionConfig.sessionId = uuid.UUID();
this._runtimeErrorComposer.appsConfig = this._appsConfig;

this._client = new Client(sessionConfig);
Expand Down
76 changes: 76 additions & 0 deletions detox/src/artifacts/CloudArtifactsManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
class CloudArtifactsManager {
Copy link
Owner Author

Choose a reason for hiding this comment

The 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.
All the methods here are the callbacks for the events happening throughout the test cycle

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;
5 changes: 5 additions & 0 deletions detox/src/artifacts/factories/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-nocheck
const ArtifactsManager = require('../ArtifactsManager');
const CloudArtifactsManager = require('../CloudArtifactsManager');
const {
AndroidArtifactPluginsProvider,
IosArtifactPluginsProvider,
Expand Down Expand Up @@ -51,6 +52,10 @@ class Noop extends ArtifactsManagerFactory {
constructor() {
super(new EmptyProvider());
}
createArtifactsManager(artifactsConfig) {
const artifactsManager = new CloudArtifactsManager();
return artifactsManager;
}
}

module.exports = {
Expand Down
16 changes: 16 additions & 0 deletions detox/src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,22 @@ class Client {
await this.sendAction(new actions.DeliverPayload(params));
}

async waitForCloudPlatform(params) {
try {
const response = await this.sendAction(new actions.CloudPlatform(params));
if (params['method'] == 'terminateApp') {
await this.waitUntilDisconnected();
}
// else if (params['method'] == 'launchApp') {
// this._onAppConnected();
// }
return response;
} catch (err) {
this._successfulTestRun = false;
throw err;
}
}

async terminateApp() {
/* see the property injection from Detox.js */
}
Expand Down
23 changes: 22 additions & 1 deletion detox/src/client/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Login extends Action {
}

get timeout() {
return 1000;
return 240000;
Copy link
Owner Author

Choose a reason for hiding this comment

The 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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -336,4 +356,5 @@ module.exports = {
SetOrientation,
SetInstrumentsRecordingState,
CaptureViewHierarchy,
CloudPlatform
};
5 changes: 2 additions & 3 deletions detox/src/configuration/composeBehaviorConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function composeBehaviorConfig({
isCloudSession
}) {
if (isCloudSession) {
cliConfig.reuse = false;
cliConfig.cleanup = false;
cliConfig.reuse = true;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed default value for reuse to true and shutdownDevice to false for cloud sessions

logger.warn(`[BehaviorConfig] The 'Behaviour' config section is not supported for device type android.cloud and will be ignored.`);
}
return _.chain({})
Expand All @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion detox/src/configuration/composeDeviceConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ const EXPECTED_DEVICE_MATCHER_PROPS = {
'android.attached': ['adbName'],
'android.emulator': ['avdName'],
'android.genycloud': ['recipeUUID', 'recipeName'],
'android.cloud': ['name', 'os', 'osVersion']
'android.cloud': ['name', 'osVersion']
};

const KNOWN_TYPES = new Set(Object.keys(EXPECTED_DEVICE_MATCHER_PROPS));
Expand Down
6 changes: 3 additions & 3 deletions detox/src/configuration/composeSessionConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Copy link
Owner Author

@pb2323 pb2323 Mar 13, 2023

Choose a reason for hiding this comment

The 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');
}
}
Expand Down
1 change: 0 additions & 1 deletion detox/src/configuration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ async function composeDetoxConfig({
if (isCloudSession) {
const query_param = {
'device': _.get(deviceConfig, 'device.name'),
'os': _.get(deviceConfig, 'device.os'),
'osVersion': _.get(deviceConfig, 'device.osVersion'),
'name': _.get(sessionConfig, 'name'),
'project': _.get(sessionConfig, 'project'),
Expand Down
151 changes: 151 additions & 0 deletions detox/src/devices/runtime/drivers/android/cloud/cloudAndroidDriver.js
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;
6 changes: 3 additions & 3 deletions detox/src/devices/runtime/factories/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class Genycloud extends RuntimeDriverFactoryAndroid {
class Noop extends RuntimeDriverFactoryAndroid {
_createDriver(deviceCookie, deps, configs) {
const props = {
adbName: deviceCookie.adbName,
adbName: undefined,
};
const AndroidDriver = require('../drivers/android/AndroidDriver');
return new AndroidDriver(deps, props);
const CloudAndroidDriver = require('../drivers/android/cloud/cloudAndroidDriver');
return new CloudAndroidDriver(deps, props);
}
}

Expand Down
Loading