Test Overview
This test checks if a button with the ID submit-btn is visible and enabled on the page using Cypress expect() BDD assertions.
This test checks if a button with the ID submit-btn is visible and enabled on the page using Cypress expect() BDD assertions.
describe('Button visibility and state test', () => { it('should verify the submit button is visible and enabled', () => { cy.visit('https://example.com') cy.get('#submit-btn').then(($btn) => { expect($btn).to.be.visible expect($btn).to.be.enabled }) }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser opened yet | — | PASS |
| 2 | Browser opens and navigates to 'https://example.com' | Browser shows the homepage of example.com | — | PASS |
| 3 | Find element with selector '#submit-btn' using cy.get | Button with ID 'submit-btn' is present in the DOM | Element found successfully | PASS |
| 4 | Use expect() to check if the button is visible | Button is visible on the page | expect($btn).to.be.visible | PASS |
| 5 | Use expect() to check if the button is enabled | Button is enabled and clickable | expect($btn).to.be.enabled | PASS |
| 6 | Test ends successfully | All assertions passed, test complete | — | PASS |
expect() in Cypress tests?expect()expect() is used to compare actual results with expected results in tests.count equals 5 using expect() in Cypress?to.equal() checks equality.expect(count).to.equal(5); is the correct way to assert equality.to.equal() for equality [OK]const title = 'Welcome'; expect(title).to.have.length(7);
to.have.length(7) correctly asserts the string length is 7.expect(user.name).to.equals('Alice');to.equal, not to.equals.to.equals causes a runtime error because it is not defined.to.equal -> Option Bitems contains the string 'apple' using expect(). Which assertion correctly tests this?items.to.include('apple') checks if the array contains that element.Pass the test and this pattern moves unknown