Appium AWS设备场-脚本中的额外数据路径

Appium AWS设备场-脚本中的额外数据路径,appium,Appium,我的Appium脚本在本地运行良好,但移动到aws设备场时,由于一个类文件而返回解析错误。 我正在尝试从此类文件中的excel文件导入数据。我想这是因为excel文件的路径错误 我将数据excel文件作为额外数据上传到aws中,但找不到位置 public static void changeCity() throws InterruptedException{ try{ File src = new File("data1.xls"); Workbook wb = Workboo

我的Appium脚本在本地运行良好,但移动到aws设备场时,由于一个类文件而返回解析错误。 我正在尝试从此类文件中的excel文件导入数据。我想这是因为excel文件的路径错误

我将数据excel文件作为额外数据上传到aws中,但找不到位置

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"); 
请帮我解决这个问题


@jmp

我使用junit并将位置设置为
File src=new文件(“/acmeandroid-appium/src/test/resources/data1.xls”)

我不清楚您上面提到的XML文件。你能解释一下如何在我的脚本中找到文件吗

请看附件中的图片


如果尝试将文件放入项目的src/test/java/resources/中,会发生什么情况?这样,它将使用jar构建,设备场可能会引用它

[更新]

我自己在AWHUB页面[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>
因此,当我使用随机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
[TestNG]正在运行:套件:“命令行测试”包含“1”个测试(配置:null)
[TestNG]调用:“命令行测试”-file.FindFile.changeCity()
[Invoker 1121172875]调用file.FindFile.changeCity
找到文件!!!
[TestNG]通过:“命令行测试”-file.FindFile.changeCity()在35毫秒内完成
====调用的方法
FindFile.changeCity()[pri:0,实例:null]
=====
创建/tmp/scratchLT6UDz.scratch/resultsm_f_bN/Command line suite/Command line test.html
创建/tmp/scratchLT6UDz.scratch/resultsm_f_bN/Command line suite/Command line test.xml
通过:变更城市
希望有帮助

致意

詹姆斯


[1] 我为AWS设备场团队工作

要读取
.xlsx
.csv
文件,可以使用以下两种方法:

  • 确保excel文件位于
    src/test/resources/com/yourexcelfile.xlsx/csv
  • 这将把文件放在
    com
    文件夹下的测试jar文件中
  • 确认后,您应该能够使用以下两个代码段之一读取文件:
  • 没有任何外部库:

    java.net.URL resource = ClassLoader.getSystemResource("/com/yourexcelfile.xlsx");
    File file = new File(resource.toURI());
    FileInputStream input = new FileInputStream(file);
    

    如果您使用Apache POI API读取excel文件:

    InputStream ins = getClass().getResourceAsStream(“/com/yourexcelfile.xlsx”);
    workbook = new XSSFWorkbook(ins);
    sheet = workbook.getSheetAt(1);
    ins.close();
    

    希望这有帮助。

    File src=new文件(“/Referenceapp-Appium-Test/src/Test/resources/Test.csv”);这不适合我。文件路径仍然是错误的。愚蠢的问题,但你添加了一个test.csv到该目录对吗?你能提供更多的信息,你如何遵循我所做的吗?请检查后,包括屏幕截图。我将评论作为答案发布。我还没有测试过这个想法,但是如果这是一个maven项目,并且测试被压缩并上传,为什么不在压缩的测试包中包含额外的文件呢?编写maven插件并将其添加到插件中应该相当容易。在写入之前,请尝试添加文件并在设备场中访问它。
    java.net.URL resource = ClassLoader.getSystemResource("/com/yourexcelfile.xlsx");
    File file = new File(resource.toURI());
    FileInputStream input = new FileInputStream(file);
    
    InputStream ins = getClass().getResourceAsStream(“/com/yourexcelfile.xlsx”);
    workbook = new XSSFWorkbook(ins);
    sheet = workbook.getSheetAt(1);
    ins.close();