如何从 java 应用程序远程启动 UFT Mobile 测试脚本?
我正在开发一个java应用程序,该应用程序将用于在相关服务器上远程启动UFT Mobile脚本,从中下载测试结果,然后分析报告,以便将结果保存在特定数据库中。
我写这篇文章是为了寻求帮助。
该应用程序将具有以下步骤:
- 文件属性,我在其中读取脚本名称和应用程序所需的一些属性
- 将用于连接到 UFT Mobile 的移动中心的类,以便通过 Mobile Center API 安装应用程序将进行测试
- 将连接到服务器并开始执行步骤 2 中安装的应用程序的测试脚本的
- 类 下载测试结果/日志,以便分析报告并将结果保存在数据库中
步骤 2(UFTLabUtils 是一个与Mobile相关的API类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;
}
}
}
问题出在步骤 3 上,我找不到执行 UFT Mobile Server 保存的脚本的方法。 我在互联网上查找,发现了一些我自定义的片段代码:
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;
}
}
所有所需的功能都是从外部读取的,特别是从输入到 java 应用程序的文件属性中读取的。 问题是:连接到移动中心,特别是连接到集线器(wd/hub)后,如何启动并启动保存在服务器(而不是本地)上的测试脚本?
此外,我查看了有关“executeScript”方法的文档,但它用于运行 JavaScript 代码/命令。
更新:我还发现了这个片段:
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();
}
}
它似乎用于启动 UFT 脚本,但在本地计算机上。它也可以用于远程服务器吗?在这种情况下,我如何连接到服务器并启动脚本?
感谢支持!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论