赛普拉斯-如何按顺序运行测试文件 [英] Cypress - How can I run test files in order

查看:269
本文介绍了赛普拉斯-如何按顺序运行测试文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我按下运行所有规格" 按钮或使用运行命令在赛普拉斯中运行所有文件,它按字母顺序运行所有测试文件,所以我不希望这样做.

When I press the "run all specs" button or use the run command that runs all files in Cypress it runs all test files alphabetically, so I don't want that.

我想用我自己的规则对它们进行排序.

I want to sort all of them with my own rules.

假设我在聊天应用程序测试中有3个步骤.

Let's say I have 3 steps in a chat app test.

  1. 可以连接聊天应用
  2. 可以连接聊天
  3. 用户可以发送消息吗

我想测试每个步骤而又不互相束缚. 我的意思是,测试自己的功能之一. 我的工作如下

I want to test every step without being tied to each other. What I mean, Testing one of their own function. What I do is as follows

chat_app_connect.spec.js

describe('Server Connecting Test', () => {
    it('Visit Server page', () => {
        cy.visit('https://chat.page..');
    });

    it('Check welcome messages', () => {
        cy.contains('Live Support');
        cy.contains('Hello, Stranger');
    });

    it('Check URL and status of circle', () => {
        // URL
        cy.url()
            .should('include', '/hello');
        // Status Circle    
        cy.get('circle')
            .should('have.class', 'positive');
    });
});

chat_connect.spec.js

import './chat_app_connect.spec.js';

describe('Chat Connecting Test', () => {
    it('Type customer name', () => {
        cy.get('input')
            .clear()
            .type('E2E Test');
    });
    it('Click to the submit button', () => {
        cy.get('.submit-button')
            .click();
    });
    it('Check URL and status of circle', () => {
        // URL
        cy.url()
            .should('equal', 'https://client.dev.octopus.chat/');
        // Status Circle
        cy.get('circle', { timeout: 5000 })
            .should('have.class', 'positive');
    });
});

chatting.spec.js

import './chat_connect.spec.js';

describe('Chatting Tests', () => {
    it('Type a test message then press Enter and check the message if it sent', () => {
        // Type
        cy.get('#chat-message')
            .clear()
            .type('Hey I\'m a test message{enter}');
        // Check the message
        cy.get('.message-list')
            .should('contain', 'Hey I\'m a test message');
    });
});

如您所见,每个测试都是相互关联的,这意味着当我尝试进行测试时,它只是对各种功能的调用,而每个测试都将被测试.

as you see every test is tied to each other, and that is mean when I tried to test just catting functionality its call every test and the whole tests will be tested.

我不知道这是不是正确的方法.

I don't know if it is the right way or not.

在这种情况下我该怎么办?或者这是可以接受的方式

what should I do in this case or can it be an acceptable way

推荐答案

在特殊情况下,我启动了一个应用程序的多个实例,而不是使用固定装置或测试数据,我只是将用户反馈作为赛普拉斯测试的集成,从登录开始就进行了集成.向前.

I have a particular case where I launch multiple instances of an app, rather than using fixtures or test data, I simply integrate user feedback as Cypress tests from login on forwards.

无论如何,我都使用了cypress.json中的testFiles配置来设置spec文件的运行顺序:

In any case, I used the testFiles config in cypress.json to set the spec file run order:

{
  "baseUrl": "http://localhost:5000",
  "testFiles": [
    "login/*.js",
    "leads/new-lead.spec.js",
    "leads/leads-list.spec.js",
    "leads/lead-detail.spec.js",
    "leads/lead-modify.spec.js",
    //...
  ]
}

不需要文件编号:D

这篇关于赛普拉斯-如何按顺序运行测试文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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