I'm developing a java application that will be used to launch remotely the UFT Mobile scripts, on related server, download the test result from it and then analyze the report in order to save the results on a specific database.
I'm writing this post in order to ask a help about it.
The application will have the following steps:
- A file properties where I read the name of scripts and some properties needed for application
- A class that will be used to connect to the Mobile Center of UFT Mobile in order to install through Mobile Center API the application that will be under the test
- A class that will connect to the server and start the execution of test script of application installed on step 2
- Download the test result/logs in order to analyze the report and save the result on database
Step 2 (UFTLabUtils is a class of API related to Mobile Center):
package uft;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.lang3.exception.ExceptionUtils;
public class UploadFile {
public static boolean uploadFile(Properties myPropertiesFile) throws IOException {
final String MC_SERVER = myPropertiesFile.getProperty("CLOUD_NAME").toLowerCase();
final String USERNAME = myPropertiesFile.getProperty("USERNAME");
final String PASSWORD = myPropertiesFile.getProperty("PASSWORD");
final String PACKAGE = myPropertiesFile.getProperty("PACKAGE");
final String VERSION = myPropertiesFile.getProperty("VERSION");
final String DEVICE_ID = myPropertiesFile.getProperty("DEVICE_ID");
final Boolean STRUMENTED = true;
try {
UFTLabUtils client = new UFTLabUtils(USERNAME, PASSWORD, MC_SERVER);
client.login(USERNAME, PASSWORD);
client.installApp(PACKAGE, VERSION, DEVICE_ID, STRUMENTED);
client.logout();
return true;
}catch(Exception e) {
System.err.println("Si è verificato un errore nella uploadFile: ");
String exc = ExceptionUtils.getStackTrace(e);
System.err.println(exc);
System.exit(-1);
return false;
}
}
}
The problem is on the step 3, where I cannot find a way to execute the script saved of UFT Mobile Server. I'm looking on internet and I found some snippet code like this that I customized:
package uft;
import java.util.HashMap;
import java.util.Properties;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.http.client.utils.URIBuilder;
import org.json.JSONObject;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
import java.net.URI;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
public class StartExecution {
@SuppressWarnings("unused")
public static String startExecution(Properties myPropertiesFile) {
final String MC_SERVER = myPropertiesFile.getProperty("CLOUD_NAME");
final String MC_SERVER_CLIENT_ID = myPropertiesFile.getProperty("MC_SERVER_CLIENT_ID");
final String MC_SERVER_CLIENT_SECRET = myPropertiesFile.getProperty("MC_SERVER_CLIENT_SECRET");
final String MC_SERVER_TENANT_ID = myPropertiesFile.getProperty("MC_SERVER_TENANT_ID");
final String MC_SERVER_WORKSPACE_NAME = myPropertiesFile.getProperty("MC_SERVER_WORKSPACE_NAME");
try {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("oauthClientId", MC_SERVER_CLIENT_ID);
capabilities.setCapability("oauthClientSecret", MC_SERVER_CLIENT_SECRET);
capabilities.setCapability("tenantId", MC_SERVER_TENANT_ID);
capabilities.setCapability("mcWorkspaceName", MC_SERVER_WORKSPACE_NAME);
switch (myPropertiesFile.getProperty("OS").toUpperCase()) {
case "ANDROID":
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.Advantage.aShopping");
capabilities.setCapability("appActivity", "com.Advantage.aShopping.SplashActivity");
AndroidDriver wd = new AndroidDriver(new URL(MC_SERVER + "/wd/hub"), capabilities);
wd.executeScript(MC_SERVER_WORKSPACE_NAME, null);
HashMap<String, String> encoding= new HashMap<String, String>();
encoding.put("encoding", "UTF-8");
String logFileContents = (String) wd.executeScript("mc-wd: downloadLogs", encoding);
case "IOS":
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("bundleId", "com.Advantage.aShopping");
IOSDriver wd2 = new IOSDriver(new URL(MC_SERVER + "/wd/hub"), capabilities);
wd2.executeScript(MC_SERVER_WORKSPACE_NAME, null);
HashMap<String, String> encoding2= new HashMap<String, String>();
encoding2.put("encoding", "UTF-8");
String logFileContents2 = (String) wd2.executeScript("mc-wd: downloadLogs", encoding2);
}
return null;
}catch(Exception e) {
System.out.println("Si è verificato un problema nella startExecution: ");
String exc = ExceptionUtils.getStackTrace(e);
System.err.println(exc);
System.exit(-1);
return null;
}
}
All desired capabilities are read from external, in particular from the file properties that is in input to the java application. The question is: after the connection to the mobile center, in particular, to the hub (wd/hub), how can I start and launch a test script that is saved on server (not in local)?
Furthermore, I looked the documentation about the method 'executeScript', but it is used to run a JavaScript code/command.
UPDATE: I also found this snippet:
public static void main(String args[]) {
try {
PrintStream out = new PrintStream(new FileOutputStream("LaunchQTP.vbs"));
out.println("Set qtApp = CreateObject(\"QuickTest.Application\")");
out.println("qtApp.Launch");
out.println("qtApp.Visible = True");
out.close();
Process p = Runtime.getRuntime().exec("cscript LaunchQTP.vbs");
p.waitFor();
out.println(p.exitValue());
} catch (Exception err) {
err.printStackTrace();
}
}
that seems to be used for launch a UFT scripts but on local machine. Could it be used also for remotely server? In this case how can i connect to the server and launch the script?
Thanks for supporting!