def reporting_fixture(browser: Browser, request): p: Page = browser.newPage() # browser.newPage(videosPath="video/") p.context.clearCookies() yield p screenshot = p.screenshot(path=f"screenshots/{request.node.name}.png", fullPage=True) # video = p.video.path() p.close() allure.attach(screenshot, name=f"{request.node.name}", attachment_type=allure.attachment_type.PNG)
def logout_fixture(browser: Browser, request): p: Page = browser.newPage() # browser.newPage(videosPath="video/") p.context.clearCookies() yield p # Logout # main_page = MainPage(base_url, p) # if p.innerText(main_page.account_button(username).selector) is not None or "": # settings_page = main_page.open_settings() # settings_page.logout() screenshot = p.screenshot(path=f"screenshots/{request.node.name}.png", fullPage=True) # video = p.video.path() p.close() allure.attach(screenshot, name=f"{request.node.name}", attachment_type=allure.attachment_type.PNG)
def test_sync_download(browser: Browser, server): server.set_route( "/downloadWithFilename", lambda request: ( request.setHeader("Content-Type", "application/octet-stream"), request.setHeader("Content-Disposition", "attachment; filename=file.txt"), request.write(b"Hello world"), request.finish(), ), ) page = browser.newPage(acceptDownloads=True) page.setContent(f'<a href="{server.PREFIX}/downloadWithFilename">download</a>') with page.expect_event("download") as download: page.click("a") assert download.value assert download.value.suggestedFilename == "file.txt" path = download.value.path() assert os.path.isfile(path) with open(path, "r") as fd: assert fd.read() == "Hello world" page.close()