Skip to content
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

Android multiapps - Detox rearchitecture #3456

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
627addd
[wip] Introduce TestApp and app-driver for Android (mostly)
d4vidi Jun 13, 2022
57defb4
[wip] Adjust matchers for Android
d4vidi Jun 15, 2022
2972df7
[wip] Adjust artifacts manager for Android
d4vidi Jun 15, 2022
594f5cf
[wip] Align Detox init and cleanup; raw sanity e2e works
d4vidi Jun 15, 2022
a13101a
[wip] Add missing app-ready event
d4vidi Jun 15, 2022
a745818
[wip] Fix numerous issues from e2e failures
d4vidi Jun 15, 2022
4edba3d
[wip] Fix launch-args thanks to e2e failures
d4vidi Jun 16, 2022
e830171
[wip] Fix element-screenshots API thanks to e2e failures
d4vidi Jun 16, 2022
53dabd9
[wip] Fix web API thanks for e2e failures; All suites are green (Andr…
d4vidi Jun 16, 2022
c2aaea3
Merge remote-tracking branch 'origin/master' into android-multiapps-oop
d4vidi Jun 16, 2022
d42a294
[wip] Add caching of package ID's (based on APK path)
d4vidi Jun 16, 2022
96d17c0
[wip] Get rid of driver.deliveryPayload() as a public method: Make it…
d4vidi Jun 16, 2022
18d41d2
[wip] iOS: Fix runtimeDevice-artifactsManager relationship issues
d4vidi Jun 16, 2022
5dee690
[wip] Introduce iOS device+app factory
d4vidi Jun 19, 2022
711d980
[wip] Align iOS matchers API with new architecture
d4vidi Jun 19, 2022
8a17742
[wip] Make sh*t work, sanity tests green
d4vidi Jun 19, 2022
129e6bb
[wip] Apply code reuse to launch(); Fix pid capturing
d4vidi Jun 19, 2022
28392e2
[wip] Push all platform-specific launchArgs mng to drivers layer => F…
d4vidi Jun 20, 2022
ce9c354
[wip] Fix url launching, improve payload delivery altogether
d4vidi Jun 20, 2022
e291b53
[wip] Fix captureViewHierarchy artifact
d4vidi Jun 20, 2022
36b0e28
[wip] Genymotion cloud
d4vidi Jun 20, 2022
47ed74f
[wip] Skip unit tests
d4vidi Jun 20, 2022
00a152c
[wip] Fix Detox cleanup problem
d4vidi Jun 20, 2022
837c452
Merge remote-tracking branch 'origin/master' into android-multiapps-oop
d4vidi Aug 4, 2022
54686ff
Fix location-set in genycloud
d4vidi Aug 4, 2022
7966f55
Align Android attached-device driver
d4vidi Oct 19, 2022
48d49b3
Merge remote-tracking branch 'origin/master' into android-multiapps-oop
d4vidi Oct 19, 2022
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
4 changes: 2 additions & 2 deletions detox/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ declare global {
/**
* Takes a screenshot of the element and schedules putting it in the artifacts folder upon completion of the current test.
* For more information, see {@link https://wix.github.io/Detox/docs/api/screenshots#element-level-screenshots}
* @param {string} name for the screenshot artifact
* @param [name] Name for the screenshot artifact
* @returns {Promise<string>} a temporary path to the screenshot.
* @example
* test('Menu items should have logout', async () => {
Expand All @@ -1227,7 +1227,7 @@ declare global {
* // * on failure, to: <artifacts-location>/✗ Menu items should have Logout/tap on menu.png
* });
*/
takeScreenshot(name: string): Promise<string>;
takeScreenshot(name?: string): Promise<string>;

/**
* Gets the native (OS-dependent) attributes of the element.
Expand Down
1 change: 1 addition & 0 deletions detox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"ini": "^1.3.4",
"lodash": "^4.17.5",
"minimist": "^1.2.0",
"p-iteration": "^1.1.8",
"proper-lockfile": "^3.0.2",
"resolve-from": "^5.0.0",
"sanitize-filename": "^1.6.1",
Expand Down
69 changes: 22 additions & 47 deletions detox/src/Detox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ const _ = require('lodash');

const lifecycleSymbols = require('../runners/integration').lifecycle;

const Client = require('./client/Client');
const DeviceAPI = require('./DeviceAPI');
const environmentFactory = require('./environmentFactory');
const { DetoxRuntimeErrorComposer } = require('./errors');
const { InvocationManager } = require('./invoke');
const DetoxServer = require('./server/DetoxServer');
const AsyncEmitter = require('./utils/AsyncEmitter');
const Deferred = require('./utils/Deferred');
const MissingDetox = require('./utils/MissingDetox');
const logger = require('./utils/logger');
const log = logger.child({ __filename });

const log = logger.child({ __filename });
const _initHandle = Symbol('_initHandle');
const _assertNoPendingInit = Symbol('_assertNoPendingInit');

Expand Down Expand Up @@ -96,25 +95,24 @@ class Detox {
this._artifactsManager = null;
}

if (this._client) {
this._client.dumpPendingRequests();
await this._client.cleanup();
this._client = null;
}

if (this.device) {
if (this._runtimeDevice) {
const shutdown = this._behaviorConfig.cleanup.shutdownDevice;
await this.device._cleanup();
await this._runtimeDevice.cleanup();
await this._deviceAllocator.free(this._deviceCookie, { shutdown });
}

if (this._eventEmitter) {
this._eventEmitter.off();
}

if (this._server) {
await this._server.close();
this._server = null;
}

this._deviceAllocator = null;
this._deviceCookie = null;
this._runtimeDevice = null;
this.device = null;
}

Expand Down Expand Up @@ -161,17 +159,6 @@ class Detox {
}
}

this._client = new Client(sessionConfig);
this._client.terminateApp = async () => {
if (this.device && this.device._isAppRunning()) {
await this.device.terminateApp();
}
};

await this._client.connect();

const invocationManager = new InvocationManager(this._client);

const {
envValidatorFactory,
deviceAllocatorFactory,
Expand All @@ -184,18 +171,15 @@ class Detox {
await envValidator.validate();

const commonDeps = {
invocationManager,
client: this._client,
eventEmitter: this._eventEmitter,
runtimeErrorComposer: this._runtimeErrorComposer,
errorComposer: this._runtimeErrorComposer,
};

this._artifactsManager = artifactsManagerFactory.createArtifactsManager(this._artifactsConfig, commonDeps);

this._deviceAllocator = deviceAllocatorFactory.createDeviceAllocator(commonDeps);
this._deviceCookie = await this._deviceAllocator.allocate(this._deviceConfig);

this.device = runtimeDeviceFactory.createRuntimeDevice(
const runtimeDevice = runtimeDeviceFactory.createRuntimeDevice(
this._deviceCookie,
commonDeps,
{
Expand All @@ -204,11 +188,14 @@ class Detox {
deviceConfig: this._deviceConfig,
sessionConfig,
});
await this.device._prepare();
await runtimeDevice.init();
await this._artifactsManager.onDeviceCreated(runtimeDevice);

this._runtimeDevice = runtimeDevice;
this.device = new DeviceAPI(runtimeDevice, this._runtimeErrorComposer);

const matchers = matchersFactory.createMatchers({
invocationManager,
runtimeDevice: this.device,
runtimeDevice,
eventEmitter: this._eventEmitter,
});
Object.assign(this, matchers);
Expand All @@ -220,9 +207,9 @@ class Detox {
});
}

await this.device.installUtilBinaries();
await runtimeDevice.installUtilBinaries();
if (behaviorConfig.reinstallApp) {
await this._reinstallAppsOnDevice();
await this._reinstallAppsOnDevice(runtimeDevice);
}

return this;
Expand All @@ -241,26 +228,14 @@ class Detox {
return handle.promise;
}

async _reinstallAppsOnDevice() {
const appNames = _(this._appsConfig)
async _reinstallAppsOnDevice(runtimeDevice) {
const appAliases = _(this._appsConfig)
.map((config, key) => [key, `${config.binaryPath}:${config.testBinaryPath}`])
.uniqBy(1)
.map(0)
.value();

for (const appName of appNames) {
await this.device.selectApp(appName);
await this.device.uninstallApp();
}

for (const appName of appNames) {
await this.device.selectApp(appName);
await this.device.installApp();
}

if (appNames.length !== 1) {
await this.device.selectApp(null);
}
await runtimeDevice.reinstallApps(appAliases);
}

_logTestRunCheckpoint(event, { status, fullName }) {
Expand Down
Loading