Best Python code snippet using playwright-python
test_browsercontext.py
Source:test_browsercontext.py  
...208    await page.goto(server.CROSS_PROCESS_PREFIX + "/csp.html")209    await page.add_script_tag(content="window.__injected = 42;")210    assert await page.evaluate("window.__injected") == 42211    await context.close()212async def test_page_event_should_bypass_csp_in_iframes_as_well(browser, server, utils):213    async def baseline():214        # Make sure CSP prohibits add_script_tag in an iframe.215        context = await browser.new_context()216        page = await context.new_page()217        await page.goto(server.EMPTY_PAGE)218        frame = await utils.attach_frame(page, "frame1", server.PREFIX + "/csp.html")219        try:220            await frame.add_script_tag(content="window.__injected = 42;")221        except Error:222            pass223        assert await frame.evaluate("window.__injected") is None224        await context.close()225    await baseline()226    # By-pass CSP and try one more time....LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!
