Skip to content

Commit

Permalink
Removing old classes (#1262)
Browse files Browse the repository at this point in the history
* deleting fluent browser/element actions classes

Signed-off-by: Mohab Mohie <[email protected]>

* linting

Signed-off-by: Mohab Mohie <[email protected]>

* optimize imports

Signed-off-by: Mohab Mohie <[email protected]>

* code cleanup

Signed-off-by: Mohab Mohie <[email protected]>

* code enhancements

- removing redundant code
- improving code performance
- overall linting

Signed-off-by: Mohab Mohie <[email protected]>

* Update Internal.java

Signed-off-by: Mohab Mohie <[email protected]>

* Update pom.xml

Signed-off-by: Mohab Mohie <[email protected]>

* Update DriverFactoryHelper.java

Signed-off-by: Mohab Mohie <[email protected]>

---------

Signed-off-by: Mohab Mohie <[email protected]>

* releasing with known issue handling JSAlerts, to be investigated further
  • Loading branch information
MohabMohie authored Aug 29, 2023
1 parent c7ee6a7 commit 6e6709d
Show file tree
Hide file tree
Showing 48 changed files with 2,258 additions and 2,348 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.shafthq</groupId>
<artifactId>SHAFT_ENGINE</artifactId>
<version>7.3.20230824.1</version> <!-- UPDATE com.shaft.properties.internal > Internal -->
<version>7.3.20230829</version> <!-- UPDATE com.shaft.properties.internal > Internal -->
<name>${project.groupId}:${project.artifactId}</name>
<description>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.
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/shaft/api/BrowserStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static MutableCapabilities setupDesktopWebExecution() {

MutableCapabilities browserStackCapabilities = new MutableCapabilities();
var browserVersion = SHAFT.Properties.browserStack.browserVersion();
if (browserVersion != null && !"".equals(browserVersion.trim())) {
if (browserVersion != null && !browserVersion.trim().isEmpty()) {
browserStackCapabilities.setCapability("browserVersion", SHAFT.Properties.browserStack.browserVersion());
}
HashMap<String, Object> browserstackOptions = new HashMap<>();
Expand All @@ -143,7 +143,7 @@ public static MutableCapabilities setupDesktopWebExecution() {
browserstackOptions.put("local", SHAFT.Properties.browserStack.local());
browserstackOptions.put("seleniumVersion", SHAFT.Properties.browserStack.seleniumVersion());
String geoLocation = SHAFT.Properties.browserStack.geoLocation();
if (geoLocation != null && !"".equals(geoLocation)) {
if (geoLocation != null && !geoLocation.isEmpty()) {
browserstackOptions.put("geoLocation", SHAFT.Properties.browserStack.geoLocation());
}
browserStackCapabilities.setCapability("bstack:options", browserstackOptions);
Expand All @@ -163,8 +163,6 @@ private static MutableCapabilities setBrowserStackProperties(String username, St
browserstackOptions.put("acceptInsecureCerts", SHAFT.Properties.browserStack.acceptInsecureCerts());
browserstackOptions.put("debug", SHAFT.Properties.browserStack.debug());
browserstackOptions.put("networkLogs", SHAFT.Properties.browserStack.networkLogs());
// browserstackOptions.put("projectName", System.getProperty("project.artifactId"));
// browserstackOptions.put("buildName", !SHAFT.Properties.browserStack.appName().equals("") ? SHAFT.Properties.browserStack.appName() : System.getProperty("project.artifactId") + "_" + System.currentTimeMillis());
browserStackCapabilities.setCapability("bstack:options", browserstackOptions);
return browserStackCapabilities;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/shaft/api/LambdaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static MutableCapabilities setupNativeAppExecution(String username, Strin
MutableCapabilities lambdaTestCapabilities = setLambdaTestProperties(username, password, deviceName, osVersion, appUrl);
testData = testData + ", App URL: " + appUrl;
passAction(testData);
HashMap<String, Object> lambdaTestOptions = new HashMap<String, Object>();
HashMap<String, Object> lambdaTestOptions = new HashMap<>();
lambdaTestOptions.put("w3c", SHAFT.Properties.lambdaTest.w3c());
if (Platform.ANDROID.toString().equalsIgnoreCase(SHAFT.Properties.platform.targetPlatform())) {
lambdaTestOptions.put("platformName", "android");
Expand Down Expand Up @@ -98,7 +98,7 @@ public static MutableCapabilities setupNativeAppExecution(String username, Strin
// set properties
MutableCapabilities LambdaTestCapabilities = setLambdaTestProperties(username, password, deviceName, osVersion, appUrl);
passAction(testData);
HashMap<String, Object> lambdaTestOptions = new HashMap<String, Object>();
HashMap<String, Object> lambdaTestOptions = new HashMap<>();
lambdaTestOptions.put("w3c", SHAFT.Properties.lambdaTest.w3c());
if (Platform.ANDROID.toString().equalsIgnoreCase(SHAFT.Properties.platform.targetPlatform())) {
lambdaTestOptions.put("platformName", "android");
Expand Down Expand Up @@ -128,7 +128,7 @@ public static MutableCapabilities setupMobileWebExecution() {
SHAFT.Properties.mobile.set().browserName(SHAFT.Properties.web.targetBrowserName());
MutableCapabilities lambdaTestCapabilities = new MutableCapabilities();
var browserVersion = SHAFT.Properties.lambdaTest.browserVersion();
if (browserVersion != null && !"".equals(browserVersion.trim())) {
if (browserVersion != null && !browserVersion.trim().isEmpty()) {
lambdaTestCapabilities.setCapability("browserVersion", SHAFT.Properties.lambdaTest.browserVersion());
}
lambdaTestCapabilities.setCapability("browserName", SHAFT.Properties.web.targetBrowserName());
Expand Down Expand Up @@ -175,7 +175,7 @@ public static MutableCapabilities setupDesktopWebExecution() {
SHAFT.Properties.platform.set().executionAddress(username + ":" + password + "@" + hubUrl);
MutableCapabilities lambdaTestCapabilities = new MutableCapabilities();
var browserVersion = SHAFT.Properties.lambdaTest.browserVersion();
if (browserVersion != null && !"".equals(browserVersion.trim())) {
if (browserVersion != null && !browserVersion.trim().isEmpty()) {
lambdaTestCapabilities.setCapability("browserVersion", SHAFT.Properties.lambdaTest.browserVersion());
}
lambdaTestCapabilities.setCapability("browserName", SHAFT.Properties.web.targetBrowserName());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/shaft/cli/FileActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String copyFile(TerminalActions terminalSession, String sourceDirectory,
String fileName) {
String command;
if (isTargetOSUnixBased()) {
if (fileName.trim().equals("")) {
if (fileName.trim().isEmpty()) {
command = "rsync --verbose --recursive " + sourceDirectory + File.separator + " "
+ destinationDirectory;
} else {
Expand Down Expand Up @@ -679,7 +679,7 @@ private String reportActionResult(String actionName, String testData, String log
message = message + " With the following test data \"" + testData + "\".";
}

if (log != null && !log.trim().equals("")) {
if (log != null && !log.trim().isEmpty()) {
attachments.add(Arrays.asList("File Action Actual Result", "Command Log", log));
}

Expand Down Expand Up @@ -815,7 +815,7 @@ private void addFolderToZip(String path, String srcFolder, ZipOutputStream zip)
* list the files in the folder
*/
for (String fileName : Objects.requireNonNull(folder.list())) {
if (path.equals("")) {
if (path.isEmpty()) {
addFileToZip(folder.getName(), srcFolder + FileSystems.getDefault().getSeparator() + fileName, zip,
false);
} else {
Expand Down
83 changes: 34 additions & 49 deletions src/main/java/com/shaft/cli/TerminalActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.shaft.tools.io.internal.FailureReporter;
import com.shaft.tools.io.internal.ReportHelper;
import com.shaft.tools.io.internal.ReportManagerHelper;
import lombok.Getter;
import org.apache.commons.lang3.SystemUtils;

import java.io.BufferedReader;
Expand All @@ -22,13 +23,20 @@

@SuppressWarnings("unused")
public class TerminalActions {
@Getter
private String sshHostName = "";
@Getter
private String sshUsername;
@Getter
private String sshKeyFileFolderName;
@Getter
private String sshKeyFileName;
@Getter
private int sshPortNumber = 22;

@Getter
private String dockerName = "";
@Getter
private String dockerUsername;

private boolean asynchronous = false;
Expand Down Expand Up @@ -155,7 +163,7 @@ private static String reportActionResult(String actionName, String testData, Str
message = message + " With the following test data \"" + testData + "\".";
}

if (log != null && !log.trim().equals("")) {
if (log != null && !log.trim().isEmpty()) {
attachments.add(Arrays.asList("Terminal Action Actual Result", "Command Log", log));
}

Expand All @@ -175,11 +183,11 @@ private static String reportActionResult(String actionName, String testData, Str
}

public boolean isRemoteTerminal() {
return !sshHostName.equals("");
return !sshHostName.isEmpty();
}

public boolean isDockerizedTerminal() {
return !dockerName.equals("");
return !dockerName.isEmpty();
}

public String performTerminalCommands(List<String> commands) {
Expand All @@ -204,14 +212,14 @@ public String performTerminalCommands(List<String> commands) {

// Prepare final log message
StringBuilder reportMessage = new StringBuilder();
if (!sshHostName.equals("")) {
if (!sshHostName.isEmpty()) {
reportMessage.append("Host Name: \"").append(sshHostName).append("\"");
reportMessage.append(" | SSH Port Number: \"").append(sshPortNumber).append("\"");
reportMessage.append(" | SSH Username: \"").append(sshUsername).append("\"");
} else {
reportMessage.append("Host Name: \"" + "localHost" + "\"");
}
if (sshKeyFileName != null && !sshKeyFileName.equals("")) {
if (sshKeyFileName != null && !sshKeyFileName.isEmpty()) {
reportMessage.append(" | Key File: \"").append(sshKeyFileFolderName).append(sshKeyFileName).append("\"");
}
reportMessage.append(" | Command: \"").append(longCommand).append("\"");
Expand All @@ -229,34 +237,6 @@ public String performTerminalCommand(String command) {
return performTerminalCommands(Collections.singletonList(command));
}

public String getSshHostName() {
return sshHostName;
}

public String getSshUsername() {
return sshUsername;
}

public String getSshKeyFileFolderName() {
return sshKeyFileFolderName;
}

public String getSshKeyFileName() {
return sshKeyFileName;
}

public int getSshPortNumber() {
return sshPortNumber;
}

public String getDockerName() {
return dockerName;
}

public String getDockerUsername() {
return dockerUsername;
}

private void passAction(String actionName, String testData, String log) {
reportActionResult(actionName, testData, log, true);
}
Expand Down Expand Up @@ -284,7 +264,7 @@ private Session createSSHsession() {
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
if (sshKeyFileName != null && !sshKeyFileName.equals("")) {
if (sshKeyFileName != null && !sshKeyFileName.isEmpty()) {
jsch.addIdentity(FileActions.getInstance().getAbsolutePath(sshKeyFileFolderName, sshKeyFileName));
}
session = jsch.getSession(sshUsername, sshHostName, sshPortNumber);
Expand All @@ -301,7 +281,7 @@ private String buildLongCommand(List<String> commands) {
StringBuilder command = new StringBuilder();
// build long command
for (Iterator<String> i = commands.iterator(); i.hasNext(); ) {
if (command.length() == 0) {
if (command.isEmpty()) {
command.append(i.next());
} else {
command.append(" && ").append(i.next());
Expand Down Expand Up @@ -343,19 +323,7 @@ private List<String> executeLocalCommand(List<String> commands, String longComma
command = command.contains(".bat") && !command.contains(".\\") ? ".\\" + command : command;
ReportManager.logDiscrete("Executing: \"" + command + "\" locally.");
try {
ProcessBuilder pb = new ProcessBuilder();
pb.directory(new File(finalDirectory));

// https://stackoverflow.com/a/10954450/12912100
if (isWindows) {
if (asynchronous && verbose) {
pb.command("powershell.exe", "Start-Process powershell.exe '-NoExit -WindowStyle Minimized \"[Console]::Title = ''SHAFT_Engine''; " + command + "\"'");
} else {
pb.command("powershell.exe", "-Command", command);
}
} else {
pb.command("sh", "-c", command);
}
ProcessBuilder pb = getProcessBuilder(command, finalDirectory, isWindows);
if (!asynchronous) {
pb.redirectErrorStream(true);
Process localProcess = pb.start();
Expand Down Expand Up @@ -405,6 +373,23 @@ private List<String> executeLocalCommand(List<String> commands, String longComma
return Arrays.asList(logs.toString().trim(), exitStatuses.toString());
}

private ProcessBuilder getProcessBuilder(String command, String finalDirectory, boolean isWindows) {
ProcessBuilder pb = new ProcessBuilder();
pb.directory(new File(finalDirectory));

// https://stackoverflow.com/a/10954450/12912100
if (isWindows) {
if (asynchronous && verbose) {
pb.command("powershell.exe", "Start-Process powershell.exe '-NoExit -WindowStyle Minimized \"[Console]::Title = ''SHAFT_Engine''; " + command + "\"'");
} else {
pb.command("powershell.exe", "-Command", command);
}
} else {
pb.command("sh", "-c", command);
}
return pb;
}

private List<String> executeRemoteCommand(List<String> commands, String longCommand) {
StringBuilder logs = new StringBuilder();
StringBuilder exitStatuses = new StringBuilder();
Expand Down Expand Up @@ -441,7 +426,7 @@ private String readConsoleLogs(BufferedReader reader) throws IOException {
if (reader != null) {
String logLine;
while ((logLine = reader.readLine()) != null) {
if (logBuilder.length() == 0) {
if (logBuilder.isEmpty()) {
logBuilder.append(logLine);
} else {
logBuilder.append(System.lineSeparator()).append(logLine);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/shaft/db/DatabaseActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class DatabaseActions {
*/
public DatabaseActions(DatabaseType databaseType, String ip, String port, String name, String username,
String password) {
if (!ip.equals("") && !port.equals("") && !name.equals("") && !username.equals("") && !password.equals("")) {
if (!ip.isEmpty() && !port.isEmpty() && !name.isEmpty() && !username.isEmpty() && !password.isEmpty()) {
this.dbType = databaseType;
this.dbServerIP = ip;
this.dbPort = port;
Expand Down Expand Up @@ -271,7 +271,7 @@ private static String reportActionResult(String actionName, String testData, Str
message = message + " With the following test data \"" + testData + "\".";
}

if (queryResult != null && !queryResult.trim().equals("")) {
if (queryResult != null && !queryResult.trim().isEmpty()) {
attachments.add(Arrays.asList("Database Action Actual Result", "Query Result", queryResult));
}

Expand Down Expand Up @@ -439,7 +439,7 @@ public int executeDeleteQuery(String sql) {
private Connection createConnection() {
Connection connection = null;
var connectionString = "";
if (!this.customConnectionString.equals("")) {
if (!this.customConnectionString.isEmpty()) {
connectionString = this.customConnectionString;
} else {
switch (dbType) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/shaft/driver/DriverFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.shaft.listeners.internal.TestNGListenerHelper;
import com.shaft.tools.io.ReportManager;
import com.shaft.tools.io.internal.ProjectStructureManager;
import lombok.Getter;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -245,6 +246,7 @@ public static void closeAllDrivers() {
/**
* List of the supported driver types for execution
*/
@Getter
public enum DriverType {
SIKULI("SikuliActions"), BROWSERSTACK("BrowserStack") ,LAMBDATEST("LambdaTest"), DATABASE("DatabaseActions"), TERMINAL("TerminalActions"), API("RestActions"), FIREFOX(Browser.FIREFOX.browserName()), CHROME(Browser.CHROME.browserName()), SAFARI(Browser.SAFARI.browserName()),
IE(Browser.IE.browserName()), EDGE(Browser.EDGE.browserName()), CHROMIUM("Chromium"), WEBKIT("Webkit"), APPIUM_CHROME("chrome"),
Expand All @@ -256,9 +258,6 @@ public enum DriverType {
this.value = type;
}

public String getValue() {
return value;
}
}

}
13 changes: 6 additions & 7 deletions src/main/java/com/shaft/driver/SHAFT.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import com.shaft.db.DatabaseActions;
import com.shaft.driver.internal.DriverFactoryHelper;
import com.shaft.driver.internal.WizardHelpers;
import com.shaft.gui.browser.internal.FluentBrowserActions;
import com.shaft.gui.browser.BrowserActions;
import com.shaft.gui.element.AlertActions;
import com.shaft.gui.element.ElementActions;
import com.shaft.gui.element.SikuliActions;
import com.shaft.gui.element.TouchActions;
import com.shaft.gui.element.internal.FluentElementActions;
import com.shaft.listeners.internal.WebDriverListener;
import com.shaft.tools.io.ExcelFileManager;
import com.shaft.tools.io.JSONFileManager;
Expand All @@ -21,7 +21,6 @@
import com.shaft.validation.internal.RestValidationsBuilder;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
import io.restassured.config.RestAssuredConfig;
import io.restassured.response.Response;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.support.events.EventFiringDecorator;
Expand Down Expand Up @@ -63,16 +62,16 @@ public void quit() {
DriverFactoryHelper.closeDriver();
}

public FluentElementActions element() {
return FluentElementActions.getInstance();
public ElementActions element() {
return ElementActions.getInstance();
}

public TouchActions touch() {
return new TouchActions();
}

public FluentBrowserActions browser() {
return FluentBrowserActions.getInstance();
public BrowserActions browser() {
return BrowserActions.getInstance();
}

public AlertActions alert() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private void setupAppiumComponents() {
APPIUM_VERSION = APPIUM_VERSION.contains("info") ? APPIUM_VERSION.split("info")[0].trim() : APPIUM_VERSION.trim();

var isFirstInstall = false;
if ("".equals(APPIUM_VERSION) || APPIUM_VERSION.contains("The term 'appium' is not recognized") || !APPIUM_VERSION.startsWith("2.")) {
if (APPIUM_VERSION.contains("The term 'appium' is not recognized") || !APPIUM_VERSION.startsWith("2.")) {
//not installed or not up to date
ReportManager.logDiscrete("Removing any instance of the deprecated Appium 1.x, and installing the latest Appium 2.x server...");

Expand Down
Loading

0 comments on commit 6e6709d

Please sign in to comment.