简体   繁体   English

Selenium JavaScript - 如何在 Jest 测试用例中设置测试 ID

[英]Selenium JavaScript - How to set test id in Jest test cases

I want to set an id to each test in Jest so that I can uniquely identify them.我想为 Jest 中的每个测试设置一个 id,以便我可以唯一地识别它们。

It is something similar to @TestParamters / @Parameters in TestNG.它类似于 TestNG 中的@TestParamters / @Parameters

Here - https://www.gurock.com/testrail/docs/api/reference/results#addresult .这里 - https://www.gurock.com/testrail/docs/api/reference/results#addresult If you look the end-point given here, it ask for :test_id .如果您查看此处给出的端点,它会要求:test_id

So, I also want to give an id to each of my test cases and fetch that id in TestRail.所以,我还想为我的每个测试用例提供一个 id,并在 TestRail 中获取该 id。

Check @jest-reporters/testrail plugin.检查@jest-reporters/testrail插件。 It is a TestRail module for Jest.它是 Jest 的 TestRail 模块。 Helps to create test runs on TestRail for multiple suites and send results.帮助在 TestRail 上为多个套件创建测试运行并发送结果。

First, install the plugin一、安装插件

npm i @jest-reporters/testrail

Second, update jest.config.js二、更新jest.config.js

 module.exports = {... reporters: [ ["testrail", { project_id: "1" }] ] };

Third, in your test case files第三,在你的测试用例文件中

 // "1:" this is Suite ID from Test Rail (Will work only for top) describe("TestRail[1] Suite", () => { // "11:" this is Case ID from Test Rail it("TestRail[11] Test success", async() => { expect(1).toBe(1); }); it("TestRail[12] Test fail", async() => { expect(1).toBe(0); }); xit("TestRail[13] Test skip", async() => { expect(1).toBe(1); }); });

The Suite ID from TestRail must be added to the start of top describe() description, ID should be in TestRail[ID].来自 TestRail 的套件 ID 必须添加到顶部 describe() 描述的开头,ID 应该在 TestRail[ID] 中。

The Case ID from TestRail must be added to the start of each it() description, ID should be in TestRail[ID]. TestRail 中的 Case ID 必须添加到每个 it() 描述的开头,ID 应该在 TestRail[ID] 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM