Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamguys committed Apr 8, 2024
1 parent 987f915 commit a0ae5fc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}


8 changes: 8 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions cypress/e2e/irctc.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}`);
}
})

Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 10 additions & 7 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...'))) {

Expand All @@ -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) => {
Expand Down Expand Up @@ -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 {
Expand All @@ -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')) {
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -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...'))) {
Expand Down

0 comments on commit a0ae5fc

Please sign in to comment.