Skip to content

Latest commit

 

History

History

playwright_sample

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

使用文档

  • 安装依赖
> pip install pytest-playwright
  • 安装浏览器
> playwright install chromium
  • 运行sample
> pytest --browser=chromium --headed test_playwright.py

playwright中使用poium

poium 本质上是一种模式,或者叫语法糖,所以,他不局限于selenium/appium,很高兴告诉你poium同样支持 playwright。

import re
from playwright.sync_api import expect
from poium.playwright import Page, Locator


class BingPage(Page):
    search_input = Locator('id=sb_form_q', describe="bing搜索框")
    search_icon = Locator('id=search_icon', describe="bing搜索按钮")


def test_playwright(page):
    # 获得元素
    page.goto("https://cn.bing.com")
    bp = BingPage(page)
    bp.search_input.highlight()
    bp.search_input.fill("playwright")
    bp.search_icon.highlight()
    bp.search_icon.screenshot(path="./image/search_icon.png")
    bp.search_icon.click()

    # 断言URL
    expect(page).to_have_title(re.compile("playwright"))