To answer straight, opening/ peeking the direct declaration of custom commands is not supported (May be, some one can correct if this supports). I would usually follow grouping of custom commands in separate files. For instance,
File: cypress/support/sample_command.ts
/// <reference types="Cypress" />
import * as PageElements from "../resources/selectors.json";
import * as Pages from "../resources/urls.json";
let xml: XMLDocument
let data: HTMLCollection
Cypress.Commands.add(
"getWorkflowXML",
(wfPath: string): Cypress.Chainable<HTMLCollection> => {
var url = Cypress.env("url") + wfPath;
return cy.request({
log: true,
url: url,
auth: {
user: Cypress.env("userName"),
pass: Cypress.env("password")
}
}).then(response => {
expect(response)
.property("status")
.to.equal(200);
xml = Cypress.$.parseXML(response.body);
data = xml.getElementsByTagName("java");
return data;
});
}
);
declare global {
namespace Cypress {
interface Chainable {
/**
* Get Workflow XML through XHR call
* @memberof Cypress.Chainable
* @param wfPath
*/
getWorkflowXML: (wfPath: string) => Cypress.Chainable<HTMLCollection>;
}
}
}
Then, in the the cypress/support/index.js
file I would import the command file,
import './sample_command'
This way gives me better traceability, instead of declaring all the commands straight under index.d.ts
.
Reference:
- https://docs.cypress.io/api/cypress-api/custom-commands.html#Syntax
- https://github.com/cypress-io/add-cypress-custom-command-in-typescript