async def test_request_token_permissions(
    app, browser, permissions_str, granted, user_special_chars
):
    """verify request token with the different options"""

    user = user_special_chars.user
    # open the token page
    await open_token_page(app, browser, user)
    scopes_input = browser.get_by_label("Permissions")
    await scopes_input.fill(permissions_str)
    request_button = browser.locator('//button[@type="submit"]')
    await request_button.click()

    if isinstance(granted, str):
        expected_error = granted
        granted = False

    if not granted:
        error_dialog = browser.locator("#error-dialog")
        await expect(error_dialog).to_be_visible()
        error_message = await error_dialog.locator(".modal-body").text_content()
        assert "API request failed (400)" in error_message
        assert expected_error in error_message
        await error_dialog.locator("button[aria-label='Close']").click()
        await expect(error_dialog).not_to_be_visible()
        return

    await browser.reload(wait_until="load")

    # API Tokens table: verify that elements are displayed
    api_token_table_area = browser.locator("div#api-tokens-section")
    await expect(api_token_table_area.get_by_role("table")).to_be_visible()
    await expect(api_token_table_area.locator("tr.token-row")).to_have_count(1)

    # getting values from DB to compare with values on UI
    assert len(user.api_tokens) == 1
    orm_token = user.api_tokens[-1]
    assert set(orm_token.scopes) == granted

    permissions_on_page = (
        await api_token_table_area.locator("tr.token-row")
        .get_by_role("cell")
        .nth(1)
        .locator('//pre[@class="token-scope"]')
        .all_text_contents()
    )
    # specifically use list to test that entries don't appear twice
    assert sorted(permissions_on_page) == sorted(granted)
verify request token with the different options
jupyterhub/tests/browser/test_browser.py