@@ -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