AWS设备场 - 脚本中的额外数据路径
我的Appium脚本在本地完美工作,但转移到aws设备场,因为一个类文件返回解析错误。 我想从这个类文件中的excel文件导入数据。我认为错误是因为excel文件的路径。AWS设备场 - 脚本中的额外数据路径
我上传数据excel文件作为额外的数据,但我找不到位置。
public static void changeCity() throws InterruptedException{
try{
File src = new File("data1.xls");
Workbook wb = Workbook.getWorkbook(src);
Sheet sh1 = wb.getSheet(0);
Sheet bugzillaUpdation = wb.getSheet("UtilityCredentials");
请帮我解决这个问题。
如果您尝试将该文件放入项目的src/test/java/resources /中,会发生什么情况?这样它就可以用jar和device farm来构建,然后可以参考它。
[更新]
与示例项目从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文件用在这里只运行特定的测试,而不是在示例项目测试的全部。这是可选的,在这里用于FYI的知识。
我然后创建在同一目录中的文件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
@jmp
我使用JUnit和摆正位置为 File src = new File("/acme-android-appium/src/test/resources/data1.xls");
我不清楚你上面说的XML文件。你能解释一下我们如何在脚本中找到文件。
请看附图。
我为AWS Device Farm团队工作。
要读取.xlsx
或.csv
文件中的以下两种方法可用于:
- 确保Excel文件
src/test/resources/com/yourexcelfile.xlsx/csv
- 下放置这将在测试jar文件的文件放在下
com
夹。 - 一旦得到确认,你应该能够读取使用下面的两段代码中的一个文件:
无需任何外部库:
java.net.URL resource = ClassLoader.getSystemResource("/com/yourexcelfile.xlsx");
File file = new File(resource.toURI());
FileInputStream input = new FileInputStream(file);
OR
如果你是使用Apache POI API读取excel文件:
InputStream ins = getClass().getResourceAsStream(“/com/yourexcelfile.xlsx”);
workbook = new XSSFWorkbook(ins);
sheet = workbook.getSheetAt(1);
ins.close();
希望这有助于。
File src = new File(“/ Referenceapp -Appium-Test/src/test/resources/test.csv”);这不适合我。文件路径仍然是错误的。 –
愚蠢的问题,但你添加一个test.csv到该目录吗? – jmp
您能否提供更多关于我如何遵循我所做的事情的信息? – jmp