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

openBrowser with observe set, results in "Browser or page not initialized" #2712

Open
fbuetler opened this issue Nov 22, 2023 · 5 comments
Open

Comments

@fbuetler
Copy link

Describe the bug

For exported functions interacting with the browser, there are some hooks in place that check each time before running these functions, if the observe mode is set, and if it is, to wait before actually running the function:

const realFuncs = {};
for (const func in module.exports) {
  realFuncs[func] = module.exports[func];
  if (realFuncs[func].constructor.name === 'AsyncFunction') {
    module.exports[func] = async function () {
      if (defaultConfig.observe) {
        await waitFor(defaultConfig.observeTime);
      }
      return await realFuncs[func].apply(this, arguments);
    };
  }
}

https://github.com/getgauge/taiko/blob/v1.3.10/lib/taiko.js#L2616-L2618

The first thing waitFor does, is to call validate (https://github.com/getgauge/taiko/blob/v1.3.10/lib/taiko.js#L2340) and the first thing validate does, is to check if there is a browser instance available (https://github.com/getgauge/taiko/blob/v1.3.10/lib/connection.js#L175-L177).

Unfortunately, this hook is also executed for the openBrowser function. As the purpose of this function is to open a browser, the aforementioned check will inherently fail, as there is no browser instance available

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

  1. Set observe to true
  2. Call openBrowser()
  const { openBrowser, setConfig } = require('taiko');
  await setConfig({
    observe: true,
  });
  await openBrowser()

Logs

    Error Message: Error: Browser or page not initialized. Call `openBrowser()` before using this API
    Stacktrace: 
    Error: Browser or page not initialized. Call `openBrowser()` before using this API
        at validate (node_modules/taiko/lib/connection.js:176:11)
        at waitFor (node_modules/taiko/lib/taiko.js:2340:3)
        at module.exports.<computed> (node_modules/taiko/lib/taiko.js:2617:15)

Expected behavior

Error should not happen.

Versions:

  • Taiko: 1.3.10
  • OS: debian bullseye
  • Node.js: 16
@DCoomer
Copy link
Contributor

DCoomer commented Nov 23, 2023

You can pass {headless:false} into openBrowser if you need to observe the test

@fbuetler
Copy link
Author

Actually, our use case was a bit different. We only wanted to have a specific time interval between each test step. Hence, we opened the browser with headless and observe set.
I know observe is originally meant to observe the test with a visible browser. However, I think, openBrowser should not fail in the case described above.

@DCoomer
Copy link
Contributor

DCoomer commented Nov 27, 2023

The observeTime option for setConfig sets the delay between each test step.

So you would need to open the browser first, then call await setConfig({observeTime: timeInMilliSeconds})
or npx taiko script.js -o -w 1500 (1500 being the observeTime in ms )

I think headless == true sets it to '0'.

Otherwise make a pull request to fix the issue you're presenting. Taiko isn't actively maintained/fixing bugs. But they do accept pull requests for bug fixes from the community

@peschee
Copy link

peschee commented Nov 27, 2023

Taiko isn't actively maintained/fixing bugs

That's a bummer :/

@DCoomer
Copy link
Contributor

DCoomer commented Nov 27, 2023

#2707

Again, they accept Pull Requests. So if you have an issue, you can submit a solution via a pull request. They are usually pretty quick to review and merge them.

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

3 participants