Cypress plugin for SFTP client
npm install cypress-sftp-clientWrapped ssh2-sftp-client to cypress framework tasks.
Add following lines to your _commands.ts_:
``tsx
///
import "cypress-sftp-client/commands";
`
Add following lines to your _plugins/index.ts_:
`tsx
// plugins file
import sftpClient from "cypress-sftp-client/plugin";
function register(on: Cypress.PluginEvents): void {
sftpClient(on);
}
export = register;
`
`tsx
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);
});
});
});
`
To build plugin run webpack with specific config:
`bash`
npx webpack --config webpack.config.plugin.ts -w
and then run cypress:
`bash`
npx cypress open
In root folder run:
`bash`
npx tsc
`bash``
node sftpClient