beforeEach 中的条件语句

问题描述 投票:0回答:1

我的大多数测试需要在开始之前完成一项任务,因此我制作了 beforeEach 函数,该函数运行完美。

一个测试在开始之前需要做其他事情。

在 Cypress 中,除了一些测试之外,还有其他方法可以做 beforeEach 吗?

我正在尝试添加 cypress.current.title switch case 语句

cypress
1个回答
0
投票

我不确定我是否正确理解了你的意思,如果有的话,请纠正我

beforeEach(() => {
  const title = Cypress.env('title'); //  if you have set the title using Cypress.env
  switch (title) {
    case 'Test1':
      //here to code to run before Test1
      break;
    case 'Test2':
      //here to code to run before Test2 or just simply break if thta you want 
      break;
    default:
      // here will be the code block to run for other tests
      break;
  }
});
© www.soinside.com 2019 - 2024. All rights reserved.