question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request : dataTable, could we have 'hashes' in addition to 'raw' ?

See original GitHub issue

Hi,

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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
badeballcommented, Mar 25, 2020

It’s straight forward, as one would expect.

When("something happens", dataTable => {
  console.log(dataTable.hashes());
});
0reactions
jasson99commented, Aug 22, 2021

@badeball @san-ouadghiri I am not able to use it, could I get some help here? Screenshot from 2021-08-22 18-40-45

Then(/^the following (links|elements) should be visible in the webUI$/, (dataTable) => {
    console.log(dataTable.hashes())
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Cucumberjs Data Tables - How to turn it to .raw()
raw () instead of data.raw(). Saying becoz data is the parameter you are using in the function which cucumber will fill in the...
Read more >
cucumber-ruby/data_table.rb at main - GitHub
# Returns a new Table with an additional column mapping. #. # Change how #hashes converts column values. The +column_name+ argument identifies the...
Read more >
Using Datatable in Cypress Cucumber - Aby George A
I have used datatable.Hashes which return an array of hashes where column name is the key. Apart from datatable.Hashes, there are other methods ......
Read more >
Package 'data.table' - R Project
Convert all character columns to factors? x. A data.table. i. Integer, logical or character vector, single column numeric matrix, expression.
Read more >
Compare The 4 Main Methods From The Cucumber ... - QAMIND
Before I dive into the 4 main DataTable class methods for ... A drief info; DataTable class; hashes(); rows(); raw(); rowsHash(); Conclusion ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found