Skip to content

Commit bdfc468

Browse files
Copilotrenemadsen
andcommitted
Add comprehensive debugging to diagnose step2e login failures
Co-authored-by: renemadsen <[email protected]>
1 parent eeb05ef commit bdfc468

File tree

2 files changed

+94
-6
lines changed

2 files changed

+94
-6
lines changed

eform-client/e2e/Page objects/Login.page.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,47 @@ class LoginPage extends Page {
4141
}
4242

4343
public async login(): Promise<void> {
44+
console.log('[LOGIN DEBUG] Starting login process...');
45+
console.log('[LOGIN DEBUG] Current URL:', await browser.getUrl());
46+
4447
await (await this.loginBtn()).waitForDisplayed({ timeout: 60000 });
48+
console.log('[LOGIN DEBUG] Login button is displayed');
49+
4550
// await (await this.usernameInput()).waitForDisplayed({ timeout: 60000 });
4651
await (await this.usernameInput()).setValue(LoginConstants.username);
52+
console.log('[LOGIN DEBUG] Username set');
53+
4754
await (await this.passwordInput()).setValue(LoginConstants.password);
55+
console.log('[LOGIN DEBUG] Password set');
56+
4857
await (await this.loginBtn()).click();
58+
console.log('[LOGIN DEBUG] Login button clicked');
59+
console.log('[LOGIN DEBUG] URL after click:', await browser.getUrl());
60+
4961
// Add pause after login click to allow application to start loading on slow environments
5062
await browser.pause(2000);
63+
console.log('[LOGIN DEBUG] Waited 2 seconds, now looking for newEFormBtn...');
64+
console.log('[LOGIN DEBUG] Current URL:', await browser.getUrl());
65+
66+
// Take screenshot before waiting for newEFormBtn to help debug
67+
try {
68+
const screenshotPath = './errorShots/before-newEFormBtn-wait.png';
69+
await browser.saveScreenshot(screenshotPath);
70+
console.log('[LOGIN DEBUG] Screenshot saved to:', screenshotPath);
71+
} catch (e) {
72+
console.log('[LOGIN DEBUG] Could not save screenshot:', e.message);
73+
}
74+
5175
const newEFormBtn = await $('#newEFormBtn');
5276
// Increased timeout for slow environments - application may take longer to initialize
77+
console.log('[LOGIN DEBUG] Waiting for newEFormBtn to be displayed (120s timeout)...');
5378
await newEFormBtn.waitForDisplayed({timeout: 120000});
79+
console.log('[LOGIN DEBUG] newEFormBtn is displayed');
80+
81+
console.log('[LOGIN DEBUG] Waiting for newEFormBtn to be clickable (120s timeout)...');
5482
await newEFormBtn.waitForClickable({timeout: 120000});
83+
console.log('[LOGIN DEBUG] newEFormBtn is clickable - login complete!');
84+
console.log('[LOGIN DEBUG] Final URL:', await browser.getUrl());
5585
}
5686
public async loginWithNewPassword(): Promise<void> {
5787
await (await this.usernameInput()).waitForDisplayed({ timeout: 60000 });

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

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,55 @@ 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) {
236-
// },
235+
beforeTest: function (test) {
236+
console.log('[DEBUG] Starting test:', test.title);
237+
console.log('[DEBUG] Test file:', test.file);
238+
try {
239+
const url = browser.getUrl();
240+
console.log('[DEBUG] Initial URL:', url);
241+
} catch (e) {
242+
console.log('[DEBUG] Could not retrieve initial URL:', e.message);
243+
}
244+
},
237245
/**
238246
* Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
239247
* beforeEach in Mocha)
240248
*/
241-
// beforeHook: function () {
242-
// },
249+
beforeHook: function (test, context, hookName) {
250+
console.log('[DEBUG] Before hook:', hookName);
251+
if (hookName && hookName.includes('before all')) {
252+
console.log('[DEBUG] This is the "before all" hook - where login happens');
253+
}
254+
},
243255
/**
244256
* Hook that gets executed _after_ a hook within the suite ends (e.g. runs after calling
245257
* afterEach in Mocha)
246258
*/
247-
// afterHook: function () {
248-
// },
259+
afterHook: function (test, context, { error, result, duration, passed }, hookName) {
260+
if (error) {
261+
console.log('[DEBUG] Hook failed:', hookName);
262+
console.log('[DEBUG] Hook error:', error.message);
263+
console.log('[DEBUG] Hook duration:', duration);
264+
265+
// Take screenshot on hook failure
266+
try {
267+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
268+
const screenshotPath = `./errorShots/hook-failure-${timestamp}.png`;
269+
browser.saveScreenshot(screenshotPath);
270+
console.log('[DEBUG] Hook failure screenshot saved to:', screenshotPath);
271+
} catch (e) {
272+
console.log('[DEBUG] Could not save hook failure screenshot:', e.message);
273+
}
274+
275+
// Try to get current URL
276+
try {
277+
const url = browser.getUrl();
278+
console.log('[DEBUG] URL at hook failure:', url);
279+
} catch (e) {
280+
console.log('[DEBUG] Could not retrieve URL:', e.message);
281+
}
282+
}
283+
},
249284
/**
250285
* Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) ends.
251286
* @param {Object} test test details
@@ -258,6 +293,29 @@ export const config: WebdriverIO.Config = {
258293
return;
259294
}
260295

296+
console.log('[DEBUG] Test failed:', test.title);
297+
console.log('[DEBUG] Error:', error ? error.message : 'No error message');
298+
console.log('[DEBUG] Duration:', duration);
299+
300+
// Capture browser console logs
301+
try {
302+
const logs = browser.getLogs('browser');
303+
console.log('[DEBUG] Browser console logs:');
304+
logs.forEach(log => {
305+
console.log(` [${log.level}] ${log.message}`);
306+
});
307+
} catch (e) {
308+
console.log('[DEBUG] Could not retrieve browser logs:', e.message);
309+
}
310+
311+
// Capture current URL
312+
try {
313+
const url = browser.getUrl();
314+
console.log('[DEBUG] Current URL:', url);
315+
} catch (e) {
316+
console.log('[DEBUG] Could not retrieve URL:', e.message);
317+
}
318+
261319
/*
262320
* get the current date and clean it
263321
* const date = (new Date()).toString().replace(/\s/g, '-').replace(/-\(\w+\)/, '');

0 commit comments

Comments
 (0)