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

Can't return/await a promisified client.getCookies() #372

Open
akdor1154 opened this issue May 11, 2018 · 1 comment
Open

Can't return/await a promisified client.getCookies() #372

akdor1154 opened this issue May 11, 2018 · 1 comment

Comments

@akdor1154
Copy link

akdor1154 commented May 11, 2018

I'm submitting a ... (check one with "x")

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead use [Stack Overflow](https://stackoverflow.com/questions/tagged/nightwatch.js+cucumber)

Current behavior
When wrapping client.getCookies in a promise, the step hangs forever if it is awaited or returned.

// hangs forever!
Then(/blah/, () => {
  const p = new Promise((resolve, reject) => {
    client.getCookies((c) => {
      try {
        resolve(c.value);
      } catch (e) {
        reject(e);
      }
    });
  })

  return p.then(console.log, console.error);
});
// works-ish (outputs, but only after the test has finished)

Then(/blah/, () => {
  const p = new Promise((resolve, reject) => {
    client.getCookies((c) => {
      try {
        resolve(c.value);
      } catch (e) {
        reject(e);
      }
    });
  })

  p.then(console.log);
});

waiting for a timeout in the test also seems to stop the getCookies callback being called.

// still only outputs after the test has finished

function wait(ms) { return new Promise((res) => setTimeout(res, ms)); }

Then(/blah/, async () => {
  const p = new Promise((resolve, reject) => {
    client.getCookies((c) => {
      try {
        resolve(c.value);
      } catch (e) {
        reject(e);
      }
    });
  })
  
  p.then(console.log);
  await wait(5000);
});

Expected/desired behavior
I should be able wait for getCookies.

Reproduction of the problem
TO DO.

Please tell us about your environment:
Tested natively on Linux and in Docker, image node:8.10.

@mucsi96
Copy link
Owner

mucsi96 commented May 11, 2018

My suggestion to use async await

Then(/blah/, async () => {
  let cookies;
  await client.getCookies(({ value }) => {
     cookies = value
  });
  console.log(cookies);
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants