1

I am using Cypress version 10.9.0 for e2e testing. Of course, there are more step defs but it stops at the first then step as it can be seen from the SS image.

When('I enter an invalid username on the login page', () => {
    cy.get('#username').type('portal').invoke('removeAttr', 'value').click({ force: true }, { timeout: 30000 })
    cy.get('#password').type('SwY66bc3VZLUFR9')
    cy.get('[type="submit"]').click()
})
 
Then('an error message is displayed with the text Invalid username/password', () => {
    cy.get(".invalid.text-left").should('contain.text', 'Invalid username/password')
})

Cypress GUI error

Cypress GUI error

DOM element

DOM element

Jason Scaggs
  • 168
  • 9
  • Are you using the cypress-cucumber-preprocessor? https://www.npmjs.com/package/cypress-cucumber-preprocessor If so, can you share `.feature` file as well? – Manuel Abascal Oct 24 '22 at 17:58
  • Hi @ManuelAbascal, yes I am using that cypress-cucumber-preprocessor. I have attached `.feature` file. ```Feature: Login Scenario: #1 Test Invalid Username / Invalid Password / Empty Username / Valid Username and Empty Password Given I am at the portal login page When I enter an invalid username on the login page Then an error message is displayed with the text Invalid username/password When I enter an invalid password on the login page Then an error message is displayed with the text Invalid username/password``` – Mehmet Şirin Tarhan Oct 24 '22 at 18:54
  • It's coming from cucumber then, you gotta make sure that the description is matching in both `.feature` & `.spec` files – Manuel Abascal Oct 24 '22 at 18:59

1 Answers1

2

The error says cannot find #username but clearly it is present, so you may have a shadowroot in the DOM above the <input>.

If so, add a configuration to allow searching within, in cypress.config.js

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    baseUrl: 'http://localhost:1234'
  },
  includeShadowDom: true,
})

If you don't see shadowroot, look for an <iframe> element.
Handling an iframe is best done with Cypress iframe

Jason Scaggs
  • 168
  • 9
  • Hi @jasonScaggs After doing what you have said here, now I am getting this error: ```then{}, function(){} Error Step implementation missing for: an error message is displayed with the text Invalid username/password``` – Mehmet Şirin Tarhan Oct 24 '22 at 23:00