cypress-sftp-client
v4.1.0
Published
Cypress plugin for SFTP client
Downloads
209
Readme
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