如果您尝试将文件放入项目的 src/test/java/resources/ 会发生什么?这样,它将使用 jar 构建,然后设备场可能会引用它。
[更新]
我自己使用 awslabs github 页面[1] 中的示例项目进行了尝试。我还可选地创建了一个包含此 xml 的 testng.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
<test name="test">
<classes>
<class name="file.FindFile"/>
</classes>
</test>
</suite>
此文件位于 /Referenceapp-Appium-Test/src/test/resources/testng.xml 并使用此插件从 pom.xml 中引用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
testng.xml 在这里仅用于运行特定测试,而不是示例项目中的所有测试。它是可选的,仅供参考。
然后我在同一目录中创建了一个 test.csv 文件并创建了一个新的包“文件”,其中包含一个测试类“FindFile”:
package file;
import java.io.File;
import org.testng.annotations.Test;
import Pages.BasePage;
import io.appium.java_client.AppiumDriver;
public class FindFile extends BasePage {
protected FindFile(AppiumDriver driver) {
super(driver);
// TODO Auto-generated constructor stub
}
@Test
public static void changeCity() throws InterruptedException{
try{
File src = new File("/Referenceapp-Appium-Test/src/test/resources/test.csv");
System.out.println("File found!!!");
}catch(Exception e){
System.out.println(e);
}
}
}
所以当我在设备场中使用随机 apk 执行它时,我让它只执行 FindFile.java 内部的测试。当我查看 appium java 输出时,我在那里看到了我的 println,所以我知道它是如何工作的。
[TestNG] RUNNING: Suite: "Command line test" containing "1" Tests (config: null)
[TestNG] INVOKING: "Command line test" - file.FindFile.changeCity()
[Invoker 1121172875] Invoking file.FindFile.changeCity
File found!!!
[TestNG] PASSED: "Command line test" - file.FindFile.changeCity() finished in 35 ms
===== Invoked methods
FindFile.changeCity()[pri:0, instance:null] <static>
=====
Creating /tmp/scratchLT6UDz.scratch/resultsm_f_bN/Command line suite/Command line test.html
Creating /tmp/scratchLT6UDz.scratch/resultsm_f_bN/Command line suite/Command line test.xml
PASSED: changeCity
希望有帮助
最好的问候
詹姆斯
[1]https://github.com/awslabs/aws-device-farm-appium-tests-for-sample-app