Xpath in Cypress
To watch in YOUTUBE : click here
1. Install xpath plugin in cypress
In your terminal run below command:
npm install -D cypress-xpath
After this you can see the cypress dependency in your package.json file.
2. Update in Support folder
Now, you need to add below command/code/line in Support/e2e.js file(previously it used to be support/index.js)
require('cypress-xpath');
3. Use xpath in the cypress code
Below is an example of test case without xpath and with xpath:
describe('test xpath in cypress', () => {
it('xpathTest', ()
=> {
cy.visit('https://www.google.com')
cy.get("div.a4bIc").type("cypress")
cy.contains("Google
Search").click()
})
it.only('xpathTest
using actual xpath', () => {
cy.visit('https://www.google.com')
cy.xpath("//div[@class='a4bIc']").type("cypress
with xpath")
cy.xpath("//div[@class='FPdoLc lJ9FBc']//following::input[@value='Google Search']")
.click({force:true})
})
})
No comments:
Post a Comment