0

I'm using playwright to run a UI test. This test request to get a URL, login, and then check the page content. As a start I just tried to login and capture the

import keyring

import asyncio
from playwright.async_api import async_playwright,Page, expect
from utils.util import get_logger
logger = get_logger(__name__)



async def login_to_dashboard():
    
    url = r"https://mytesturl"
    credential = keyring.get_credential("webpage", None)
    username = credential.username
    password = credential.password

    async with async_playwright() as playwright:
        browser = await playwright.chromium.launch(channel="chrome",headless=False)
        context = await browser.new_context()
        page = await context.new_page()
        await page.goto(url)
        await page.locator("[placeholder=\"Username\"]").fill(username)
        await page.locator("[placeholder=\"Password\"]").fill(password)
        await page.locator("input:has-text(\"Sign In\")").click()
        html1 = await page.content()
        await page.screenshot(path="o.png")

        #logger.info(html1)
        url = page.url
        logger.info(url)
        
        
        await context.storage_state(path='login_data.json')


if __name__ == "__main__":
    asyncio.run(login_to_dashboard())

I run it from python command line. I can see chrome start up, id/password filled in and immediately the chrome page disappeared. My page.screenshot(path="o.png") captured the screenshot but this is the screenshot before login, while my expectation is it should capture the screenshot after login as I await page.locator("input:has-text(\"Sign In\")").click().

Can you please advise if I misunderstood anything here?

martineau
  • 119,623
  • 25
  • 170
  • 301
Ginger_Chacha
  • 317
  • 1
  • 11

0 Answers0