roggerfe/cypress-get-table

Unable to print the table content with GetTable method

Closed this issue · 2 comments

GetTable method prints object{5} instead of a JSON response of the table contents

I am assuming you are using cy.log command to print output of table data, correct?

I wrote and ran this snippet of cypress code to get historical table for SP500 on yahoo finance website:

describe('Issue #4', () => {
    it.only('Go to Yahoo Finance and get S&P 500 historical data', () => {
        cy.visit('https://finance.yahoo.com/quote/%5EGSPC/history?period1=1641772800&period2=1642204800&interval=1d&filter=history&frequency=1d&includeAdjustedClose=true')
        cy.get('table').getTable().should(tableData => {
            cy.log('Printing data using JSON.stringify(tableData)', JSON.stringify(tableData));
            cy.log('Printing data without using stringify', tableData);
        })
    })
})

Notice, that first I am using JSON.stringify(tableData) which will print the results in the test execution, I don't recommend doing that though, because the readability of the test run is bad, especially if the JSON is too big.
image
The other way to audit the value is to click into the second log and open your browser console to check the JSON results
image

Let me know if it was helpful.