Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
package config;

import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.entity.mime.FileBody;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.OutputType;
import org.apache.commons.io.FileUtils;
import org.testng.ITestListener;
import org.testng.ITestResult;
import org.testng.ITestContext;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -33,25 +24,24 @@ public class CustomTestListener implements ITestListener {
// List to store test results
private final List<ITestResult> testResults = new ArrayList<>();

// This method is called when a test starts
@Override
public void onTestStart(ITestResult result) {
System.out.println("Test started: " + result.getName());
}

// This method is called when a test passes
@Override
public void onTestSuccess(ITestResult result) {
System.out.println("Test passed: " + result.getName());
testResults.add(result); // Store the passed test result
testResults.add(result);
}

// This method is called when a test fails
@Override
public void onTestFailure(ITestResult result) {
System.out.println("Test failed: " + result.getName());
testResults.add(result); // Store the failed test result
testResults.add(result);

// Screenshot capture is currently disabled
/*
if (driver != null) {
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

Expand All @@ -63,29 +53,26 @@ public void onTestFailure(ITestResult result) {
e.printStackTrace();
}
}
*/
}

// This method is called when a test is skipped
@Override
public void onTestSkipped(ITestResult result) {
System.out.println("Test skipped: " + result.getName());
testResults.add(result); // Store the skipped test result
testResults.add(result);
}

// This method is called before the test suite starts
@Override
public void onStart(ITestContext context) {
System.out.println("Test suite started: " + context.getName());
}

// This method is called after the test suite finishes
@Override
public void onFinish(ITestContext context) {
System.out.println("Test suite finished: " + context.getName());
sendSlackNotification(); // Send Slack notification at the end of the suite
sendSlackNotification();
}

// Utility method to get status string based on result status
private String getStatus(int status) {
switch (status) {
case ITestResult.SUCCESS:
Expand All @@ -99,26 +86,29 @@ private String getStatus(int status) {
}
}

// Method to retrieve the collected test results
public List<ITestResult> getTestResults() {
return testResults;
}

// Method to send a Slack notification with the summary of results
private void sendSlackNotification() {
List<ITestResult> results = getTestResults();

StringBuilder resultMessage = new StringBuilder();
int passed = 0;
int failed = 0;
int skipped = 0;

for (ITestResult result : results) {
if (result.getStatus() == ITestResult.SUCCESS) {
passed++;
} else if (result.getStatus() == ITestResult.FAILURE) {
failed++;
} else if (result.getStatus() == ITestResult.SKIP) {
skipped++;
switch (result.getStatus()) {
case ITestResult.SUCCESS:
passed++;
break;
case ITestResult.FAILURE:
failed++;
break;
case ITestResult.SKIP:
skipped++;
break;
}
}

Expand All @@ -131,7 +121,6 @@ private void sendSlackNotification() {
sendSlackMessage(resultMessage.toString());
}

// Method to send the formatted result message to Slack
private void sendSlackMessage(String message) {
try {
CloseableHttpClient client = HttpClients.createDefault();
Expand All @@ -149,5 +138,4 @@ private void sendSlackMessage(String message) {
System.err.println("Failed to send Slack notification.");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,12 @@
import java.io.IOException;

public class StartAppiumServer {
// public static void startAppium1(String AppiumPort) {
// ProcessBuilder processBuilder = new ProcessBuilder("node", "C:\\Users\\nas\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js");
// processBuilder.redirectErrorStream(true);
// processBuilder.redirectOutput(new File("appium.log")); // Redirect output to a log file
//
// try {
// Process process = processBuilder.start();
// // Wait for the server to start
// Thread.sleep(5000); // Adjust the sleep time if necessary
// } catch (IOException | InterruptedException e) {
// e.printStackTrace();
// }
// }


public static void startAppium(String AppiumPort) {
ProcessBuilder processBuilder = new ProcessBuilder("node", "C:\\Users\\nas\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js","--port",AppiumPort);
ProcessBuilder processBuilder = new ProcessBuilder("node", "\\npm\\node_modules\\appium\\build\\lib\\main.js","--port",AppiumPort);
processBuilder.redirectErrorStream(true);
processBuilder.redirectOutput(new File("C:\\Users\\nas\\Desktop\\appium.log")); // Redirect output to a log file
processBuilder.redirectOutput(new File("")); // Redirect output to a log file

try {
Thread.sleep(5000); // Adjust the sleep time if necessary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,5 @@ public void createConcordionAccount() throws MalformedURLException {
public void tearDown(){
driver.quit();
}

@AfterSuite
public void TestMoResults() throws InterruptedException {

Thread.sleep(5000);
String batchFilePath = "C:\\Users\\nas\\Desktop\\TestMo.bat"; // Update this path
runBatchFile(batchFilePath);
System.out.println("Start posting resutls to testmo");
}



}