Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggest ] 建议 playwright的进程被ctrl +c 或者vscode 插件 关闭后,monocart-reporter仍输出报告 #117

Open
jiawen94 opened this issue May 10, 2024 · 10 comments

Comments

@jiawen94
Copy link

现状:
使用微软的默认的html测试报告,当我将playwright的npx进程ctrl+c 杀掉(或者vscode 插件的中止按钮)后,仍然会出现测试报告;
image

使用monocart-reporter进行测试,如果ctrl+c 杀进程(或者vscode 插件的中止按钮),monocart-reporter不会生成报告
期望:
使用monocart-reporter进行测试,如果ctrl+c 杀进程(或者vscode 插件的中止按钮),monocart-reporter也生成报告。
因为就算是手工终断playwright,我也想看到前面运行过的test cases的报告详情

@cenfun
Copy link
Owner

cenfun commented May 11, 2024

试了一下,ctrl+c 杀进程,好像不行,官方的html报告也没有,你确定不是之前的html缓存?
如果是点停止按钮,我不知道你说的是在哪的停止,我得看下能不能重现
如果从一般情况来说,进程都终止了,是不可能继续运行任何代码的,难道是实时生成的报告?

@jiawen94
Copy link
Author

电脑不在身边,这个我明后天验证一下

@jiawen94
Copy link
Author

jiawen94 commented May 13, 2024

中途ctrl+c后会提示Terminate batch job (Y/N)? ,我输入y继续中断
测试前删除过playwright-report文件夹,测试后也检查过报告的测试时间,应该不是之前的缓存。
我简单设计了三个case,在第二个case进行了暂停。官方html报告能正常输出

PS C:\Users\aaa\test-netone-playwright> npx playwright test test-1.spec.ts  --project debug  --trace off
global setup                        
browserName:  Chrome
browserType:  chromium
browserVersion:  123.0.6312.4
apiRequestContext.get: Invalid URL
    at globalSetup (C:\Users\aaa\test-netone-playwright\lib\common\global-setup.ts:72:38) {
  name: 'TypeError'
}

Running 3 tests using 1 worker

  ✓  1 [debug] › test-1.spec.ts:3:5 › test0 (2.6s)
  ✘  2 [debug] › test-1.spec.ts:11:5 › test1 (2.2s)
global teardown
Thanks


  1) [debug] › test-1.spec.ts:11:5 › test1 ─────────────────────────────────────────────────────────

    Test was interrupted.

    Error: locator.click: Test ended.
    Call log:
      - waiting for locator('#kw')
      -   locator resolved to <input id="kw" value="" name="wd" class="s_ipt" maxleng…/>
      - attempting click action
      -   waiting for element to be visible, enabled and stable
      -   element is visible, enabled and stable
      -   scrolling into view if needed
      -   done scrolling
      -   performing click action


      11 | test('test1', async ({ page }) => {
      12 |   await page.goto('https://www.baidu.com/');
    > 13 |   await page.locator('#kw').click();
         |                             ^
      14 |
      15 |   await page.waitForTimeout(5_000)
      16 |   await page.locator('#kw').fill('hehehe');

        at C:\Users\aaa\test-netone-playwright\tests\test-1.spec.ts:13:29

    attachment #1: screenshot (image/png) ──────────────────────────────────────────────────────────
    test-results\test-1-test1-debug\test-failed-1.png
    ────────────────────────────────────────────────────────────────────────────────────────────────

  1 interrupted
    [debug] › test-1.spec.ts:11:5 › test1 ──────────────────────────────────────────────────────────
  1 did not run
  1 passed (9.4s)

To open last HTML report run:

  npx playwright show-report

Terminate batch job (Y/N)? y
PS C:\Users\aaa\test-netone-playwright> npx playwright show-report

  Serving HTML report at http://localhost:9323. Press Ctrl+C to quit.
^C^CTerminate batch job (Y/N)?
^C

image
image

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

test('test0', async ({ page }) => {
  await page.goto('https://www.baidu.com/');
  await page.locator('#kw').click();
  await page.locator('#kw').fill('playwright');
  await page.getByRole('button', { name: '百度一下' }).click();

});

test('test1', async ({ page }) => {
  await page.goto('https://www.baidu.com/');
  await page.locator('#kw').click();

  await page.waitForTimeout(5_000)
  await page.locator('#kw').fill('hehehe');
  await page.getByRole('button', { name: '百度一下' }).click();


});

test('test2', async ({ page }) => {
  await page.goto('https://www.baidu.com/');
  await page.locator('#kw').click();


  await page.waitForTimeout(5_000)
  await page.locator('#kw').fill('hehehe');
  await page.getByRole('button', { name: '百度一下' }).click();
});

不过使用vscode的插件中途停止,有时候(小概率)确实是获取不到官方的报告
20240513-103731

@cenfun
Copy link
Owner

cenfun commented May 13, 2024

我也是测试之前删除html的文件夹,ctrl+c后并没有产生任何html的文件

  • 一次ctrl+c后输入y终止试过
  • 连续多次ctrl+c终止也试过

不知道你用的什么playwright版本和操作系统,还有nodejs版本,还有用的什么终端,比如cmd(是否开启管理员模式)?不知道和这些有没有关系
要不,你把你这个简单例子提交到一个仓库吧,我clone下来按照你的步骤试试
如果能重现,应该追踪html的实现方式,谢谢

@jiawen94
Copy link
Author

好的,仓库准备好了跟你说下
版本信息:
node: 20.10
Playwright Test v1.42.1
windows11

终端为vscode底下的windows powershell终端(未开管理员模式)

@jiawen94
Copy link
Author

jiawen94 commented May 13, 2024

@cenfun
Copy link
Owner

cenfun commented May 13, 2024

看起来好像真的可以,你这个仓库,我按ctrl+c就立即显示To open last HTML report run说明已经触发了生成报告
我研究一下,谢谢这个例子

@cenfun
Copy link
Owner

cenfun commented May 13, 2024

然后,我增加了'monocart-reporter'好像也可以触发,只是稍微慢一点,要不你也试试?

Running 3 tests using 1 worker

  ✘  1 [debug] › test-1.spec.ts:3:5 › test0 (727ms)
终止批处理操作吗(Y/N)?
  1 interrupted
    [debug] › test-1.spec.ts:3:5 › test0 ───────────────────────────────────────────────────────────
  2 did not run
[MR] generating report data ...
[MR] generating test report ...
[MR] My Report
┌─────────────┬────────────────────┐
│ Tests       │ 3                  │
│ ├ Passed    │ 0 (0.0%)           │
│ ├ Flaky     │ 0 (0.0%)           │
│ ├ Skipped   │ 3 (100.0%)         │
│ └ Failed    │ 0 (0.0%)           │
│ Steps       │ 14                 │
│ Suites      │ 1                  │
│ ├ Projects  │ 1                  │
│ ├ Files     │ 1                  │
│ ├ Describes │ 0                  │
│ └ Shards    │ 0                  │
│ Retries     │ 0                  │
│ Errors      │ 0                  │
│ Logs        │ 0                  │
│ Attachments │ 2                  │
│ Artifacts   │ 0                  │
│ Playwright  │ v1.42.1            │
│ Date        │ 2024/5/13 11:33:56 │
│ Duration    │ 2.1s               │
└─────────────┴────────────────────┘
[MR] html report: test-results/report.html (json: test-results/report.json)
[MR] view report: npx monocart show-report test-results/report.html

To open last HTML report run:

  npx playwright show-report

y

而我自己的项目,好像无论是html还是monocart都没有触发报告
我感觉是playwright本身的问题,因为无论是自定义报告,还是官方的报告,实际上就是监听回调事件执行而已,这个回调事件得playwright内核通知到报告才行

  • 如果通知了,无非是先后执行的问题,html顶多在monocart前面执行(可能是按照配置的顺序,你试试调一下)
  • 如果没有通知,那么就应该都没有通知,总不可能偏心,只通知自带的html,而不通知第三方自定义的(毕竟不是亲生的)
  • 还有可能是终止后的条件限制,毕竟终止了,不允许运行太多太长的任务,可能就被进程或playwright掐掉了也不一定(ctrl+c后可以连续按,也可以迅速按y,也可以等一会按y,这两个操作之间时间间隔可能就是处理报告的极限时间)

但目前来说,我还没有找到html里面有什么特别的代码来处理这个特殊情况,当然,html报告应该比monocart快,毕竟里面的功能和要处理的任务不同,也许你按得快,时间只够处理html的报告

@jiawen94
Copy link
Author

在这个demo里面,我加了monocart-reporter,ctrl+c也能输出报告。而我自己的项目里面却无法输出报告,不清楚是不是项目里面增加了一些功能模块而触发了“ctrl+c中断无法输出报告”的问题。这个复现条件蛮奇怪的,我后面按照你的分析思路验证一下

@cenfun
Copy link
Owner

cenfun commented May 13, 2024

嗯,谢谢,我也会继续研究一下,感觉还是执行时间限制的问题,如果工作量大,就来不及执行所有的任务

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants