Working with Table can be tricky as we might need to handle both rows and column to arrive at the target. In this section we find and check whether the rank of Joanna Jedrzejczyk in Women's Strawweight is 4 or not.
This should apply to all the website with the tables in it even if there are several no of rows and column.
CODE
describe('Handling the Table',function(){
context('Test Cases',function(){
it('Women\'s Strawweight',function(){
cy.visit('https://www.ufc.com/rankings')
cy.get('#onetrust-accept-btn-handler').click()
cy.get('.cc-btn').click()
cy.get(':nth-child(11) > .view-grouping-content > .views-table > tbody >tr >td:nth-child(2)').each(($e1, index, $list) => {
const text = $e1.text()
if(text.includes('Joanna')){
cy.get(':nth-child(11) > .view-grouping-content > .views-table > tbody >tr >td:nth-child(1)').eq(index).then(function(rank){
const rankText = rank.text()
expect(rankText).includes('4')
})
}
})
})
})
})
EXPLANATION
Once we visit our target website close all the popup and then we select the table we wish to inspect at, after that we group all the names in the column into the array of string.
Then use the conditional if to get our target row by iteratively running over and over on the list.
We use the index of the target row to arrive at its rank column. Once arrived we will then use assert to validate the rank obtained with the value of the expected.
Download the spec file below,
https://drive.google.com/open?id=1ivEwbeZBjTjlwoU6l6HuZb4_41K8D6hw