예제 #1
0
async def test_should_override_request_url(page: Page, context: BrowserContext,
                                           server: Server) -> None:
    url = []
    await context.route(
        "**/global-var.html",
        lambda route: (
            url.append(route.request.url),
            asyncio.create_task(route.continue_()),
        ),
    )
    await context.route(
        "**/foo",
        lambda route: asyncio.create_task(
            route.fallback(url=server.PREFIX + "/global-var.html")),
    )

    [server_request, response, _] = await asyncio.gather(
        server.wait_for_request("/global-var.html"),
        page.wait_for_event("response"),
        page.goto(server.PREFIX + "/foo"),
    )

    assert url == [server.PREFIX + "/global-var.html"]
    assert response.url == server.PREFIX + "/foo"
    assert await page.evaluate("() => window['globalVar']") == 123
    assert server_request.uri == b"/global-var.html"
    assert server_request.method == b"GET"
예제 #2
0
    def test_admin_login(page: Page):
        """
        登录后台
        """
        # Click [placeholder="请输入用户名"]
        page.click("[placeholder=\"请输入用户名\"]")
        # Fill [placeholder="请输入用户名"]
        page.fill("[placeholder=\"请输入用户名\"]", "admin")
        # Fill [placeholder="请输入登录密码"]
        page.fill("[placeholder=\"请输入登录密码\"]", "shopxo")
        # Click button:has-text("登录")
        page.click("button:has-text(\"登录\")")
        # Go to http://localhost/shopxo/admin.php?s=/index/index.html
        page.goto("http://localhost/shopxo/admin.php?s=/index/index.html")

        assert page.url == 'http://localhost/shopxo/admin.php?s=/index/index.html'