Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions cypress/e2e/cypressBestPractices.spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const spage = new seleniumEasyPage()
let seleniumEasyData, inspifyData

describe('Cypress best practices', () => {

context('SeleniumEasy', () => {
before(() => {
cy.fixture('seleniumEasy.json').then((data) => {
Expand Down Expand Up @@ -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(() => {
Expand All @@ -77,7 +90,7 @@ describe('Cypress best practices', () => {
})
})

context.skip('Inspify', () => {
context('Inspify', () => {
before(() => {
cy.fixture('testData.json').then((data) => {
inspifyData = data;
Expand Down
12 changes: 12 additions & 0 deletions cypress/e2e/practicePrograms.spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<splitname.length;i++){
result += splitname[i].charAt(0)
}
console.log(result)
}
printInitialCharsOfName()
14 changes: 9 additions & 5 deletions cypress/locators/seleniumEasyLocators.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const seleniumEasyLocators = {
menuArrow: "#treemenu .tree-branch [href]",
dragAndDropmenu: '.tree-branch [href*= "drag-and-drop"]',
drag : '[draggable="true"]',
drop : "#mydropzone",
drag: '[draggable="true"]',
drop: "#mydropzone",
droppedList: "#droppedlist",
radioButtonMenu: '#treemenu [href*="radiobutton"]',
radioButton : 'input:not([name="gender"])[value="Male"]',
getCheckedValueButton : "#buttoncheck",
radioButton: 'input:not([name="gender"])[value="Male"]',
getCheckedValueButton: "#buttoncheck",
checkedResultText: ".radiobutton",
selectDropdownList: '#treemenu [href*="select-dropdown"]',
panelHeading: ".panel-heading",
Expand All @@ -18,7 +18,11 @@ const seleniumEasyLocators = {
javascriptAlertsmenu: '.tree-branch [href*= "javascript-alert"]',
alertBoxButton: '[onclick="myAlertFunction()"]',
confirmationBoxButton: '[onclick="myConfirmFunction()"]',
confirmationBoxText: '#confirm-demo'
confirmationBoxText: '#confirm-demo',
gmail: '[aria-label*="Gmail"]',
randomProfile: "#loading",
getNewUserButton: "#save",
dynamicDataLoadingMenu: '#treemenu [href*="dynamic-data-loading"]'
}

export default seleniumEasyLocators;
58 changes: 44 additions & 14 deletions cypress/pages/seleniumEasyPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,49 @@ export default class seleniumEasyPage {
});
}

handleJavascriptAlertWithInputBox() {
cy.on('window:alert', (message) => {
// 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')
})
}
}
10 changes: 9 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

// @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
});
});