老实说,我很惊讶它以这种方式工作......我想说“不,这不是一个好习惯......”但在玩了几分钟后,我没有发现这样做有任何缺点它。
但我仍然不会这样做,因为如果你放在expect()
块it()
中,很容易看到你的测试中的逻辑顺序(例如打开页面->期望 smtng;单击按钮->期望 smtng;等)
但是你可以实现它,使用它一段时间,看看它是否适合你自己
PS只是为了形象化为什么我认为这不是一个可怕的想法,因为它看起来可能是:拥有以下代码
beforeAll(async () => {expect(true).toBe(false)});
it("1", async () => {
});
it("2", async () => {
});
it("3", async () => {
});
将产生以下输出
Suite: UCare - Provider Search - 'Places' tab
✗ 1 (0.002 sec)
- Expected true to be false.
at UserContext.beforeAll (/Users/spleshakov/Documents/ui-automation/protractor/custom_implementation/test.spec.js:11:38)
at /Users/spleshakov/Documents/ui-automation/node_modules/jasminewd2/index.js:112:25
at new Promise (<anonymous>)
at SimpleScheduler.promise (/Users/spleshakov/Documents/ui-automation/node_modules/selenium-webdriver/lib/promise.js:2242:12)
at schedulerExecute (/Users/spleshakov/Documents/ui-automation/node_modules/jasminewd2/index.js:95:18)
at promise (/Users/spleshakov/Documents/ui-automation/node_modules/selenium-webdriver/lib/promise.js:2232:22)
at new Promise (<anonymous>)
✗ 2 (1 sec)
- Expected true to be false.
at UserContext.beforeAll (/Users/spleshakov/Documents/ui-automation/protractor/custom_implementation/test.spec.js:11:38)
at /Users/spleshakov/Documents/ui-automation/node_modules/jasminewd2/index.js:112:25
at new Promise (<anonymous>)
at SimpleScheduler.promise (/Users/spleshakov/Documents/ui-automation/node_modules/selenium-webdriver/lib/promise.js:2242:12)
at schedulerExecute (/Users/spleshakov/Documents/ui-automation/node_modules/jasminewd2/index.js:95:18)
at promise (/Users/spleshakov/Documents/ui-automation/node_modules/selenium-webdriver/lib/promise.js:2232:22)
at new Promise (<anonymous>)
✗ 3 (0.907 sec)
- Expected true to be false.
at UserContext.beforeAll (/Users/spleshakov/Documents/ui-automation/protractor/custom_implementation/test.spec.js:11:38)
at /Users/spleshakov/Documents/ui-automation/node_modules/jasminewd2/index.js:112:25
at new Promise (<anonymous>)
at SimpleScheduler.promise (/Users/spleshakov/Documents/ui-automation/node_modules/selenium-webdriver/lib/promise.js:2242:12)
at schedulerExecute (/Users/spleshakov/Documents/ui-automation/node_modules/jasminewd2/index.js:95:18)
at promise (/Users/spleshakov/Documents/ui-automation/node_modules/selenium-webdriver/lib/promise.js:2232:22)
at new Promise (<anonymous>)
可以看出,报告正在正常打印,其中每个失败都显示为单独的it()
测试用例失败