getgauge / taiko

A node.js library for testing modern web applications
https://taiko.dev
MIT License
3.56k stars 452 forks source link

Problem to run 1 more async #2671

Closed FatherScrooge closed 1 month ago

FatherScrooge commented 1 year ago

Hi!

I'm trying to run a "for", "while", etc to try to run more than one asynchronous function simultaneously because I need it for my operation.

The only way I found was to create several .js files for each asynchronous function to run.

I would like to know if it is possible to run everything in just one file because the following error is always being returned to me.

"Error: Browser or page not initialized. Call openBrowser() before using this API"

DCoomer commented 1 year ago

I think running everything in one file is expected, are you able to show your code?

FatherScrooge commented 1 year ago

Example:

const { openBrowser, goto, near, click, textBox, press, write, button, reload, text, tap} = require('taiko') var readline = require('readline') const random = require('random') const delay = require('delay') setConfig( { noOfElementToMatch: 200}); var consts = require('./consts.js'); var teste = 1;

while(teste < 5) { teste++

(async () =>
{       
    try 
    {
        await openBrowser({args: ['--disable-gpu','--disable-dev-shm-usage','--disable-setuid-sandbox','--no-first-run','--no-sandbox','--no-zygote', '--user-data-dir=C:/bots/['+teste+']']})
        await emulateDevice('iPhone X')
        await goto('https://google.com/', {navigationTimeout:90000})
    }

    finally 
    {

    }
})();

}

DCoomer commented 1 year ago

I'm pretty sure can only open browser once per test, so you would need to have a separate file for each of your profiles in C:/bots. Depending on what you need each profile for, you could maybe put that into code instead. Otherwise a separate file is needed