javascript - How to go to custom commands implementation in Cypress? - Stack Overflow

I'm using custom mands in cypress and it it working fine. I'm using visual studio code as edi

I'm using custom mands in cypress and it it working fine. I'm using visual studio code as editor. I was looking for how to let intelliSence to recognize custom mands and found that in

I added cypress/index.d.ts file:

/// <reference types="cypress" />
declare namespace Cypress {
interface Chainable<Subject> {
  /**
   * Do something
   * @example
   * cy.doSomething()
   */
  doSomething(): Chainable<any>
}}

now when clicking on doSomething in the spec file it opens the declaration in index.d.ts, is there a way to let vscode open the actual mand implementation under support/mands.js?

I'm using custom mands in cypress and it it working fine. I'm using visual studio code as editor. I was looking for how to let intelliSence to recognize custom mands and found that in https://github./cypress-io/cypress-example-todomvc#cypress-intellisense

I added cypress/index.d.ts file:

/// <reference types="cypress" />
declare namespace Cypress {
interface Chainable<Subject> {
  /**
   * Do something
   * @example
   * cy.doSomething()
   */
  doSomething(): Chainable<any>
}}

now when clicking on doSomething in the spec file it opens the declaration in index.d.ts, is there a way to let vscode open the actual mand implementation under support/mands.js?

Share Improve this question edited Mar 22, 2019 at 9:55 DilbertFan 1131 gold badge1 silver badge9 bronze badges asked Mar 21, 2019 at 13:40 Emad AldaluEmad Aldalu 611 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

To answer straight, opening/ peeking the direct declaration of custom mands is not supported (May be, some one can correct if this supports). I would usually follow grouping of custom mands in separate files. For instance,

File: cypress/support/sample_mand.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 mand file,

import './sample_mand'

This way gives me better traceability, instead of declaring all the mands straight under index.d.ts.

Reference:

  1. https://docs.cypress.io/api/cypress-api/custom-mands.html#Syntax
  2. https://github./cypress-io/add-cypress-custom-mand-in-typescript

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744796432a4594230.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信