playwright——好用的测试工具

1,playwright支持使用node.js、python、java方式进行使用
        下面是playwright网站

Installation | Playwrighticon-default.png?t=N7T8https://playwright.dev/docs/intro#introduction

2,在python里面使用的话是比较方便的
       

pip install pytest-playwright

playwright install

使用上面的命令就可以配置好python使用playwright了
 

import re
from playwright.sync_api import Page, expect

def test_has_title(page: Page):
    page.goto("https://playwright.dev/")

    # Expect a title "to contain" a substring.
    expect(page).to_have_title(re.compile("Playwright"))

def test_get_started_link(page: Page):
    page.goto("https://playwright.dev/")

    # Click the get started link.
    page.get_by_role("link", name="Get started").click()

    # Expects page to have a heading with the name of Installation.
    expect(page.get_by_role("heading", name="Installation")).to_be_visible()

这是一个demo可以使用

3,使用node可以使用命令一键生成项目


npm init playwright@latest

yarn create playwright

pnpm create playwright

这是关于nodejs创建playwright项目的命令
 

在生成的项目内的路径C:\myfile\Files\demo-file\tests(这里是以我的路径为展示)
 

import { test, expect } from '@playwright/test';

// 设置测试超时时间为 120 秒
test.beforeEach(async () => {
  test.setTimeout(120000); 
})
test('has title', async ({ page }) => {
  await page.goto('https://playwright.dev/',{waitUntil:'domcontentloaded'});
  // Expect a title "to contain" a substring.
  await expect(page).toHaveTitle(/Playwright/);
});

test('get started link', async ({ page }) => {
  await page.goto('https://playwright.dev/',{waitUntil:'domcontentloaded'});
  // Click the get started link.
  await page.getByRole('link', { name: 'Get started' }).click();

  // Expects page to have a heading with the name of "Get started".
  await expect(page.getByRole('heading', { name: 'Get started' })).toBeVisible();
});

按照这个可以解决上面has title的超时报错问题
不过目前还有出现
 expect(page.getByRole('heading', { name: 'Get started' })).toBeVisible();
默认调用出现超时5秒的情况,在后面给配置timeout就会对应显示报错时长

4,关于java版本的目前还未尝试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值