[英]Testcafe - beforeAll and afterAll tests in a file or all files
如果我有 3 個測試文件,每個文件都有幾個固定裝置和測試,就像這樣
file1.js
fixture1
test1
test2
fixture2
test3
test4
file2.js
fiture3
test5
test6
fixture4
test7
test8
file3.js
fixture5
test9
test10
test11
fixture6
test12
test13
我發現我可以對某個固定裝置使用fixture.after()
和fixture.before()
。 我可以使用test.after()
和test.before()
進行某個測試。
如果我想給file2.js設置環境,當file2.js中的所有測試(test5、test6、test7、test8)執行完后clean, testcafe
有沒有這樣的功能?
如果我想為所有文件設置環境,並在所有測試執行時清理它, testcafe
有沒有這樣的功能?
謝謝
在閱讀了 vasily.strelyaev 提供的測試運行前后的 Hooks 之后,我創建了.testcaferc_seq.js
並添加了"test": "./node_modules/.bin/testcafe chrome --sf./integration_tests/file2.js --live --config-file.testcaferc_seq.js"
在 package.json。
.testcaferc_seq.js
是
const utils = require ("integration_tests/utils/afterAllTestRunner.js");
module.exports = {
hostname: "localhost",
...
// before all and after all tests
hooks: {
testRun: {
before: async ctx => {
console.log("---------------- \n before all tests \n ---------------------");
utils.cleanUsers();
},
after: async ctx => {
console.log("---------------- \n after all tests \n ---------------------");
utils.cleanUsers();
},
},
},
}
然而,鈎子並沒有起作用,我從兩個console.log(...)
中看不到這兩句話。 我錯過了什么?
還有一個問題,如果我想控制瀏覽器(比如chrome)做一些pre/post testRun的步驟,怎么辦?
目前沒有內置方法可以在特定文件中的第一個 fixture 開始之前以及該文件中的最后一個 fixture 結束之后運行掛鈎。 作為一種解決方法,您可以將此文件中的所有測試放在一個夾具中並指定其 hooks 。 或者,如果可以在您的場景中多次運行掛鈎代碼,您可以使用設置和拆卸代碼創建輔助函數,並從每個夾具的單獨掛鈎調用這些函數。
至於你的第二個問題,是的,你可以使用全局測試運行掛鈎在第一個測試開始之前設置環境並在所有測試完成后清理它: https://testcafe.io/documentation/403435/guides/intermediate-指南/鈎子#hooks-before-and-after-test-runs 。
您可以在我們的 Hooks 指南中找到更多信息: https://testcafe.io/documentation/403435/guides/intermediate-guides/hooks 。
讀取配置文件可能存在一些問題。 查看控制台,您將看到:
An error has occurred while reading the "....testcaferc.js" configuration file.
這就是全局掛鈎不起作用的原因。 這個錯誤可能是由integration_tests/utils/afterAllTestRunner.js
模塊引起的。 嘗試在不使用它的情況下運行它。
關於 testRun 掛鈎之前/之后的瀏覽器操作。 這是不支持的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.