tgf*_*dev 0 javascript node.js cypress
我有一个命令可以覆盖暂停以将对话框中的输入添加到报告中。我想知道是否有办法知道哪个测试正在调用该函数,以便我可以自定义输入上的消息。
Cypress.Commands.overwrite('pause', (originalFn, element, options) => {
var tryThis = '';
if (//place calling the function == file1) {
tryThis = 'message1';
} else if (//place calling the function == file2) {
...
} else if (//place calling the function == file3) {
...
}
var datalog = window.prompt(tryThis, "Log your results");
cy.addContext("DATALOG:" + datalog);
return originalFn(element, options)
})
Run Code Online (Sandbox Code Playgroud)
除了通过 Mocha 属性访问之外,还可以
对于规格文件 Cypress.spec
属性为my.spec.js
Cypress.spec.absolute: "C:/.../my.spec.js"
Cypress.spec.name: "my.spec.js"
Cypress.spec.relative: "cypress\integration\my.spec.js"
Cypress.spec.specFilter: "my"
Cypress.spec.specType: "integration"
Run Code Online (Sandbox Code Playgroud)
用于测试 cy.state('runnable')
为了
describe('my-context', () => {
it('my-test', () => {
Run Code Online (Sandbox Code Playgroud)
属性和方法,
const title = cy.state('runnable').title; // "my-test"
const fullTitle = cy.state('runnable').fullTitle(); // "my-context my-test"
const titlePath = cy.state('runnable').titlePath(); // ["my-context", "my-test"]
Run Code Online (Sandbox Code Playgroud)
您还可以将元数据添加到测试中
describe('my-context', () => {
it('my-test', { message: "my-message" }, () => {
Run Code Online (Sandbox Code Playgroud)
并在命令覆盖中抓住它
const message = cy.state('runnable').cfg.message; // "my-message"
Run Code Online (Sandbox Code Playgroud)