Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.

Commit 245b48a

Browse files
committed
chore: confirm you can click on button returned by xpath
1 parent 89923ff commit 245b48a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cypress/integration/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<body>
22
<main>
33
<h1>cypress-xpath</h1>
4+
<button id="first-button">Click me</button>
45
</main>
56
<script>
7+
document.getElementById('first-button').addEventListener('click', () => {
8+
window.alert('you clicked first button')
9+
})
610
setTimeout(() => {
711
document.querySelector('main').insertAdjacentHTML('afterend',
812
'<div id="inserted">inserted text</div>')

cypress/integration/spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,18 @@ describe('cypress-xpath', () => {
4343
cy.xpath('boolean(//h2)').should('be.false')
4444
})
4545
})
46+
47+
describe('clicking', () => {
48+
it('on button', () => {
49+
// this button invokes window.alert when clicked
50+
const alert = cy.stub()
51+
cy.on('window:alert', alert)
52+
cy.xpath('//*[@id="first-button"]').click()
53+
.then(() => {
54+
expect(alert).to.have.been.calledOnce
55+
})
56+
57+
})
58+
})
4659
})
4760
})

0 commit comments

Comments
 (0)