Skip to content

Commit

Permalink
Set remote session for Testrunner Options (#62)
Browse files Browse the repository at this point in the history
* Set remote session for Testrunner Options

Signed-off-by: Longfei Wang <longfeiw@amazon.de>

* Patch version update.

Signed-off-by: Longfei Wang <longfeiw@amazon.de>

---------

Signed-off-by: Longfei Wang <longfeiw@amazon.de>
  • Loading branch information
longfeiwAmazonDE authored Feb 9, 2024
1 parent 8398e0d commit 59e4077
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wdio-aws-device-farm-service",
"version": "8.0.5",
"version": "8.0.6",
"description": "AWS Device Farm support for WebdriverIO",
"keywords": [
"aws",
Expand Down Expand Up @@ -93,4 +93,4 @@
"lint-staged": {
"*.{json,ts,md}": "prettier --write"
}
}
}
12 changes: 10 additions & 2 deletions src/__tests__/launcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe("DeviceFarmLauncher", () => {
vi.resetAllMocks();
});

it("Updates capabilities with destination", async () => {
createTestGridUrlResponse.mockReturnValueOnce({
it("Updates capabilities & config with destination", async () => {
createTestGridUrlResponse.mockReturnValue({
url: "https://devicefarm.url/id",
});

Expand All @@ -41,6 +41,14 @@ describe("DeviceFarmLauncher", () => {
browserName: "chrome",
connectionRetryTimeout: 180000,
});

expect(config).toEqual({
protocol: "https",
hostname: "devicefarm.url",
path: "/id",
port: 443,
connectionRetryTimeout: 180000,
});
});

it("Throws ServereServiceError when create test grid url fails", () => {
Expand Down
16 changes: 10 additions & 6 deletions src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class DeviceFarmLauncher implements Services.ServiceInstance {
}

public async onPrepare(
_config: Options.Testrunner,
config: Options.Testrunner,
capabilities: Capabilities.RemoteCapabilities
): Promise<void> {
try {
Expand All @@ -35,28 +35,32 @@ export default class DeviceFarmLauncher implements Services.ServiceInstance {
}
if (Array.isArray(capabilities)) {
for (const cap of capabilities) {
await this.setCapabilitySession(cap);
await this.setRemoteSession(cap);
}
} else if (typeof capabilities === "object" && capabilities !== null) {
for (const cap of Object.values(capabilities)) {
await this.setCapabilitySession(cap);
await this.setRemoteSession(cap);
}
}
// Set remote session so that wdio can skip setting up drivers for cross-browser tests.
// See: https://github.com/webdriverio/webdriverio/blob/main/packages/wdio-utils/src/node/manager.ts#L63
await this.setRemoteSession(config);
}

private async setCapabilitySession(
capability:
private async setRemoteSession(
config:
| Capabilities.DesiredCapabilities
| Capabilities.W3CCapabilities
| Options.WebdriverIO
| Options.Testrunner
) {
const testGridUrlResult = await this.createSession();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const url = new URL(testGridUrlResult.url!);

this.logger?.info("Created device farm test grid:", testGridUrlResult);

Object.assign(capability, {
Object.assign(config, {
protocol: "https",
port: 443,
hostname: url.hostname,
Expand Down

0 comments on commit 59e4077

Please sign in to comment.