Feature Request : dataTable, could we have 'hashes' in addition to 'raw' ?
See original GitHub issueHi,
This is a feature request.
Available at cypress-cucumber-preprocessor https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/master/cypress/support/step_definitions/dataTable.js The steps makes available a ‘rawTable’ that is an array of array. We can then manipulate it. This is nice to see dataTable handled 😃 (I thought I would have to code that, so honestly, I’m thankful).
Feature Request Here is some cucumber classical implementation of dataTable. Depending on the called methods you call you can end up with differents formats for your yielded table.
I would personnaly be interested in retrieving a ‘hashes’ (via .hashesTable’ ?) instead of a ‘raw’ via rawTable. In fact, I’d like to use a dataTable to feed the cy.request() ‘qs’ option that requires a {foo: ‘bar’} object. I’m testing an API microservice, and being able to convert a dataTable into cypress requests parameters would be a great plus. Thus the ability to retrieve an object instead of an array would be very nice.
In between, if someone else search for a solution, here is some non-optimized working code. Maybe there’s a way to make it simpler ; if so please share 😃.
When(/^I retrieve items such as$/, function (parameters) {
const parametersArray = parameters.rawTable.slice(1); // Slice remove the header line
// == This function below should be store somewhere else JSYK ==
function objectify(array) {
return array.reduce(function(p, c) {
p[c[0]] = c[1];
return p;
}, {});
};
// ==================================================
const parametersObject = objectify(parametersArray);
cy.request({
method: 'GET',
url: '/path',
headers: {someHeaders},
qs: parametersObject // This works :)
}).then( (response) => {
cy.wrap(response).its('status').as('responseStatusCode');
cy.wrap(response).its('headers').as('responseHeaders');
cy.wrap(response).its('body').as('responseBody');
cy.wrap(response).its('duration').as('responseDuration');
})
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)

Top Related StackOverflow Question
It’s straight forward, as one would expect.
@badeball @san-ouadghiri I am not able to use it, could I get some help here?