如何仅在夹具级别而不是针对该夹具下的每个测试执行“每次测试之前" [英] How to do 'beforeEach' only at Fixture level and not for each test under that fixture

查看:93
本文介绍了如何仅在夹具级别而不是针对该夹具下的每个测试执行“每次测试之前"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在灯具级别运行"beforeEach",而不要在该灯具下运行每个测试

I want to run 'beforeEach' only at the fixture level and not for each test under that fixture

fixture `Fixture A for Use Case1`
   .beforeEach(login)

test('A Test 1', async t => {
      await t 
      ---
    }); 

test('A Test 2', async t => {
      await t 
      ---
    }); 

fixture `Fixture B for Use Case2`
    .beforeEach(login)

test('B Test 1', async t => {
      await t 
      ---
    }); 

test('B Test 2', async t => {
      await t 
      ---
    }); 
   
test('B Test 3', async t => {
      await t 
      ---
    }); 

正在发生什么

在每次测试"Fixture A"和"Fixture B"下运行登录功能

What Is Happening

The login function is being run before every test under 'Fixture A' and 'Fixture B'

我希望登录"在每个固定装置"开始时都运行一次,而不是在固定装置下的每个测试中都运行一次.

I want 'login' to run once at the start of every 'Fixture' and not for every test under the fixtures.

有可能吗?我找不到有关文档的方法.

Is it possible? I couldn't find a way on documentation.

推荐答案

这可以通过用户角色"和保留网址"选项来实现. TestCafe的文档在此处进行了说明: https://devexpress.github.io/testcafe/documentation/test-api/authentication/user-roles.html#optionspreserveurl

This is achievable via User Roles and the 'preserve url' option. TestCafe's documentation explains it here: https://devexpress.github.io/testcafe/documentation/test-api/authentication/user-roles.html#optionspreserveurl

这篇关于如何仅在夹具级别而不是针对该夹具下的每个测试执行“每次测试之前"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆