-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
chore: use playwright for e2e test #5663
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pull Request Test Coverage Report for Build 6584873773
💛 - Coveralls |
xiaoiver
force-pushed
the
feat-playwright
branch
from
October 25, 2023 03:54
a17135f
to
1cfb102
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
使用 Playwright 进行截图测试,代替原有的 node-canvas / headless-gl,好处如下:
需要注意该方案并不能完全代替已有的 node-canvas / headless-gl / JSDOM 服务端渲染方案,只是更适合做 e2e 测试。
另外也不能代替 Jest 做单元测试以及统计代码覆盖率。
详细方案如下:
启动开发服务器
Playwright 提供了test-webserver 用于在测试开始前启动服务器
访问页面并截图
在测试用例中截取
<canvas>
,与基准图片进行对比:为了确保截图时机准确,例如渲染完成后立刻触发截图,使用 exposeFunction 向页面中 window 对象挂载 screenshot 方法:
这样在浏览器的测试页面中就可以随时调用该方法,例如渲染完成后:
上传截图结果报告
跑 e2e.yml 后回上传 Playwright 的截图测试报告到 artifact 中:
动画测试
核心思路还是使用 G 提供的 Animation API 精确控制动画流程,需要在页面中 window 对象上挂载 goTo 方法,然后在测试用例中调用。Playwright 提供了 evaluate 方法用于执行页面中的方法:
问题记录
import ESM 报错
Playwright 设计成只允许执行 CJS,也不提供 ESM -> CJS 的转译,因此没有提供类似 Jest 的
transformIgnorePatterns
。这就导致测试用例中类似
d3-*
这样的依赖会报错:目前的解决方式来自:microsoft/playwright#7121 (comment)
截图高度 1px 误差
关于基准图片生成,由于 Chrome 在不同操作系统环境下截图存在不一致现象(例如高度多 1px),甚至官方也推荐在 CI 环境截图:
我自己测试下来造成截图 1px 误差的原因来自
<canvas>
在页面中的位置坐标不为整数,设置上面的一排 UI 高度为整数可以解决: