Xk6-browser, async vs sync

Hi Team,

I see few examples where people have written test as

page.goto('test-site-5', { waitUntil: 'networkidle'});

page.$('input[name="UserId"]').type('username');
page.$('input[name="Password"]').type('password');
page.$('input[type="submit"]').click();

but its not working for me, browser is just getting open and closed, I have to used page.goto as async function e.g.

page.goto('url', { waitUntil: 'load' }).then(()=>{
      page.$("//input[@id='']").type('')
      page.$("//input[@id='']").type('')  
         
   return Promise.all([
           page.waitForNavigation(),
           page.$("//button[@name='']").click()       
      ])

and this works for me.

Can you please confirm why so

Hi @vish_s02,

Which version of xk6-browser are you using? We are migrating our APIs to work asynchronously. Here is the current list of APIs that were migrated across to async and the version of xk6-browser that the change was implemented in:

v0.3.0:

  • Browser.on() is async.

v0.5.0:

  • ElementHandle.click() is async.
  • Frame.click() is async.
  • Page.click() is async.
  • Page.waitForFunction() is async.

v0.6.0:

  • Page.goto() is async.

Depending on which version of xk6-browser you are using, you will need to work with the listed async APIs with the .then syntax.

Cheers,
Ankur