diff --git a/cypress/e2e/cypressBestPractices.spec.cy.ts b/cypress/e2e/cypressBestPractices.spec.cy.ts index 9ac171e..b39030d 100644 --- a/cypress/e2e/cypressBestPractices.spec.cy.ts +++ b/cypress/e2e/cypressBestPractices.spec.cy.ts @@ -9,7 +9,6 @@ const spage = new seleniumEasyPage() let seleniumEasyData, inspifyData describe('Cypress best practices', () => { - context('SeleniumEasy', () => { before(() => { cy.fixture('seleniumEasy.json').then((data) => { @@ -62,10 +61,24 @@ describe('Cypress best practices', () => { spage.handleJavascriptConfirmationBoxClickCancel() }) - it.only('Handle javascript alert with input box',()=>{ + it('Handle javascript alert with input box', () => { spage.clickOnAlertsAndModals() spage.clickOnJavascriptAlerts() - spage.handleJavascriptAlertWithInputBox() + //spage.handleJavascriptAlertWithInputBox() + // cy.get('[onclick="myPromptFunction()"]').click(); + //@ts-ignore + cy.handlePrompt() + }) + + // This block will be executed only if we comment the before code + // it.skip('Handling tabs', () => { + // spage.handleTabs() + // }) + + it('Cypress call back functions', () => { + spage.clickOnOthersmenu() + spage.clickOnDynamicDataLoadingMenu() + spage.callbackFunctions() }) afterEach(() => { @@ -77,7 +90,7 @@ describe('Cypress best practices', () => { }) }) - context.skip('Inspify', () => { + context('Inspify', () => { before(() => { cy.fixture('testData.json').then((data) => { inspifyData = data; diff --git a/cypress/e2e/practicePrograms.spec.cy.ts b/cypress/e2e/practicePrograms.spec.cy.ts index 42df7ed..9b35817 100644 --- a/cypress/e2e/practicePrograms.spec.cy.ts +++ b/cypress/e2e/practicePrograms.spec.cy.ts @@ -67,3 +67,15 @@ function toprintreversename() { console.log(reverseString) } toprintreversename() + +function printInitialCharsOfName(){ + let name = "Ramya Reddy Alla" + let splitname = name.split(" ") + console.log(splitname) + let result = "" + for(let i=0;i { - // Extract the expected prompt message - const promptMessage = message.replace('Please enter your value:', '').trim(); - - // Simulate entering a value into the prompt - const promptValue = 'Your value goes here'; - cy.window().then((win) => { - cy.stub(win, 'prompt').returns(promptValue); - }); - }); - - // Trigger the action that triggers the alert with an input box - cy.get('[onclick="myPromptFunction()"]').click(); + // handleJavascriptAlertWithInputBox() { + // cy.on('window:prompt', (message, defaultValue) => { + // // Handle the prompt box + // cy.window().then((win) => { + // cy.stub(win, 'prompt').returns('John Doe'); // Simulate user input + // cy.on('window:confirm', () => {}); // Stub the subsequent confirm + // }); + // }); + + // // Trigger the action that triggers the alert with an input box + // cy.get('[onclick="myPromptFunction()"]').click(); + // cy.handlePrompt() + // } + + handleTabs() { + // url launch + cy.visit("https://www.google.com/") + // delete target attribute with invoke for link + cy.get(locators.gmail) + .invoke('removeAttr', 'target').click() + // verify tab url + cy.url() + .should('contain', 'gmail') + // shift to parent window + cy.go('back') + cy.url().should('not.contain', 'gmail') + cy.go('forward') + } + + clickOnDynamicDataLoadingMenu() { + cy.get(locators.dynamicDataLoadingMenu).should('be.visible').should('contain.text', 'Dynamic Data Loading') + .should('contain.html', 'Data').click() + } + + callbackFunctions() { + cy.get(locators.getNewUserButton).should('be.visible').should('contain.text', 'Get New User').then(($button) => { + cy.wrap($button).click() + }) + cy.get(locators.randomProfile).find('br').should((verify) => { + expect(verify).to.have.length(4) + }) + cy.get(locators.randomProfile).invoke('text').should((verify) => { + expect(verify).to.contain('First') + }) } } \ No newline at end of file diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index df73edf..d3f7e07 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -23,4 +23,12 @@ Cypress.Commands.add("logout", () => { cy.get(locators.LogoutButton).click() cy.get(locators.LoginForm).should('be.visible') .find('h1').should('contain.text', 'WELCOME') -}) \ No newline at end of file +}) + +// @ts-ignore +Cypress.Commands.add('handlePrompt', () => { + cy.window().then((win) => { + cy.stub(win, 'prompt').returns('Ramya'); // Simulate user input + cy.stub(win, 'onbeforeunload'); // Stub onbeforeunload to prevent page refresh + }); +}); \ No newline at end of file