Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run async functions within a step table #570

Closed
autumn-calhoun opened this issue Sep 1, 2022 · 6 comments
Closed

Unable to run async functions within a step table #570

autumn-calhoun opened this issue Sep 1, 2022 · 6 comments

Comments

@autumn-calhoun
Copy link
Contributor

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
Copy link
Contributor Author

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

@zabil
Copy link
Member

zabil commented Nov 9, 2022

It's not under active development anymore.

Please read getgauge/gauge#1732

PR's to fix issues will be accepted.

@autumn-calhoun
Copy link
Contributor Author

@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
Copy link
Member

zabil commented Apr 13, 2023

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
Copy link
Member

zabil commented Apr 13, 2023

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 added a commit to autumn-calhoun/gauge-js that referenced this issue Apr 14, 2023
…tions to resolve issue getgauge#570.  Also had to bump the ecmaVersion to 8 in eslint to support async await

Signed-off-by: Autumn Calhoun <[email protected]>
@autumn-calhoun
Copy link
Contributor Author

@zabil I created a PR that includes the corrected repo in the contributing file.
#571

autumn-calhoun added a commit to autumn-calhoun/gauge-js that referenced this issue Apr 20, 2023
zabil pushed a commit that referenced this issue Apr 29, 2023
#571)

* Added another function to Table that will process async callback functions to resolve issue #570.  Also had to bump the ecmaVersion to 8 in eslint to support async await

Signed-off-by: Autumn Calhoun <[email protected]>

* #570 updated per code review comments

Signed-off-by: Autumn Calhoun <[email protected]>

---------

Signed-off-by: Autumn Calhoun <[email protected]>
@zabil zabil closed this as completed Apr 29, 2023
autumn-calhoun added a commit to autumn-calhoun/gauge-js that referenced this issue Jul 10, 2023
…e callback function is an AsyncFunction

Signed-off-by: Autumn Calhoun <[email protected]>
chadlwilson pushed a commit that referenced this issue Jul 10, 2023
…ck function is an AsyncFunction

Signed-off-by: Autumn Calhoun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants