Rayrun
โ† Back to Discord Forum

Is there a way that I can make cross browser tests in playwright?

acanyasar_73403posted in #help-playwright
Open in Discord
acanyasar_73403

I know that playwright supports testing with different browsers. In my use case, I am trying to test a call product. Where there is one caller, and one callee. I would like to assign them different browsers. I have created a script but it does not work. Any idea how to make this happen? Sample script:

test("@WEB-2352 @Sanity chross browser tests", async ({}) => { const browser1 = await chromium.launch(); const browser2 = await firefox.launch(); const context1 = await browser1.newContext(); const context2 = await browser2.newContext(); const callerPage = await context1.newPage(); const calleePage = await context2.newPage();

await callerPage.goto("daily.11sigh.com");
await calleePage.goTo("google.com");

});

This thread is trying to answer question "Is there a way to perform cross-browser testing in Playwright where different browsers are assigned to different users?"

6 replies
dirvinautomation_16636

Hmm, this is an interesting question. I think it should be possible if you configure a single test block to run to tests in parallel, but it might not work as you hope. You'd need some kind of global flag to indicate both pages are ready but it could work.

I haven't tested this, but it might go something like this:

test.describe.configure({ mode: "parallel" })

test.describe("two browsers at the same time", async () => {
  const readyState = { chromium: false, firefox: false }

  test("the caller in chrome", async () => {
    const browser = await chromium.launch()
    const context = await browser.newContext()
    const page = await context.newPage()
    await page.goto("daily.11sigh.com")
    // assert page has loaded with "expect"
    readyState.chromium = true
    while (!readyState.firefox) await page.waitForTimeout(500)
    // call the callee!
  })

  test("the callee in ff", async () => {
    const browser = await firefox.launch()
    const context = await browser.newContext()
    const page = await context.newPage()
    await page.goto("google.com")
    // assert page has loaded with "expect"
    readyState.firefox = true
    while (!readyState.chromium) await page.waitForTimeout(500)
    // receive the call!
  })
})
acanyasar_73403

Thank you for your detailed answer! I will give it a try and let you know how went ๐Ÿ™‚

Having a single multi-user test spread across two parallel tests as suggested by Dirvin-automation isn't going to work. Each parallel test runs in a different worker process, so they won't share the same readyState object.

Besides, it will actually make coordinating the sequence of steps by the different users harder. You want to do things like caller does some action, then assert something on the callee page. That's much easier if it's one test/one script.

What was actually the problem with your initial approach? What about it was not working? Any error message(s)?

acanyasar_73403

The implementation that I have did its not even actually starting the browser, because we have in playwright I have to run the test with a "browser" right. So when I run the test this is the test output. Its declaring that callerpage.goTo() is not a function. I use the same strructure in my regular tests.

Here is the trace file for the test that I have run :

Hi, looking at the trace, that's just a uppercase/lowercase typo. (JavaScript method calls are case sensitive.) So you need to write .goto() instead of .goTo().

dirvinautomation_16636

Thanks for keeping me honest @refactoreric ! I definitely did not think of that. Nice job getting to the heart of the matter.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].