我是新来编写测试用例的人。在我们的项目之一中,我们需要编写XCUITestcase,它是在Perfecto上使用Appium执行的。 Perfecto通过在config.json文件中提供测试用例名称,提供了独立的命令来执行特定的测试用例。下面是我用来运行测试用例的json。
{
"cloudURL": "mycloud.perfectomobile.com",
"securityToken": "Mysecurity Token",
"devices": [
{"deviceName" : "UDID"}
],
"appPath": "repository://PRIVATE:/<App IPA Path>",
"testAppPath": "repository://PRIVATE:/<App Runner IPA Path>",
"testMethodNames": ["ClassName#testLogin"],
"tags" : [],
"projectName" : "IOS-XCUITest",
"projectVersion" : "v10.9-test",
"jobName" : "LoginInApp",
"jobNumber" : 2,
"debug":true,
"branch" : "master",
"runUiTests": true,
"runUnitTests": false
}
现在,当我执行perfecto给出的gradle命令gradle perfecto-xctest
时。步骤
使用gradle命令,一切正常。现在,我们尝试使用Java中的Appium Automation脚本执行相同的操作。
这是应用程序自动化的代码
public class AppiumTest {
public static void main(String[] args) throws MalformedURLException, IOException {
System.out.println("Run started");
String browserName = "mobileOS";
DesiredCapabilities capabilities = new
DesiredCapabilities(browserName, "", Platform.ANY);
String host = "mycloud.perfectomobile.com";
capabilities.setCapability("user", "userEmail");
capabilities.setCapability("password", "password");
//TODO: Change your device ID
capabilities.setCapability("deviceName", "udid of device");
// Use the automationName capability to define the required framework - Appium (this is the default) or PerfectoMobile.
capabilities.setCapability("automationName", "XCUITest");
// Call this method if you want the script to share the devices with the Perfecto Lab plugin.
PerfectoLabUtils.setExecutionIdCapability(capabilities, host);
// For iOS:
capabilities.setCapability("bundleId","com.apple.test.TestAppUITests-Runner");
// Name your script
// capabilities.setCapability("scriptName", "AppiumTest");
IOSDriver driver = new IOSDriver(new URL("https://" + host + "/nexperience/perfectomobile/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
// Reporting client. For more details, see http://developers.perfectomobile.com/display/PD/Reporting
PerfectoExecutionContext perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder()
.withProject(new Project("My Project", "1.0"))
.withJob(new Job("My Job", 45))
.withContextTags("tag1")
.withWebDriver(driver)
.build();
ReportiumClient reportiumClient = new ReportiumClientFactory().createPerfectoReportiumClient(perfectoExecutionContext);
try {
reportiumClient.testStart("My test name", new TestContext("tag2", "tag3"));
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.launchApp();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
reportiumClient.testStop(TestResultFactory.createSuccess());
} catch (Exception e) {
reportiumClient.testStop(TestResultFactory.createFailure(e.getMessage(), e));
e.printStackTrace();
} finally {
try {
driver.quit();
// Retrieve the URL to the DigitalZoom Report (= Reportium Application) for an aggregated view over the execution
String reportURL = reportiumClient.getReportUrl();
System.out.println("reportURL " + reportURL);
// Retrieve the URL to the Execution Summary PDF Report
String reportPdfUrl = (String)(driver.getCapabilities().getCapability("reportPdfUrl"));
System.out.println("reportPdfUrl " + reportURL);
// For detailed documentation on how to export the Execution Summary PDF Report, the Single Test report and other attachments such as
// video, images, device logs, vitals and network files - see http://developers.perfectomobile.com/display/PD/Exporting+the+Reports
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("Run ended");
}
}
当我在java文件上运行时,它启动我的跑步程序,但随后继续尝试启动跑步程序。我的问题是启动我在XCUITest中编写的特定测试用例。我不知道应该设置哪些功能,以及使用Appium脚本执行特定测试用例需要使用哪种方法。我想使用XCUITestcase执行自动化,并且应该使用Appium脚本启动。
注意:-上面的appium脚本可以正常工作,但是可以获取设备,但是我不知道如何执行XCUI测试用例