getgauge / gauge-js

JavaScript language plugin for Gauge
MIT License
82 stars 39 forks source link

Unable to run async functions within a step table #570

Closed autumn-calhoun closed 1 year ago

autumn-calhoun commented 2 years ago

Describe the bug Steps are getting skipped, causing the test to fail, when you have an async function as your callback function in table.entries.

To Reproduce Steps (or project) to reproduce the behavior:

  1. I am using gauge-js with playwright-js. I have the following scenario that has a step with a table:

    Create Multiple Orders In Single Test

    • Login as "user"
    • Open "site" "811811" from the home page
    • Create Order

      customer license_type scope
      customer 1 create other
      customer 2 amend ground space
  2. The step implementation is as follows:

    step("Create Order

    ", async function (table) { let order = new Order(gauge.dataStore.scenarioStore.get("page"))

    await table.entries(async function (entry) {
        await order.createOrder(entry["customer"], entry["license_type"], entry["scope"])
    })

    })

  3. When I run the test I get the following error: UnhandledPromiseRejectionWarning: page.click: Target closed. The page.click is happening in the createOrder async function

  4. I was able to get past this by creating my own instance of the Table function and making async (see below), but am wondering if this can be officially supported or is it already and I just missed it somewhere?

  5. Expected behavior table.entries waits for the async callback function to complete before proceeding

    Versions:

    • Playwright 1.25.1
    • OS Windows 10.0.19042
    • Node.js v12.22.1
    gauge -v

    Gauge version: 1.4.3 Commit Hash: f98dd40

    Plugins

    flash (0.0.2) html-report (4.1.4) js (2.4.0) python (0.3.17) screenshot (0.1.0) spectacle (0.1.4) xml-report (0.2.3)

    Additional context I noticed that the Table entries function is not asynchronous, so I created my own instance and made it asynchronous and now the test runs as expected.

    1. Copied the table function and updated as follows:

    var AsyncTable = function (protoTable) { Object.assign(this, protoTable);

    this.entries = async function (callback) {
        for (var row of this.rows) {
            let entry = {};
            row.cells.forEach((cell, index) => entry[this.headers.cells[index]] = cell);
            await callback(entry);
        }
    };

    };

    module.exports = AsyncTable;

    1. Modified my step implementation as follows:

    step("Create Order

    ", async function (table) { let order = new Order(gauge.dataStore.scenarioStore.get("page")) let async_table = new AsyncTable(table)

    await async_table.entries(async function (entry) {
        await order.createOrder(entry["customer"], entry["license_type"], entry["scope"])
    })

    })

    autumn-calhoun commented 1 year ago

    @zabil @sriv Does anyone know if this project is still being maintained?

    zabil commented 1 year ago

    It's not under active development anymore.

    Please read https://github.com/getgauge/gauge/issues/1732

    PR's to fix issues will be accepted.

    autumn-calhoun commented 1 year ago

    @zabil I want to submit a fix for this issue, but the contribution repo is not up to date with the gauge-js master (https://github.com/getgauge-contrib/gauge-jso). How do I get it up to date? Do I have to update it in my fork and submit a separate PR for that first?

    zabil commented 1 year ago

    https://github.com/getgauge-contrib/gauge-jso is not the correct repo.

    You can fork this repo and send a pull request with your changes.

    zabil commented 1 year ago

    The repo mentioned at https://github.com/getgauge/gauge-js/blob/master/CONTRIBUTING.md

    Is wrong, please feel free to correct that too!

    autumn-calhoun commented 1 year ago

    @zabil I created a PR that includes the corrected repo in the contributing file. https://github.com/getgauge/gauge-js/pull/571