async def open_admin_page(app, browser, login_as=None):
    """Login as `user` and open the admin page"""
    admin_page = url_escape(app.base_url) + "hub/admin"
    if login_as:
        user = login_as
        url = url_path_join(
            public_host(app), app.hub.base_url, "/login?next=" + admin_page
        )
        await browser.goto(url)
        await login(browser, user.name, password=str(user.name))
        await expect(browser).to_have_url(re.compile(".*/hub/admin"))
    else:
        # url = url_path_join(public_host(app), app.hub.base_url, "/login?next=" + admin_page)
        await browser.goto(admin_page)
        await expect(browser).to_have_url(re.compile(".*/hub/admin"))
    await browser.wait_for_load_state("networkidle")
Login as `user` and open the admin page
jupyterhub/tests/browser/test_browser.py