标签: playwright

如何使用剧作家/测试运行程序生成 Allure HTML 报告?

如何使用剧作家/测试运行程序生成 Allure HTML 报告?

我们计划使用 Nodejs、Typescript 和 Playwright 推荐的测试运行程序 (playwright/test),但无法找到任何有关如何使用上述技术堆栈生成 Allure HTML 报告的文档。还有其他报告格式,例如 json 和 junit,但我们希望生成 Allure HTML 报告,并希望附加失败测试用例的屏幕截图和视频。任何参考都会非常有帮助。

html allure playwright

4
推荐指数
1
解决办法
5917
查看次数

剧作家 waitForResponse 如何等待响应文本“完成”

我有一个场景,其中 API 接收多个响应(一次一个)并在 UI 上呈现。API 继续轮询数据库,直到接收完所有响应为止。我需要我的脚本等待 API 响应变为“完成”。我尝试了下面的代码,但它没有等到状态完成。

const response = await page.waitForResponse(response => response.url().includes('https://services/url') && response.status() === 200);

console.log('RESPONSE ' + (await response.body()));
Run Code Online (Sandbox Code Playgroud)

以下是记录的响应

{
  "transactionDetail": {
    "transactionID":"866f357f-7541-4ff2-b879-61ca284513a7",
    "transactionTimestamp":"2021-08-02T10:48:50.372207",
    "inLanguage":"en-US",
    "serviceVersion":"1"
  },
  "resultSummary":{
    "inputCount":1,
    "successCount":1,
    "failureCount":0},
    "inquiryDetail": {
      "kaseIterationId":"8a7b11547af8835d017b067ad06e04ba"
    },
  },
  "response":"InProgress"
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能让我的脚本等到“响应”变成“已完成”而不是“进行中”。

automated-tests typescript protractor angular playwright

4
推荐指数
1
解决办法
2万
查看次数

剧作家“元素未附加到 DOM”

我正在尝试使用 Playwright (.NET) 抓取一个网站。该网站看起来像是在 2000 年代初编写的(以怪异模式等运行),而我遇到了一个我似乎无法找到解决方案的问题。

我的目标是选中一个复选框。我可以input使用选择元素

var input = await page.QuerySelectorAsync("inputSelector")
Run Code Online (Sandbox Code Playgroud)

该元素已成功选择,但在尝试运行时await input.CheckAsync(),出现错误Element is not attached to the DOM。我没有注意到会导致这种情况的元素有任何异常。为什么会发生此错误?

更新

await page.ClickAsync("inputSelector")我通过运行来检查该框来使其工作。这适用于我的目的,但它不能解释为什么如果以其他方式完成它会出错,所以我仍然想知道为什么会发生该错误。

c# webautomation playwright playwright-sharp playwright-dotnet

4
推荐指数
1
解决办法
7775
查看次数

在 Azure Function 中运行 Playwright .NET (Windows)

将其发布到 Azure 云后,我无法运行调用剧作家测试的 azure 函数。

\n

异常如下

\n
    Playwright Test or Playwright was just installed or updated. \n\xe2\x95\x91 \xe2\x95\x91 Please run the following command to download new browsers: \xe2\x95\x91 \xe2\x95\x91 \n\xe2\x95\x91 \xe2\x95\x91 playwright install \xe2\x95\x91 \xe2\x95\x91 \n\xe2\x95\x91 \xe2\x95\x91 <3 Playwright Team \xe2\x95\x91\n
Run Code Online (Sandbox Code Playgroud)\n

问题是我不知道如何运行playwright install

\n

有一些远程构建的可能性,但文档不包含详细信息。

\n

所以我尝试遵循

\n
    \n
  1. 将 chrome 浏览器复制%USERPROFILE%\\AppData\\Local\\ms-playwright\\chrome-win到项目文件夹中。
  2. \n
  3. 将 chrome-win 文件夹附加到项目中。
  4. \n
  5. 更新.csproj后 chrome 浏览器将位于输出目录并输出 zip
  6. \n
\n
<ItemGroup>\n  <Content Include="chrome-win\\**">\n     <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\n  </Content>\n</ItemGroup>\n
Run Code Online (Sandbox Code Playgroud)\n
    \n …

azure-functions playwright

4
推荐指数
1
解决办法
3378
查看次数

如何使用 Playwright 运行 e2e Angular 测试?

我想使用Playwright为我的 Angular 应用程序运行端到端 (e2e) 浏览器测试。然而,截至 2021 年 11 月,我尚未找到 Playwright 的 Angular 示意图。

例如, Cypress有一个官方的 Angular Schematic 。这使得可以使用以下命令运行赛普拉斯 e2e 测试:

ng e2e
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以在不编写 Angular 原理图的情况下使用 Playwright 运行 Angular e2e 测试?或者我错过了 Playwright 的 Angular 示意图吗?

e2e-testing angular-cli angular angular-schematics playwright

4
推荐指数
1
解决办法
6945
查看次数

我如何等待所有 xhr 请求完成

我单击触发 http 请求的按钮\n并且我希望能够在请求完成后关闭页面。

\n

示例:\nAwait page.click(触发http请求的某个按钮)

\n

我已经尝试过:Await page.waitForLoadState()\nWith \xe2\x80\x9cload\xe2\x80\x9d 和 \xe2\x80\x9cnetworkidle\xe2\x80\x9d 并且它不起作用。\n对于加载页面,没有关闭请求完成并等待网络空闲直到超时。

\n

我希望能够等待后台所有的xhr请求完成

\n

playwright

4
推荐指数
2
解决办法
1万
查看次数

剧作家强制点击隐藏元素不起作用

我正在使用 Playwright 进行端到端测试。其中一种场景涉及检查 PDFviewer 窗口中显示的 pdf 内容,该窗口的下载按钮已对最终用户隐藏。检查 pdf 内容需要下载它,因此我使用\nforce文档提到的选项:\n https://playwright.dev/docs/api/class-page#page-click

\n

使用的实现如下:

\n
innerFrameContent.click("//button[contains(@id, \'secondaryDownload\')]", { force: true })\n
Run Code Online (Sandbox Code Playgroud)\n

(xpath是正确的,我在Chrome浏览器中检查并设法通过控制台单击该元素)

\n

不幸的是,我从 Playwright 收到以下异常日志:

\n
frame.click: Element is not visible\n=========================== logs ===========================\nwaiting for selector "//button[contains(@id, \'secondaryDownload\')]"\n  selector resolved to hidden <button tabindex="54" title="Download" id="secondaryDown\xe2\x80\xa6>\xe2\x80\xa6</button>\nattempting click action\n  waiting for element to be visible, enabled and stable\n    forcing action\n  element is visible, enabled and stable\n  scrolling into view if needed\n============================================================\n...\n
Run Code Online (Sandbox Code Playgroud)\n

javascript node.js playwright

4
推荐指数
1
解决办法
2万
查看次数

无法在 MacOS 和 ubutunOS 上从“playwright.sync_api”导入名称“sync_playwright”

我正在尝试导入剧作家框架。但是,我遇到了以下问题:

Traceback (most recent call last):
  File "simple.py", line 1, in <module>
    from playwright.sync_api import sync_playwright
ImportError: cannot import name 'sync_playwright' from 'playwright.sync_api' (/home/acid/dev/play/venv
/lib/python3.8/site-packages/playwright/sync_api.py)
Run Code Online (Sandbox Code Playgroud)

我已经通过以下命令安装了剧作家:

pip install playwright==1.8.0a1
playwright install
Run Code Online (Sandbox Code Playgroud)

然后,运行脚本:

from playwright.sync_api import sync_playwright

    with sync_playwright() as p:
        for browser_type in [p.chromium, p.firefox, p.webkit]:
            browser = browser_type.launch()
            page = browser.new_page()
            page.goto('http://whatsmyuseragent.org/')
            page.screenshot(path=f'example-{browser_type.name}.png')
            browser.close()
Run Code Online (Sandbox Code Playgroud)

然而,仍然没有成功。对于这个问题你有什么建议吗?提前致谢

python playwright

4
推荐指数
2
解决办法
1万
查看次数

Playwright URL 配置 - 多个应用程序和不同基本 URL 的环境变量

为项目配置和使用 url 的最佳方法是什么

  • 2x 网络应用程序
  • 3x 环境

...作为示例,我们有这样的情况

水果应用程序

  • 基本网址:
    • dev.fruits.com
    • test.fruits.com
    • prod.fruits.com
  • 端点:
    • /香蕉/
    • /猕猴桃/
    • /苹果/

色彩应用程序

  • 基本网址:
    • dev.colors.com
    • test.colors.com
    • prod.colors.com
  • 端点:
    • /红色的/
    • /蓝色的/
    • /绿色的/

...和这样的测试


    test('Navigate to fruits/banana', async () => {
      await page.goto('https://https://dev.fruits.com/banana/');
      ...
    });
     
    test('Navigate to colors/red', async () => {
      await page.goto('https://https://dev.colors.com/red/');
      ...
    });

Run Code Online (Sandbox Code Playgroud)

...我想去的地方

  1. 将 dev.fruits.com 和 dev.colors.com 替换为 baseurl 变量
  2. “dev”部分应该是动态的,具体取决于我运行测试的环境

automated-tests base-url playwright

4
推荐指数
1
解决办法
7774
查看次数

Playwright - 在测试之间共享状态

我正在同时学习 Playwright 和 JavaScript,所以这可能是一个基本问题 - 我想知道人们如何建议customerId在测试之间共享状态 - 在这种情况下是变量。

例子:

test.describe.only('Generate a new customer', () => {
  let customerId
  let baseUrl = process.env.SHOP_URL
  
  test('Create new customer', async ({ request }) => {
    const response = await request.post(baseUrl +    `/shopify/v5/customer`, {})
    
    const responseBody = JSON.parse(await response.text())
    expect(response.status()).toBe(200)
    customerId = responseBody.customerId //need to persist customerId to pass into following test

  })

  test('Update customer details', async ({ request }) => {
     const response = await request.post(baseUrl +    `/shopify/v5/customer/update`, {})
      {
        data: { …
Run Code Online (Sandbox Code Playgroud)

javascript playwright

4
推荐指数
1
解决办法
9904
查看次数