test: cleanup test codes, use fixtures
This commit is contained in:
1 parent
ed84aeb78b
commit
38305f533b
5 files changed
+158
-74
No files matched your search
@@ -0,0 +1,31 @@
|
||||
export default class TestUtil {
|
||||
constructor(page, testInfo, testScreenshotPath) {
|
||||
this._page = page
|
||||
this._testInfo = testInfo
|
||||
this._testScreenshotPath = testScreenshotPath
|
||||
}
|
||||
|
||||
async captureScreenshot(pageInstance, screenshotName) {
|
||||
if (!pageInstance) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const screenshotPath = `${this._testScreenshotPath}/${screenshotName || `unknown_${Date.now()}`}.png`
|
||||
|
||||
await pageInstance.screenshot({ path: screenshotPath })
|
||||
} catch (error) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
async onTestError(error) {
|
||||
const titleLists = [...this._testInfo.titlePath]
|
||||
titleLists.shift()
|
||||
const title = titleLists.join('-')
|
||||
|
||||
await this.captureScreenshot(this._page, `${title}_${Date.now()}`)
|
||||
|
||||
return new Error(error)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user