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.
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.tools.io.PropertyFileManager;
import com.shaft.tools.io.ReportManager;
import org.testng.Assert;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
@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 unattended = false;
/**
* This constructor is used for local terminal actions.
*/
public TerminalActions() {
}
/**
* This constructor is used for local terminal actions.
*
* @param unattended true for unattended execution of commands in a separate thread
*/
public TerminalActions(boolean unattended) {
this.unattended = unattended;
}
/**
* 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;
}
private static String reportActionResult(String actionName, String testData, String log, Boolean passFailStatus) {
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.isEmpty() && testData.length() >= 500) {
List