Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@monkeyjumps/cypress-get-table
Advanced tools
Cypress plugin to make table and grid assertions easier
Adds getTable
command to cypress
test runner.
npm install --save @monkeyjumps/cypress-get-table
Then include in your project's cypress/support/index.js
require('@monkeyjumps/cypress-get-table')
Ater installation, cy
object will have getTable
command.
The command can ONLY be called chained after a subject.
Incorrect usage:
cy.getTable('table#table1')
Correct usage:
cy.get('table#table1').getTable()
Suppose you have this table in your webpage:
City | Country |
---|---|
Rio de Janeiro | Brazil |
Los Angeles | USA |
Buenos Aires | Argentina |
cy.get("table").getTable()
will return the following list of objects:
[{
"City": "Rio de Janeiro",
"Country": "Brazil"
}, {
"City": "Los Angeles",
"Country": "USA"
}, {
"City": "Buenos Aires",
"Country": "Argentina"
}]
If table is empty (with only headers), getTable() will return an empty list.
Given table:
City | Country |
---|---|
Code:
cy.get('table').getTable().should(tableData => {
expect(tableData).to.be.empty
})
Given table:
City | Country |
---|---|
Rio de Janeiro | Brazil |
Los Angeles | USA |
Code:
const expected = [
{
"City": "Rio de Janeiro",
"Country": "Brazil"
}, {
"Country": "USA",
"City": "Los Angeles"
}
]
cy.get('table').getTable().should(tableData => {
expect(tableData).to.deep.equal(expected)
})
Given table:
City | Country |
---|---|
Rio de Janeiro | Brazil |
Los Angeles | USA |
Code:
const expected = [
{
"Country": "USA",
"City": "Los Angeles"
}, {
"City": "Rio de Janeiro",
"Country": "Brazil"
}
]
cy.get('table').getTable().should(tableData => {
expect(tableData).to.deep.equalInAnyOrder(expected)
})
Given table:
City | Country |
---|---|
Rio de Janeiro | Brazil |
Los Angeles | USA |
Code:
const expected = [
{
"Country": "USA",
"City": "Los Angeles"
}
]
cy.get('table').getTable().should(tableData => {
expected.forEach(item => expect(tableData).to.deep.include(item))
})
Given table:
City | State | Country |
---|---|---|
Rio de Janeiro | Rio de Janeiro | Brazil |
Los Angeles | California | USA |
Code:
const losAngeles = {
"City": "Los Angeles",
"Country": "USA"
}
cy.get('table').getTable({ onlyColumns: Object.keys(losAngeles) }).should(tableData => {
expect(tableData).to.deep.include(losAngeles)
})
As you can see for this case is necessary to pass key 'onlyColumns'
which is a list of string of all columns needed.
cypress/integration/spec.js
and let the tets speak for itself.This library only works if your table uses the correct tags, which is thead/th
For table head and table header, and tr/td
for table row and table data.
Does not handle pagination neither infinite scrolling
Table needs to have a table header
Does not handle colspan neither rowspan
Please do not hesitate to open bugs, issues and enhancements, and feel free to add more features and make this library more useful for others and make a pull request.
FAQs
Cypress plugin to make table and grid assertions easier
We found that @monkeyjumps/cypress-get-table demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.