How to print the output of Cypress SQL Srver (cy.sqlServer) command in the console

Viewed 1079

I am using Cypress to automate tests and I have the following line in my test:

cy.sqlServer("Select top 1 Name from [Test_Org].[dbo].[Orgs]  order by DateCreate desc")

How can I log the output of this command and/or store the value to make assertions on it?

1 Answers

If you take a look at the cy.sqlServer test at /node_modules/cypress-sql-server/test/cypress/integration/db.js, you can see the results come back as nested arrays

cy.sqlServer(sql).should('deep.eq', [['row1col1', 'row1col2'], ['row2col1', 'row2col2']]);

so you can use a .then() instead of .should() to on-process the data,

cy.sqlServer(sql).then(data => {
  console.log(data);
  console.log('row count', data.length);
);
Related