Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
SHAFT is a unified test automation engine. Powered by best-in-class frameworks, SHAFT provides a
wizard-like syntax to drive your automation efficiently, maximize your ROI, and minimize your learning curve.
Stop reinventing the wheel. Upgrade now!
package com.shaft.cli;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.shaft.driver.SHAFT;
import com.shaft.tools.io.ReportManager;
import com.shaft.tools.io.internal.FailureReporter;
import com.shaft.tools.io.internal.ReportHelper;
import com.shaft.tools.io.internal.ReportManagerHelper;
import org.apache.commons.lang3.SystemUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("unused")
public class TerminalActions {
private String sshHostName = "";
private String sshUsername;
private String sshKeyFileFolderName;
private String sshKeyFileName;
private int sshPortNumber = 22;
private String dockerName = "";
private String dockerUsername;
private boolean asynchronous = false;
private boolean verbose = false;
/**
* This constructor is used for local terminal actions.
*/
public TerminalActions() {
}
/**
* This constructor is used for local terminal actions.
*
* @param asynchronous true for asynchronous execution of commands in a separate thread
*/
public TerminalActions(boolean asynchronous) {
this.asynchronous = asynchronous;
}
private TerminalActions(boolean asynchronous, boolean verbose) {
this.asynchronous = asynchronous;
this.verbose = verbose;
}
/**
* This constructor is used for local terminal actions inside a docker.
*
* @param dockerName the name of the docker instance that you want to
* execute the terminal command inside
* @param dockerUsername the username which will be used to access the docker
* instance. Must have the access/privilege to execute the
* terminal command
*/
public TerminalActions(String dockerName, String dockerUsername) {
this.dockerName = dockerName;
this.dockerUsername = dockerUsername;
}
/**
* This constructor is used for remote terminal actions.
*
* @param sshHostName the IP address or host name for the remote
* machine you want to execute the terminal command
* on.
* @param sshPortNumber the port that's used for the SSH service on the
* target machine. Default is 22.
* @param sshUsername the username which will be used to access the
* target machine via ssh. Must have the
* access/privilege to execute the terminal command
* @param sshKeyFileFolderName the directory that holds the ssh key file
* (usually it's somewhere in the test data of the
* current project)
* @param sshKeyFileName the name of the ssh key file
*/
public TerminalActions(String sshHostName, int sshPortNumber, String sshUsername, String sshKeyFileFolderName,
String sshKeyFileName) {
this.sshHostName = sshHostName;
this.sshPortNumber = sshPortNumber;
this.sshUsername = sshUsername;
this.sshKeyFileFolderName = sshKeyFileFolderName;
this.sshKeyFileName = sshKeyFileName;
}
/**
* This constructor is used for remote terminal actions inside a docker.
*
* @param sshHostName the IP address or host name for the remote
* machine you want to execute the terminal command
* on.
* @param sshPortNumber the port that's used for the SSH service on the
* target machine. Default is 22.
* @param sshUsername the username which will be used to access the
* target machine via ssh. Must have the
* access/privilege to execute the terminal command
* @param sshKeyFileFolderName the directory that holds the ssh key file
* (usually it's somewhere in the test data of the
* current project)
* @param sshKeyFileName the name of the ssh key file
* @param dockerName the name of the docker instance that you want to
* execute the terminal command inside
* @param dockerUsername the username which will be used to access the
* docker instance. Must have the access/privilege
* to execute the terminal command
*/
public TerminalActions(String sshHostName, int sshPortNumber, String sshUsername, String sshKeyFileFolderName,
String sshKeyFileName, String dockerName, String dockerUsername) {
this.sshHostName = sshHostName;
this.sshPortNumber = sshPortNumber;
this.sshUsername = sshUsername;
this.sshKeyFileFolderName = sshKeyFileFolderName;
this.sshKeyFileName = sshKeyFileName;
this.dockerName = dockerName;
this.dockerUsername = dockerUsername;
}
public static TerminalActions getInstance() {
return new TerminalActions();
}
public static TerminalActions getInstance(boolean asynchronous) {
return new TerminalActions(asynchronous);
}
public static TerminalActions getInstance(boolean asynchronous, boolean verbose) {
return new TerminalActions(asynchronous, verbose);
}
private static String reportActionResult(String actionName, String testData, String log, Boolean passFailStatus, Exception... rootCauseException) {
actionName = actionName.substring(0, 1).toUpperCase() + actionName.substring(1);
String message;
if (Boolean.TRUE.equals(passFailStatus)) {
message = "Terminal Action \"" + actionName + "\" successfully performed.";
} else {
message = "Terminal Action \"" + actionName + "\" failed.";
}
List> attachments = new ArrayList<>();
if (testData != null && testData.length() >= 500) {
List