I am struggling to make Cypress see my web table that is in a Shadow DOM. My test Scenario is: After I type invalid data on the search bar, e.g 'oo', Cypress ensures that the table is empty, this means that only the headers: Name and Billing Contact Name are displayed.
What I did:
- Installed getTable command:
npm install --save cypress-get-table
- Included in the project’s cypress/support/index.js file:
require('cypress-get-table')
This is the HTML code
And this is my cypress code
it('should type an invalid search', function () {
cy.get('div.input-container').type('oo{enter}') //type oo in the search bar
//After type oo the table should be cleared
cy.get('im-data-table.hydrated').shadow().find('div#dataTable').getTable().should(tableData(){
expect(tableData).to.be.empty
})
})
Problem is: Cypress can not find the table.
Any help is realy appreciated.
Update: I put a new picture to have the HTML code more complete. On this new one, we can see the content of the table and the im-root
and this is the code with multiple .shadow() calls
cy.get('im-page.hydrated').shadow()
.find('im-section:nth-of-type(2)') //second im-section
.shadow()
.find('im-data-table.hydrated')
.shadow()
.find('div#dataTable')
.getTable()
.should(function (tableData) {
expect(tableData).to.be.empty
})
With this chained .shadow() calls Cypress does not find the im-section