compare: pass url as command argument

This commit is contained in:
Corentin Sechet 2022-03-21 17:00:25 +01:00
parent 9a37473f93
commit 566b9ae239
2 changed files with 6 additions and 4 deletions

4
TODO
View File

@ -1,6 +1,6 @@
* Make a compare subcommand
* Pass url to compare as command argument
* Pass screenshots directory as command arguments
* See how to pass css overwrite options efficiently to command line
* Take screenshot of page with and without overwritten CSS
* Compare CSS for differences
* Compare output image for differences
* Pass resolution as command argument

View File

@ -1,5 +1,6 @@
from asyncio import run
from click import group
from click import argument
from click import pass_context
from functools import update_wrapper
from playwright.async_api import Route
@ -32,15 +33,16 @@ async def get_css(route: Route) -> None:
@cli.command()
@argument('url', type=str)
@pass_context
@async_command
async def compare(ctx):
async def compare(ctx, url):
async with async_playwright() as p:
browser = await p.firefox.launch()
context = await browser.new_context()
await context.route(re_compile(r'.*\.css(.map)?.*'), get_css)
page = await context.new_page()
await page.goto("https://demarches.auch.fr/")
await page.goto(url)
screenshot_bytes = await page.screenshot()
with open('/home/csechet/screenshot.png', 'wb') as screenshot_file:
screenshot_file.write(screenshot_bytes)