diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b41d5e3..30135b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,6 +35,6 @@ jobs: # continue-on-error: true with: browser: chrome - command: npx cypress run --headed --record --key 967b25a7-e4dd-4b5b-a143-d799131b2d3b --browser chrome --env USERNAME=${{secrets.USERNAME}},PASSWORD=${{secrets.PASSWORD}} + command: npx cypress run --record --key 967b25a7-e4dd-4b5b-a143-d799131b2d3b --browser chrome --env USERNAME=${{secrets.USERNAME}},PASSWORD=${{secrets.PASSWORD}} diff --git a/cypress.config.js b/cypress.config.js index f52fb25..3d26e04 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -9,6 +9,14 @@ module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { // implement node event listeners here + on('task', { + log(message) { + // Then to see the log messages in the terminal + // cy.task("log", "my message"); + console.log(message + '\n\n'); + return null; + }, + }); }, chromeWebSecurity: false, experimentalModifyObstructiveThirdPartyCode: true diff --git a/cypress/e2e/irctc.cy.js b/cypress/e2e/irctc.cy.js index c62258f..f81e09c 100644 --- a/cypress/e2e/irctc.cy.js +++ b/cypress/e2e/irctc.cy.js @@ -7,6 +7,7 @@ describe('IRCTC TATKAL BOOKING', () => { it('Tatkal Booking Begins......', () => { cy.viewport(1478, 1056) cy.visit('https://www.irctc.co.in/nget/train-search') + cy.task("log", 'Fetching Completed') cy.get('.h_head1 > .search_btn').click() cy.get(':nth-child(1) > .form-control').invoke('val', username).trigger('input') cy.get(':nth-child(2) > .form-control').invoke('val', password).trigger('input') @@ -57,7 +58,7 @@ describe('IRCTC TATKAL BOOKING', () => { if (div[0].innerText.includes(TRAIN_NO) && div[0].innerText.includes(TRAIN_COACH)) { cy.bookUntilTatkalGetsOpen(div, TRAIN_COACH, TRAVEL_DATE, TRAIN_NO, TATKAL).then(() => { - console.log('TATKAL TIME STARTED......') + cy.task("log", 'TATKAL TIME STARTED......') }) // this is to ensure that Form Page has been opened up so until it fetches it all other execution would be blocked @@ -126,11 +127,11 @@ describe('IRCTC TATKAL BOOKING', () => { cy.wrap(inputField).clear().type(PASSENGER['NAME']); } else { // Log an error if 'NAME' property is missing in passenger object - console.error(`'NAME' property missing in passenger object at index ${index}`); + cy.task("log", `'NAME' property missing in passenger object at index ${index}`); } } else { // Log an error if PASSENGER_DETAILS is missing or insufficient data - console.error(`PASSENGER_DETAILS is missing or insufficient data for index ${index}`); + cy.task("log", `PASSENGER_DETAILS is missing or insufficient data for index ${index}`); } }) @@ -230,8 +231,8 @@ describe('IRCTC TATKAL BOOKING', () => { // https://securegw.paytm.in/theia/processTransaction?orderid=100004437462426 cy.wait("@payment", { timeout: 200000 }).then((interception) => { - cy.log(interception) - console.log(interception.response.body) + cy.task("log", interception) + cy.task("log", interception.response.body) // MAKE SURE UPI ID EXIST THEN PROCEED PLEASE FILL UPI_ID VALUE IN cypress/fixtures/passenger_data.json as something like this "123713278162@paytm" if (UPI_ID) { diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 017d300..0dbda80 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -47,7 +47,7 @@ function performLogin(LOGGED_IN) { cy.get('body').should('be.visible').then((el) => { if (el[0].innerText.includes('Logout')) { - console.log("We have logged in successfully at this stage") + cy.task("log", "We have logged in successfully at this stage") } else if ((el[0].innerText.includes('FORGOT ACCOUNT DETAILS')) && !(el[0].innerText.includes('Please Wait...'))) { @@ -67,9 +67,10 @@ function performLogin(LOGGED_IN) { // get captcha value base64 starts--------- cy.get('.captcha-img').invoke('attr', 'src').then((value) => { // api call to retrieve captcha value - console.log(`python3 irctc-captcha-solver/app.py "${value}"`) + cy.task("log", `python3 irctc-captcha-solver/app.py "${value}"`) cy.exec(`python3 irctc-captcha-solver/app.py "${value}"`).then((result) => { MAX_ATTEMPT -= 1 + cy.task("log", `MAX ATTEMPT -> ${MAX_ATTEMPT} result.stdout ${result.stdout}`) cy.get('#captcha').type(result.stdout).type('{enter}'); // cy.contains('SIGN IN').click() cy.get('body').then((el) => { @@ -146,7 +147,7 @@ function solveCaptcha() { cy.get('#captcha').focus() cy.get('body').then((el) => { if (el[0].innerText.includes('Payment Methods')) { - console.log("Bypassed Captcha") + cy.task("log", "Bypassed Captcha") } }) } else { @@ -156,6 +157,8 @@ function solveCaptcha() { // api call to retrieve captcha value cy.exec(`python3 irctc-captcha-solver/app.py "${value}"`).then((result) => { MAX_ATTEMPT_1 -= 1 + cy.task("log", `MAX ATTEMPT_1 -> ${MAX_ATTEMPT_1}`) + cy.get('#captcha').type(result.stdout).type('{enter}') cy.get('body').then((el) => { if (el[0].innerText.includes('Your ticket will be sent to')) { @@ -164,7 +167,7 @@ function solveCaptcha() { } else if (el[0].innerText.includes('Payment Methods')) { - console.log("Bypassed Captcha") + cy.task("log", "Bypassed Captcha") } else { solveCaptcha() @@ -188,7 +191,7 @@ function solveCaptcha() { } else if (el[0].innerText.includes('Payment Methods')) { - console.log("CAPTCHA .... SOLVED") + cy.task("log", "CAPTCHA .... SOLVED") } else { solveCaptcha() @@ -213,7 +216,7 @@ function BOOK_UNTIL_TATKAL_OPENS(div, TRAIN_COACH, TRAVEL_DATE, TRAIN_NO, TATKAL if (TATKAL && !hasTatkalAlreadyOpened(TRAIN_COACH)) { // wait for exact time - cy.log("Waiting for the exact time of opening of TATKAL...") + cy.task("log", "Waiting for the exact time of opening of TATKAL...") const exactTimeToOpen = tatkalOpenTimeForToday(TRAIN_COACH) cy.get('div.h_head1', { timeout: 300000 }).should('include.text', exactTimeToOpen) @@ -262,7 +265,7 @@ function BOOK_UNTIL_TATKAL_OPENS(div, TRAIN_COACH, TRAVEL_DATE, TRAIN_NO, TATKAL } else if (el[0].innerText.includes('Passenger Details') && el[0].innerText.includes('Contact Details') && !(el[0].innerText.includes('Please Wait...'))) { - console.log("TATKAL BOOKING NOW OPEN....STARTING FURTHER PROCESS") + cy.task("log", "TATKAL BOOKING NOW OPEN....STARTING FURTHER PROCESS") } else if (!(el[0].innerText.includes('Passenger Details')) && !(el[0].innerText.includes('Contact Details')) && !(el[0].innerText.includes('Please Wait...'))) {