Unable to print the table content with GetTable method
Closed this issue · 2 comments
likitha1524 commented
GetTable method prints object{5} instead of a JSON response of the table contents
roggerfe commented
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.
The other way to audit the value is to click into the second log and open your browser console to check the JSON results
Let me know if it was helpful.
likitha1524 commented
Thank you so much, this worked perfectly fine.
Regards,
Likitha Lokesh
Chicago, IL
…On Sat, Jan 15, 2022 at 3:51 PM Rogger Fernandes ***@***.***> wrote:
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: image]
<https://user-images.githubusercontent.com/6186831/149638787-edd70495-79b6-4cce-acbd-5a52496fc283.png>
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: image]
<https://user-images.githubusercontent.com/6186831/149638829-58fb144c-e0a0-48aa-b502-744c66869081.png>
Let me know if it was helpful.
—
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHA7EHONXJZ4KU3XPVALO2TUWHT7LANCNFSM5L7VA4JQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>