Skip to content

Commit f370e48

Browse files
Copilotrenemadsen
andcommitted
Fix async/await issues in wdio hooks for proper debugging
Co-authored-by: renemadsen <[email protected]>
1 parent bdfc468 commit f370e48

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

eform-client/wdio-headless-step2e.conf.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ export const config: WebdriverIO.Config = {
232232
* Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
233233
* @param {Object} test test details
234234
*/
235-
beforeTest: function (test) {
235+
beforeTest: async function (test) {
236236
console.log('[DEBUG] Starting test:', test.title);
237237
console.log('[DEBUG] Test file:', test.file);
238238
try {
239-
const url = browser.getUrl();
239+
const url = await browser.getUrl();
240240
console.log('[DEBUG] Initial URL:', url);
241241
} catch (e) {
242242
console.log('[DEBUG] Could not retrieve initial URL:', e.message);
@@ -256,7 +256,7 @@ export const config: WebdriverIO.Config = {
256256
* Hook that gets executed _after_ a hook within the suite ends (e.g. runs after calling
257257
* afterEach in Mocha)
258258
*/
259-
afterHook: function (test, context, { error, result, duration, passed }, hookName) {
259+
afterHook: async function (test, context, { error, result, duration, passed }, hookName) {
260260
if (error) {
261261
console.log('[DEBUG] Hook failed:', hookName);
262262
console.log('[DEBUG] Hook error:', error.message);
@@ -266,15 +266,15 @@ export const config: WebdriverIO.Config = {
266266
try {
267267
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
268268
const screenshotPath = `./errorShots/hook-failure-${timestamp}.png`;
269-
browser.saveScreenshot(screenshotPath);
269+
await browser.saveScreenshot(screenshotPath);
270270
console.log('[DEBUG] Hook failure screenshot saved to:', screenshotPath);
271271
} catch (e) {
272272
console.log('[DEBUG] Could not save hook failure screenshot:', e.message);
273273
}
274274

275275
// Try to get current URL
276276
try {
277-
const url = browser.getUrl();
277+
const url = await browser.getUrl();
278278
console.log('[DEBUG] URL at hook failure:', url);
279279
} catch (e) {
280280
console.log('[DEBUG] Could not retrieve URL:', e.message);
@@ -285,7 +285,7 @@ export const config: WebdriverIO.Config = {
285285
* Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) ends.
286286
* @param {Object} test test details
287287
*/
288-
afterTest(test, context, { error, result, duration, passed, retries }) {
288+
afterTest: async function (test, context, { error, result, duration, passed, retries }) {
289289
const path = require('path');
290290

291291
// if test passed, ignore, else take and save screenshot.
@@ -299,7 +299,7 @@ export const config: WebdriverIO.Config = {
299299

300300
// Capture browser console logs
301301
try {
302-
const logs = browser.getLogs('browser');
302+
const logs = await browser.getLogs('browser');
303303
console.log('[DEBUG] Browser console logs:');
304304
logs.forEach(log => {
305305
console.log(` [${log.level}] ${log.message}`);
@@ -310,7 +310,7 @@ export const config: WebdriverIO.Config = {
310310

311311
// Capture current URL
312312
try {
313-
const url = browser.getUrl();
313+
const url = await browser.getUrl();
314314
console.log('[DEBUG] Current URL:', url);
315315
} catch (e) {
316316
console.log('[DEBUG] Could not retrieve URL:', e.message);
@@ -339,7 +339,7 @@ export const config: WebdriverIO.Config = {
339339
const filePath = path.resolve(this.screenshotPath, `${filename}.png`);
340340

341341
console.log('Saving screenshot to:', filePath);
342-
browser.saveScreenshot(filePath);
342+
await browser.saveScreenshot(filePath);
343343
console.log('Saved screenshot to:', filePath);
344344
},
345345
/**

0 commit comments

Comments
 (0)