cypress-sftp-client
TypeScript icon, indicating that this package has built-in type declarations

4.1.0 • Public • Published

cypress-sftp-client

Wrapped ssh2-sftp-client to cypress framework tasks.

Adding to project

Add following lines to your commands.ts:

/// <reference types="Cypress plugin for SFTP client" />

import "cypress-sftp-client/commands";

Add following lines to your plugins/index.ts:

// plugins file

import sftpClient from "cypress-sftp-client/plugin";

function register(on: Cypress.PluginEvents): void {
    sftpClient(on);
}

export = register;

Example

describe("SFTP client", () => {
    const debug = true;
    const rootDir = "sftp_client_test";
    const connectionSettings: ISftpConnectionSettings = {
        host: "127.0.0.1",
        port: 22,
        userName: "user",
        password: "password",
        protocol: "IPv4", // "IPv6"
        dir: rootDir,
    };

    const dirInput = "input";
    const fileName = dirInput + "/test.txt";

    it("walk around SFTP tasks", () => {
        cy.sftpCreateDirectory({
            debug,
            connectionSettings,
            directoryName: [dirInput],
        }).then((r) => {
            cy.log("sftpCreateDirectory result", r);
        });

        cy.sftpUpload({
            debug,
            connectionSettings,
            content: "content",
            fileName,
        }).then((r) => {
            cy.log("sftpUpload result", r);
        });

        cy.sftpExists({
            debug,
            connectionSettings,
            fileName,
        }).then((r) => {
            cy.log("sftpExists result", r);
            expect(r.isExisting).is.be.true;
        });

        cy.sftpList({
            debug,
            directory: dirInput,
            connectionSettings,
        }).then((r) => {
            cy.log("sftpList result" + r.files.map((f) => `${f.fileName} - ${f.modifiedDate}`), r);
        });

        cy.sftpDownload({
            debug,
            connectionSettings,
            fileName: fileName,
        }).then((r) => {
            cy.log("sftpDownload result" + r.fileContent, r);
        });

        cy.sftpDelete({
            debug,
            connectionSettings,
            fileNames: [fileName],
        }).then((r) => {
            cy.log("sftpDelete result", r);
        });
    });
});

How to Develop

To build plugin run webpack with specific config:

npx webpack --config webpack.config.plugin.ts -w

and then run cypress:

npx cypress open

How to run example

In root folder run:

npx tsc
node sftpClient

Readme

Keywords

none

Package Sidebar

Install

npm i cypress-sftp-client

Weekly Downloads

359

Version

4.1.0

License

MIT

Unpacked Size

1.03 MB

Total Files

17

Last publish

Collaborators

  • k.steinmetz