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
108 changes: 108 additions & 0 deletions e2e/wdio/headless/mocking.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { browser } from '@wdio/globals'

describe('network mocking', () => {
afterEach(async () => {
await browser.mockRestoreAll()
})

it('marks a request as mocked even without overwrites', async () => {
const baseUrl = 'https://guinea-pig.webdriver.io/'
const mock = await browser.mock('https://cdn.jsdelivr.net/npm/hammerjs@1.1.3/hammer.min.js', {
Expand All @@ -13,4 +17,108 @@ describe('network mocking', () => {
timeout: 2000
})
})

it('should mock with wildcard (*) pattern', async () => {
const baseUrl = 'https://guinea-pig.webdriver.io/'
const mock = await browser.mock('https://cdn.jsdelivr.net/npm/jquery@3.6.0/*', {
method: 'get',
statusCode: 200,
})
await browser.url(baseUrl)
await browser.execute(() => {
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js'
document.body.appendChild(script)
})
await browser.waitUntil(() => mock.calls.length >= 1, {
timeoutMsg: 'Expected wildcard mock to be called',
timeout: 5000
})
})

it('should mock with double wildcard (**) pattern', async () => {
const mock = await browser.mock('https://cdn.jsdelivr.net/npm/vue@2.6.14/**', {
method: 'get',
statusCode: 200,
})
await browser.url('https://guinea-pig.webdriver.io/')
await browser.execute(() => {
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js'
document.body.appendChild(script)
})
await browser.waitUntil(() => mock.calls.length >= 1, {
timeoutMsg: 'Expected double wildcard mock to be called',
timeout: 5000
})
})

it('should mock with wildcard in middle of path', async () => {
const mock = await browser.mock('https://cdn.jsdelivr.net/npm/react@17.0.2/*/react.production.min.js', {
method: 'get',
statusCode: 200,
})
await browser.url('https://guinea-pig.webdriver.io/')
await browser.execute(() => {
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/npm/react@17.0.2/umd/react.production.min.js'
document.body.appendChild(script)
})
await browser.waitUntil(() => mock.calls.length >= 1, {
timeoutMsg: 'Expected middle wildcard mock to be called',
timeout: 5000
})
})

it('should mock with hostname wildcard', async () => {
const mock = await browser.mock('https://*.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js', {
method: 'get',
statusCode: 200,
})
await browser.url('https://guinea-pig.webdriver.io/')
await browser.execute(() => {
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js'
document.body.appendChild(script)
})
await browser.waitUntil(() => mock.calls.length >= 1, {
timeoutMsg: 'Expected hostname wildcard mock to be called',
timeout: 5000
})
})

it('should mock with file extension wildcard', async () => {
const mock = await browser.mock('https://cdn.jsdelivr.net/npm/moment@2.29.1/moment.min.*', {
method: 'get',
statusCode: 200,
})
await browser.url('https://guinea-pig.webdriver.io/')
await browser.execute(() => {
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/npm/moment@2.29.1/moment.min.js'
document.body.appendChild(script)
})
await browser.waitUntil(() => mock.calls.length >= 1, {
timeoutMsg: 'Expected extension wildcard mock to be called',
timeout: 5000
})
})

it('should mock with complex mixed wildcards', async () => {
// Matches https://cdn.jsdelivr.net/.../bootstrap.min.js
const mock = await browser.mock('https://*.jsdelivr.net/**/bootstrap.min.js', {
method: 'get',
statusCode: 200,
})
await browser.url('https://guinea-pig.webdriver.io/')
await browser.execute(() => {
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js'
document.body.appendChild(script)
})
await browser.waitUntil(() => mock.calls.length >= 1, {
timeoutMsg: 'Expected complex wildcard mock to be called',
timeout: 5000
})
})
})
4 changes: 3 additions & 1 deletion packages/wdio-appium-service/src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@
* start Appium
*/
const command = await this._getCommand(this._options.command)
this._process = await this._startAppium(command, this._appiumCliArgs)

const timeout = this._options.appiumStartTimeout ?? APPIUM_START_TIMEOUT
this._process = await this._startAppium(command, this._appiumCliArgs, timeout)

if (this._logPath) {
this._redirectLogStream(this._logPath)
Expand Down Expand Up @@ -237,7 +239,7 @@
* e.g. if the port is already in use, reject the promise.
*/
timeoutId = setTimeout(() => {
rejectOnce(new Error('Timeout: Appium did not start within expected time'))

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (windows-latest.22)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:588:17 ❯ processTimers node:internal/timers:523:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (windows-latest.22)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:588:17 ❯ processTimers node:internal/timers:523:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (windows-latest.22)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:588:17 ❯ processTimers node:internal/timers:523:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (ubuntu-latest.22)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:588:17 ❯ processTimers node:internal/timers:523:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (ubuntu-latest.22)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:588:17 ❯ processTimers node:internal/timers:523:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (ubuntu-latest.22)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:588:17 ❯ processTimers node:internal/timers:523:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (ubuntu-latest.20)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:581:17 ❯ processTimers node:internal/timers:519:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (ubuntu-latest.20)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:581:17 ❯ processTimers node:internal/timers:519:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (ubuntu-latest.20)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:581:17 ❯ processTimers node:internal/timers:519:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (macos-latest.24)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:605:17 ❯ processTimers node:internal/timers:541:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (macos-latest.24)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:605:17 ❯ processTimers node:internal/timers:541:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (macos-latest.24)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:605:17 ❯ processTimers node:internal/timers:541:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (macos-latest.20)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:581:17 ❯ processTimers node:internal/timers:519:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (macos-latest.20)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:581:17 ❯ processTimers node:internal/timers:519:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (macos-latest.20)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:581:17 ❯ processTimers node:internal/timers:519:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (windows-latest.20)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:581:17 ❯ processTimers node:internal/timers:519:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (windows-latest.20)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:581:17 ❯ processTimers node:internal/timers:519:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (windows-latest.20)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:581:17 ❯ processTimers node:internal/timers:519:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (windows-latest.24)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:605:17 ❯ processTimers node:internal/timers:541:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (windows-latest.24)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:605:17 ❯ processTimers node:internal/timers:541:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (windows-latest.24)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:605:17 ❯ processTimers node:internal/timers:541:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (ubuntu-latest.24)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:605:17 ❯ processTimers node:internal/timers:541:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (ubuntu-latest.24)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:605:17 ❯ processTimers node:internal/timers:541:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (ubuntu-latest.24)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:605:17 ❯ processTimers node:internal/timers:541:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (macos-latest.22)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:588:17 ❯ processTimers node:internal/timers:523:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (macos-latest.22)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:588:17 ❯ processTimers node:internal/timers:523:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 242 in packages/wdio-appium-service/src/launcher.ts

View workflow job for this annotation

GitHub Actions / Unit Tests / Unit Test (macos-latest.22)

Unhandled error

Error: Timeout: Appium did not start within expected time ❯ Timeout.<anonymous> packages/wdio-appium-service/src/launcher.ts:242:28 ❯ listOnTimeout node:internal/timers:588:17 ❯ processTimers node:internal/timers:523:7 This error originated in "packages/wdio-appium-service/tests/launcher.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect custom timeout from config". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
}, timeout)

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/wdio-appium-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ export interface AppiumServiceConfig {
* @default {}
*/
args?: AppiumServerArguments

/**
* Timeout in milliseconds for Appium to start successfully.
* @default 30000
*/
appiumStartTimeout?: number
}

export type ArgValue = string | number | boolean | null | object
Expand Down
51 changes: 51 additions & 0 deletions packages/wdio-appium-service/tests/launcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,45 @@ describe('Appium launcher', () => {
await launcher.onPrepare()
expect(launcher['_startAppium']).toHaveBeenCalledTimes(1)
})

test('should use custom appiumStartTimeout when provided', async () => {
const options = {
logPath: './',
command: 'test/path',
args: { address: 'bar' },
appiumStartTimeout: 60000
}
const capabilities = [{ 'appium:deviceName': 'baz' }] as WebdriverIO.Capabilities[]
const launcher = new AppiumLauncher(options, capabilities, {} as any)
const startAppiumSpy = vi.spyOn(launcher as any, '_startAppium')

await launcher.onPrepare()

expect(startAppiumSpy).toHaveBeenCalledWith(
'test/path',
expect.any(Array),
60000
)
})

test('should use default timeout when appiumStartTimeout is not provided', async () => {
const options = {
logPath: './',
command: 'test/path',
args: { address: 'bar' }
}
const capabilities = [{ 'appium:deviceName': 'baz' }] as WebdriverIO.Capabilities[]
const launcher = new AppiumLauncher(options, capabilities, {} as any)
const startAppiumSpy = vi.spyOn(launcher as any, '_startAppium')

await launcher.onPrepare()

expect(startAppiumSpy).toHaveBeenCalledWith(
'test/path',
expect.any(Array),
30000 // Default APPIUM_START_TIMEOUT
)
})
})

describe('onComplete', () => {
Expand Down Expand Up @@ -965,6 +1004,18 @@ describe('Appium launcher', () => {
expect(mockLogWarn).toHaveBeenCalled()
expect(mockLogError).not.toHaveBeenCalled()
})

test('should respect custom timeout from config', async () => {
const origSpawn = await vi.importActual<typeof cp>('node:child_process').then((m) => m.spawn)
vi.mocked(spawn).mockImplementationOnce(origSpawn)
const launcher = new AppiumLauncher({ appiumStartTimeout: 5000 }, [{ 'appium:deviceName': 'baz' }], {} as any)

await expect(launcher['_startAppium'](
'node',
['-e', '(() => { setTimeout(() => { console.log(JSON.stringify({message: \'Appium REST http interface listener started\'})); }, 3000); })()'],
5000
)).resolves.toEqual(expect.objectContaining({ spawnargs: expect.arrayContaining(['-e', expect.any(String)]) }))
})
})

afterEach(() => {
Expand Down
8 changes: 7 additions & 1 deletion packages/wdio-browserstack-service/src/crash-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ export default class CrashReporter {
})

if (response.ok) {
BStackLogger.debug(`[Crash_Report_Upload] Success response: ${JSON.stringify(await response.json())}`)
let body = await response.text()
try {
body = JSON.stringify(JSON.parse(body))
} catch {
// Response is not JSON, use text as-is
}
BStackLogger.debug(`[Crash_Report_Upload] Success response: ${body}`)
} else {
BStackLogger.error(`[Crash_Report_Upload] Failed due to ${response.body}`)
}
Expand Down
4 changes: 3 additions & 1 deletion packages/wdio-browserstack-service/src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export default class BrowserstackLauncherService implements Services.ServiceInst
this.browserStackConfig = BrowserStackConfig.getInstance(_options, _config)
BStackLogger.debug(`_options data: ${JSON.stringify(_options)}`)
BStackLogger.debug(`webdriver capabilities data: ${JSON.stringify(capabilities)}`)
BStackLogger.debug(`_config data: ${JSON.stringify(_config)}`)
const configCopy = JSON.parse(JSON.stringify(_config))
CrashReporter.recursivelyRedactKeysFromObject(configCopy, ['user', 'key', 'accesskey', 'password'])
BStackLogger.debug(`_config data: ${JSON.stringify(configCopy)}`)
if (Array.isArray(capabilities)) {
capabilities
.flatMap((c) => {
Expand Down
30 changes: 24 additions & 6 deletions packages/webdriverio/src/utils/interception/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class WebDriverInterception {
#calls: local.NetworkResponseCompletedParameters[] = []
#responseBodies = new Map<string, remote.NetworkBytesValue>()

constructor (
constructor(
pattern: URLPattern,
mockId: string,
filterOptions: MockFilterOptions,
Expand Down Expand Up @@ -92,7 +92,7 @@ export default class WebDriverInterception {
return new WebDriverInterception(pattern, interception.intercept, filterOptions, browser)
}

#emit (event: string, args: unknown) {
#emit(event: string, args: unknown) {
if (!this.#eventHandler.has(event)) {
return
}
Expand All @@ -103,7 +103,7 @@ export default class WebDriverInterception {
}
}

#addEventHandler (event: string, handler: Function) {
#addEventHandler(event: string, handler: Function) {
if (!this.#eventHandler.has(event)) {
this.#eventHandler.set(event, [])
}
Expand All @@ -119,6 +119,15 @@ export default class WebDriverInterception {
* - request is not matching the pattern, e.g. a different mock is responsible for this request
*/
if (!this.#isRequestMatching(request)) {
/**
* if request is not matching pattern but blocked by this mock (due to catch-all),
* we need to continue the request
*/
if (request.intercepts?.includes(this.#mockId)) {
return this.#browser.networkContinueRequest({
request: request.request.request
})
}
return
}

Expand Down Expand Up @@ -163,6 +172,15 @@ export default class WebDriverInterception {
* - request is not matching the pattern, e.g. a different mock is responsible for this request
*/
if (!this.#isRequestMatching(request)) {
/**
* if request is not matching pattern but blocked by this mock (due to catch-all),
* we need to continue the request
*/
if (request.intercepts?.includes(this.#mockId)) {
return this.#browser.networkProvideResponse({
request: request.request.request
}).catch(this.#handleNetworkProvideResponseError)
}
return
}

Expand Down Expand Up @@ -269,12 +287,12 @@ export default class WebDriverInterception {
return this.#responseBodies
}

#isRequestMatching<T extends local.NetworkBeforeRequestSentParameters | local.NetworkResponseCompletedParameters> (request: T) {
#isRequestMatching<T extends local.NetworkBeforeRequestSentParameters | local.NetworkResponseCompletedParameters>(request: T) {
const matches = this.#pattern && this.#pattern.test(request.request.url)
return request.isBlocked && matches
}

#matchesFilterOptions<T extends local.NetworkBeforeRequestSentParameters | local.NetworkResponseCompletedParameters> (request: T) {
#matchesFilterOptions<T extends local.NetworkBeforeRequestSentParameters | local.NetworkResponseCompletedParameters>(request: T) {
let isRequestMatching = true

if (isRequestMatching && this.#filterOptions.method) {
Expand Down Expand Up @@ -482,7 +500,7 @@ export default class WebDriverInterception {
}
}

waitForResponse ({
waitForResponse({
timeout = this.#browser.options.waitforTimeout,
interval = this.#browser.options.waitforInterval,
timeoutMsg,
Expand Down
9 changes: 5 additions & 4 deletions packages/webdriverio/src/utils/interception/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function parseOverwrite<
const statusCodeOverwrite = typeof overwrite.statusCode === 'function'
? overwrite.statusCode(request as local.NetworkResponseCompletedParameters)
: overwrite.statusCode
;(result as RespondWithOptions).statusCode = statusCodeOverwrite
; (result as RespondWithOptions).statusCode = statusCodeOverwrite
}

if ('method' in overwrite) {
Expand All @@ -77,14 +77,15 @@ export function parseOverwrite<
return result
}

export function getPatternParam (pattern: URLPattern, key: keyof Omit<remote.NetworkUrlPatternPattern, 'type'>) {
if (pattern[key] === '*') {
export function getPatternParam(pattern: URLPattern, key: keyof Omit<remote.NetworkUrlPatternPattern, 'type'>) {
const value = pattern[key]
if (value === '*' || value.includes('*')) {
return
}

if (key === 'port' && pattern.port === '') {
return pattern.protocol === 'https' ? '443' : '80'
}

return pattern[key].replaceAll('*', '\\*')
return value
}
Loading