"""截图库存"""
import asyncio
from playwright.async_api import async_playwright
import os, sys
sys.stdout.reconfigure(encoding='utf-8')
BASE = os.path.dirname(os.path.abspath(__file__))
URL = 'http://localhost:8899/dashboard.html'

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page(viewport={'width': 1400, 'height': 950})
        await page.goto(URL, wait_until='networkidle')
        await asyncio.sleep(3)
        
        # 库存总览
        await page.click('button[data-m="inv"]')
        await asyncio.sleep(2)
        await page.screenshot(path=os.path.join(BASE, 'ss_inv_all.png'), full_page=True)
        print('ss_inv_all.png')
        
        # 选一个门店
        await page.select_option('#invStore', '万达店')
        await asyncio.sleep(2)
        await page.screenshot(path=os.path.join(BASE, 'ss_inv_store.png'), full_page=True)
        print('ss_inv_store.png')
        
        await browser.close()

asyncio.run(main())
