Skip to content

Commit 5d908a1

Browse files
committed
Extend time for the test.
Add try/catch in After.
1 parent 102e82d commit 5d908a1

1 file changed

Lines changed: 31 additions & 13 deletions

File tree

cucumber.conf.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const os = require("os");
1212
const reporter = require("cucumber-html-reporter");
1313

1414
require("events").EventEmitter.defaultMaxListeners = 20;
15-
setDefaultTimeout(300000);
15+
setDefaultTimeout(600000); // Increase timeout to 10 minutes
1616

1717
Before(async function ({ pickle }) {
1818
fs.mkdirSync("report", { recursive: true });
@@ -103,20 +103,38 @@ Before(async function ({ pickle }) {
103103
});
104104

105105
After(async function (testCase) {
106-
if (testCase.result.status === "FAILED" && this.browser) {
107-
const filename = `screenshots/${testCase.pickle.name}-${Date.now()}.png`;
108-
await this.browser.saveScreenshot(filename);
109-
this.attach(fs.readFileSync(filename), "image/png");
110-
}
106+
try {
107+
// Take screenshot if test failed and browser is available
108+
if (testCase.result.status === "FAILED" && this.browser) {
109+
try {
110+
const filename = `screenshots/${testCase.pickle.name}-${Date.now()}.png`;
111+
await this.browser.saveScreenshot(filename);
112+
this.attach(fs.readFileSync(filename), "image/png");
113+
} catch (screenshotError) {
114+
console.error("Failed to save screenshot:", screenshotError.message);
115+
}
116+
}
111117

112-
// Only quit browser if not running with @debug tag
113-
const isDebug = testCase.pickle && testCase.pickle.tags && testCase.pickle.tags.some(tag => tag.name === '@debug');
114-
if (this.browser && !isDebug) {
115-
await this.browser.quit();
116-
}
118+
// Only quit browser if not running with @debug tag
119+
const isDebug = testCase.pickle && testCase.pickle.tags && testCase.pickle.tags.some(tag => tag.name === '@debug');
120+
if (this.browser && !isDebug) {
121+
try {
122+
await this.browser.quit();
123+
} catch (quitError) {
124+
console.error("Failed to quit browser:", quitError.message);
125+
}
126+
}
117127

118-
if (this.tmpUserDataDir) {
119-
fs.rmSync(this.tmpUserDataDir, { recursive: true, force: true });
128+
// Clean up temp directory
129+
if (this.tmpUserDataDir) {
130+
try {
131+
fs.rmSync(this.tmpUserDataDir, { recursive: true, force: true });
132+
} catch (cleanupError) {
133+
console.error("Failed to clean up temp directory:", cleanupError.message);
134+
}
135+
}
136+
} catch (error) {
137+
console.error("Error in After hook:", error.message);
120138
}
121139

122140
if (

0 commit comments

Comments
 (0)