赛普拉斯两次测试之间通过状态的最佳实践是什么 [英] What is the best practice of pass states between tests in Cypress

查看:36
本文介绍了赛普拉斯两次测试之间通过状态的最佳实践是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在每个测试之间传递/共享数据.在赛普拉斯中实现它的最佳方法是什么?

I want to pass/share data between each test. What is the best way to implement it in Cypress?

例如:

 it('test 1'), () => {
   cy.wrap('one').as('a')
   const state1 = 'stat1'
 })

 it('test 2'), () => {
   cy.wrap('two').as('b')
 })

 it('test 2'), () => {
   //I want to access this.a and this.b

   //Also I want to access state1

 })

推荐答案

对于Javascript变量,您可以执行以下操作:

In the case of Javascript variables, you can do something like this:

let state;

describe('test 1', () => {
    it('changes state', () => {
        state = "hi";
     });
});

describe('test 2', () => {
    it('reports state', () => {
        cy.log(state); // logs "hi" to the Cypress log panel
     });
});

.as()似乎无法在 describe 块之间传递状态.

.as() does not appear to be able to carry state between describe blocks.

这篇关于赛普拉斯两次测试之间通过状态的最佳实践是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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