Skip to content

Commit 74b3b21

Browse files
committed
fix: add timeouts
1 parent d1beac1 commit 74b3b21

File tree

11 files changed

+205
-93
lines changed

11 files changed

+205
-93
lines changed

.github/workflows/appium_Android.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ env:
1515
jobs:
1616
appium:
1717
runs-on: ubuntu-22.04
18+
timeout-minutes: 30
1819

1920
strategy:
2021
matrix:
@@ -41,4 +42,5 @@ jobs:
4142
--form 'payload=@test/data/mobile/selendroid-test-app-0.17.0.apk' \
4243
--form 'name="selendroid-test-app-0.17.0.apk"'
4344
44-
- run: 'npm run test:appium-${{ matrix.test-suite }}'
45+
- run: 'timeout 900 bash -c "npm run test:appium-${{ matrix.test-suite }}"'
46+
timeout-minutes: 20

.github/workflows/appium_iOS.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
appium:
1717
if: false
1818
runs-on: ubuntu-22.04
19+
timeout-minutes: 30
1920

2021
strategy:
2122
matrix:
@@ -40,4 +41,5 @@ jobs:
4041
--form 'payload=@test/data/mobile/TestApp-iphonesimulator.zip' \
4142
--form 'name="TestApp-iphonesimulator.zip"'
4243
43-
- run: 'npm run test:ios:appium-${{ matrix.test-suite }}'
44+
- run: 'timeout 900 bash -c "npm run test:ios:appium-${{ matrix.test-suite }}"'
45+
timeout-minutes: 20

.github/workflows/playwright.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env:
1616
jobs:
1717
build:
1818
runs-on: ubuntu-latest
19+
timeout-minutes: 30
1920

2021
strategy:
2122
matrix:
@@ -42,19 +43,26 @@ jobs:
4243
run: npx playwright install && npx playwright install-deps
4344
- name: check
4445
run: './bin/codecept.js check -c test/acceptance/codecept.Playwright.js'
46+
timeout-minutes: 2
4547
- name: start a server
4648
run: 'php -S 127.0.0.1:8000 -t test/data/app &'
4749
- name: run chromium tests
48-
run: 'BROWSER=chromium ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
50+
run: 'timeout 600 bash -c "unset BROWSER && BROWSER=chromium ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"'
51+
timeout-minutes: 12
4952
- name: run chromium with restart==browser tests
50-
run: 'BROWSER_RESTART=browser ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
53+
run: 'timeout 600 bash -c "unset BROWSER && BROWSER_RESTART=browser ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"'
54+
timeout-minutes: 12
5155
- name: run chromium with restart==session tests
52-
run: 'BROWSER_RESTART=session ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
56+
run: 'timeout 600 bash -c "unset BROWSER && BROWSER_RESTART=session ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"'
57+
timeout-minutes: 12
5358
- name: run firefox tests
54-
run: 'BROWSER=firefox node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
59+
run: 'timeout 600 bash -c "unset BROWSER && BROWSER=firefox node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"'
60+
timeout-minutes: 12
5561
- name: run webkit tests
56-
run: 'BROWSER=webkit node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
62+
run: 'timeout 600 bash -c "unset BROWSER && BROWSER=webkit node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"'
63+
timeout-minutes: 12
5764
- name: run chromium unit tests
5865
run: ./node_modules/.bin/mocha test/helper/Playwright_test.js --timeout 5000 --reporter @testomatio/reporter/mocha
66+
timeout-minutes: 5
5967
env:
6068
GH_PAT: ${{ github.token }}

.github/workflows/puppeteer.yml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,36 @@ env:
1515

1616
jobs:
1717
build:
18-
1918
runs-on: ubuntu-22.04
19+
timeout-minutes: 25
2020

2121
strategy:
2222
matrix:
2323
node-version: [20.x]
2424

2525
steps:
26-
- uses: actions/checkout@v4
27-
- name: Use Node.js ${{ matrix.node-version }}
28-
uses: actions/setup-node@v4
29-
with:
30-
node-version: ${{ matrix.node-version }}
31-
- uses: shivammathur/setup-php@v2
32-
with:
33-
php-version: 7.4
34-
- name: npm install
35-
run: |
36-
npm i --force && npm i puppeteer --force
37-
env:
38-
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
39-
- name: start a server
40-
run: "php -S 127.0.0.1:8000 -t test/data/app &"
41-
- uses: browser-actions/setup-chrome@v1
42-
- run: chrome --version
43-
- name: run tests
44-
run: "./bin/codecept.js run-workers 2 -c test/acceptance/codecept.Puppeteer.js --grep @Puppeteer --debug"
45-
- name: run unit tests
46-
run: ./node_modules/.bin/mocha test/helper/Puppeteer_test.js --reporter @testomatio/reporter/mocha
47-
env:
48-
GH_PAT: ${{ github.token }}
26+
- uses: actions/checkout@v4
27+
- name: Use Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
- uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: 7.4
34+
- name: npm install
35+
run: |
36+
npm i --force && npm i puppeteer --force
37+
env:
38+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
39+
- name: start a server
40+
run: 'php -S 127.0.0.1:8000 -t test/data/app &'
41+
- uses: browser-actions/setup-chrome@v1
42+
- run: chrome --version
43+
- name: run tests
44+
run: 'timeout 600 bash -c "./bin/codecept.js run-workers 2 -c test/acceptance/codecept.Puppeteer.js --grep @Puppeteer --debug"'
45+
timeout-minutes: 12
46+
- name: run unit tests
47+
run: ./node_modules/.bin/mocha test/helper/Puppeteer_test.js --reporter @testomatio/reporter/mocha
48+
timeout-minutes: 5
49+
env:
50+
GH_PAT: ${{ github.token }}

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
unit-tests:
1313
name: Unit tests
1414
runs-on: ubuntu-22.04
15+
timeout-minutes: 15
1516

1617
strategy:
1718
matrix:
@@ -28,12 +29,14 @@ jobs:
2829
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
2930
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
3031
- run: npm run test:unit
32+
timeout-minutes: 10
3133
env:
3234
GH_PAT: ${{ github.token }}
3335

3436
runner-tests:
3537
name: Runner tests
3638
runs-on: ubuntu-22.04
39+
timeout-minutes: 15
3740

3841
strategy:
3942
matrix:
@@ -50,5 +53,6 @@ jobs:
5053
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
5154
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
5255
- run: npm run test:runner
56+
timeout-minutes: 10
5357
env:
5458
GH_PAT: ${{ github.token }}

.github/workflows/testcafe.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ env:
1313
# Force terminal colors. @see https://www.npmjs.com/package/colors
1414
FORCE_COLOR: 1
1515

16-
1716
jobs:
1817
build:
19-
2018
runs-on: ubuntu-22.04
19+
timeout-minutes: 20
2120

2221
strategy:
2322
matrix:
2423
node-version: [20.x]
2524

2625
steps:
27-
- uses: actions/checkout@v4
28-
- name: Use Node.js ${{ matrix.node-version }}
29-
uses: actions/setup-node@v4
30-
with:
31-
node-version: ${{ matrix.node-version }}
32-
- uses: shivammathur/setup-php@v2
33-
with:
34-
php-version: 7.4
35-
- name: npm install
36-
run: |
37-
npm i --force
38-
env:
39-
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
40-
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
41-
- name: start a server
42-
run: "php -S 127.0.0.1:8000 -t test/data/app &"
43-
- name: run unit tests
44-
run: xvfb-run --server-args="-screen 0 1280x720x24" ./node_modules/.bin/mocha test/helper/TestCafe_test.js --reporter @testomatio/reporter/mocha
45-
env:
46-
GH_PAT: ${{ github.token }}
26+
- uses: actions/checkout@v4
27+
- name: Use Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
- uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: 7.4
34+
- name: npm install
35+
run: |
36+
npm i --force
37+
env:
38+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
39+
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
40+
- name: start a server
41+
run: 'php -S 127.0.0.1:8000 -t test/data/app &'
42+
- name: run unit tests
43+
run: xvfb-run --server-args="-screen 0 1280x720x24" ./node_modules/.bin/mocha test/helper/TestCafe_test.js --reporter @testomatio/reporter/mocha
44+
timeout-minutes: 10
45+
env:
46+
GH_PAT: ${{ github.token }}

.github/workflows/webdriver.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env:
1616
jobs:
1717
build:
1818
runs-on: ubuntu-latest
19+
timeout-minutes: 25
1920
strategy:
2021
matrix:
2122
node-version: [20.x]
@@ -40,9 +41,12 @@ jobs:
4041
run: 'php -S 127.0.0.1:8000 -t test/data/app &'
4142
- name: check
4243
run: './bin/codecept.js check -c test/acceptance/codecept.WebDriver.js'
44+
timeout-minutes: 2
4345
- name: run unit tests
4446
run: ./node_modules/.bin/mocha test/helper/WebDriver_test.js --exit --reporter @testomatio/reporter/mocha
47+
timeout-minutes: 5
4548
env:
4649
GH_PAT: ${{ github.token }}
4750
- name: run tests
48-
run: './bin/codecept.js run -c test/acceptance/codecept.WebDriver.js --grep @WebDriver --debug'
51+
run: 'timeout 600 bash -c "./bin/codecept.js run -c test/acceptance/codecept.WebDriver.js --grep @WebDriver --debug"'
52+
timeout-minutes: 12

lib/helper/Playwright.js

Lines changed: 89 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,24 @@ class Playwright extends Helper {
691691
} else {
692692
this.activeSessionName = session
693693
}
694-
const existingPages = await this.browserContext.pages()
695-
await this._setPage(existingPages[0])
694+
695+
// Safety check: ensure browserContext exists before calling pages()
696+
if (!this.browserContext) {
697+
this.debug('Cannot restore session vars: browserContext is undefined')
698+
return
699+
}
700+
701+
try {
702+
const existingPages = await this.browserContext.pages()
703+
if (existingPages && existingPages.length > 0) {
704+
await this._setPage(existingPages[0])
705+
} else {
706+
this.debug('Cannot restore session vars: no pages available')
707+
}
708+
} catch (err) {
709+
this.debug(`Failed to restore session vars: ${err.message}`)
710+
return
711+
}
696712

697713
return this._waitForAction()
698714
},
@@ -980,6 +996,36 @@ class Playwright extends Helper {
980996
}
981997
}
982998

999+
// Ensure browser is initialized before page operations
1000+
if (!this.page) {
1001+
this.debugSection('Auto-initializing', `Browser not started properly. page=${!!this.page}, isRunning=${this.isRunning}, browser=${!!this.browser}, browserContext=${!!this.browserContext}`)
1002+
1003+
if (!this.browser) {
1004+
await this._startBrowser()
1005+
}
1006+
1007+
// Create browser context and page (simplified version of _before logic)
1008+
if (!this.browserContext) {
1009+
const contextOptions = {
1010+
ignoreHTTPSErrors: this.options.ignoreHTTPSErrors,
1011+
acceptDownloads: true,
1012+
...this.options.emulate,
1013+
}
1014+
this.browserContext = await this.browser.newContext(contextOptions)
1015+
}
1016+
1017+
const pages = await this.browserContext.pages()
1018+
const mainPage = pages[0] || (await this.browserContext.newPage())
1019+
await this._setPage(mainPage)
1020+
1021+
this.debugSection('Auto-initializing', `Completed. page=${!!this.page}, browserContext=${!!this.browserContext}`)
1022+
}
1023+
1024+
// Additional safety check
1025+
if (!this.page) {
1026+
throw new Error(`Page is not initialized after auto-initialization. this.page=${this.page}, this.isRunning=${this.isRunning}, this.browser=${!!this.browser}, this.browserContext=${!!this.browserContext}`)
1027+
}
1028+
9831029
await this.page.goto(url, { waitUntil: this.options.waitForNavigation })
9841030

9851031
const performanceTiming = JSON.parse(await this.page.evaluate(() => JSON.stringify(window.performance.timing)))
@@ -2305,11 +2351,16 @@ class Playwright extends Helper {
23052351
async saveElementScreenshot(locator, fileName) {
23062352
const outputFile = screenshotOutputFolder(fileName)
23072353

2308-
const res = await this._locateElement(locator)
2309-
assertElementExists(res, locator)
2310-
const elem = res
2311-
this.debug(`Screenshot of ${new Locator(locator)} element has been saved to ${outputFile}`)
2312-
return elem.screenshot({ path: outputFile, type: 'png' })
2354+
try {
2355+
const res = await this._locateElement(locator)
2356+
assertElementExists(res, locator)
2357+
const elem = res
2358+
this.debug(`Screenshot of ${new Locator(locator)} element has been saved to ${outputFile}`)
2359+
return elem.screenshot({ path: outputFile, type: 'png' })
2360+
} catch (err) {
2361+
this.debug(`Failed to take element screenshot: ${err.message}`)
2362+
throw err
2363+
}
23132364
}
23142365

23152366
/**
@@ -2321,25 +2372,43 @@ class Playwright extends Helper {
23212372

23222373
this.debugSection('Screenshot', relativeDir(outputFile))
23232374

2324-
await this.page.screenshot({
2325-
path: outputFile,
2326-
fullPage: fullPageOption,
2327-
type: 'png',
2328-
})
2375+
if (!this.page) {
2376+
this.debug('Cannot take screenshot: page object is undefined')
2377+
return
2378+
}
23292379

2330-
if (this.activeSessionName) {
2380+
try {
2381+
await this.page.screenshot({
2382+
path: outputFile,
2383+
fullPage: fullPageOption,
2384+
type: 'png',
2385+
})
2386+
} catch (err) {
2387+
this.debug(`Failed to take screenshot: ${err.message}`)
2388+
throw err
2389+
}
2390+
2391+
// Handle session screenshots for ALL sessions, not just active one
2392+
if (this.sessionPages && Object.keys(this.sessionPages).length > 0) {
23312393
for (const sessionName in this.sessionPages) {
2332-
const activeSessionPage = this.sessionPages[sessionName]
2394+
const sessionPage = this.sessionPages[sessionName]
23332395
outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`)
23342396

23352397
this.debugSection('Screenshot', `${sessionName} - ${relativeDir(outputFile)}`)
23362398

2337-
if (activeSessionPage) {
2338-
await activeSessionPage.screenshot({
2339-
path: outputFile,
2340-
fullPage: fullPageOption,
2341-
type: 'png',
2342-
})
2399+
try {
2400+
if (sessionPage && !sessionPage.isClosed()) {
2401+
await sessionPage.screenshot({
2402+
path: outputFile,
2403+
fullPage: fullPageOption,
2404+
type: 'png',
2405+
})
2406+
} else {
2407+
this.debug(`Cannot take session screenshot: session page for '${sessionName}' is closed or undefined`)
2408+
}
2409+
} catch (err) {
2410+
this.debug(`Failed to take session screenshot for '${sessionName}': ${err.message}`)
2411+
// Don't throw here - main screenshot was successful
23432412
}
23442413
}
23452414
}

0 commit comments

Comments
 (0)