访问AWS设备场上的Appium测试的其他测试文件 [英] Access additional test files for Appium tests on AWS device farm

查看:87
本文介绍了访问AWS设备场上的Appium测试的其他测试文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在AWS设备场上使用JUnit运行Appium测试。有没有办法上传其他测试文件并从我的代码中访问它们?因此,基本上,我可以访问运行Appium测试的容器的文件系统吗?



我的JAR文件中有必要的文件(按照AWS要求),但我不确定在测试运行期间AWS是否在何处从该JAR中提取文件(可能不是)。



有一个名为<$的选项c $ c>添加额外的数据可用于上传文件,但我不确定如何从代码中访问它们。该文档指出:


对于iOS,多余的数据实际上位于应用程序安装的
目录中[...]在Android上,我们将其取消存档在
sdcard的根目录中。


这是否意味着我需要从文件中提取文件电话(Appium可以做到)并将它们放在一些临时文件夹中?我也可以尝试从git repo或Web共享中提取文件,但我希望有一种更简单的方法来访问文件系统。另一个问题是是否存在一些限制,使我根本无法写入文件系统。



有人对此有任何经验吗?

解决方案

我知道有两种方法可以访问设备主机上的其他文件。


  1. 将其包含在jar中(就像您已经做的那样),然后使用当前线程访问文件。



    额外您提到的data 功能只会在设备中放置其他文件,而不会在运行测试的设备主机中放置其他文件。我还使用appium来拉入和推入文件,我相信只能在模拟器上使用,而目前在实际设备上无法使用。



    https://discuss.appium.io/t/pull-file-from-ios-device/1541/3



    -詹姆斯


    I am running Appium tests with JUnit on AWS device farm. Is there a way to upload additional test files and access them from within my code? So basically, can I access the file system of the container that runs the Appium tests?

    I have the necessary files within my JAR file (which is inside a zip as per AWS requirements) but I'm not sure if and where AWS extracts the files from this JAR during the test run (probably not).

    There is an option called Add extra data which can be used to upload files but I'm not sure how to access them from within my code. The documentation states:

    For iOS, the extra data is actually inside the app installation directory [...] On Android, we unarchive it in a root directory of the sdcard.

    Does this mean I would need to pull the files from the phone (Appium could do that) and put them in some temp folder? I could also try to pull the files from a git repo or a web share but I was hoping there would be a simpler way to access the file system. Another concern is whether there is some restriction which wouldn't allow me to write to the file system at all.

    Does anyone have any experience with this?

    解决方案

    There are two way that I know of to access additional files on the device host.

    1. Include it in the jar(as you're already doing) and then access the files using the current thread. SO Post where I did this

      InputStream input = null;
      //load in the properties file from src/test/resources 
      try {
      
          input = Thread.currentThread().getContextClassLoader().getResourceAsStream("myproperties.properties");
      
          // load a properties file
          prop.load(input);
      
          // get the property value and print it out
          System.out.println(prop.getProperty("devicefarm"));
      
      } catch (IOException ex) {
          ex.printStackTrace();
      }
      

    2. Include it in the zip uploaded to Device Farm using the copy resources plugin.

    POM:

    <build>
      <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.6</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>test-jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                    <executions>
                        <execution>
                            <id>copy-resources</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/dependency-resources</outputDirectory>
                                <resources>
                                    <resource>
                                        <directory>src/test/resources</directory>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.5.4</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                            <configuration>
                                <finalName>zip-with-dependencies</finalName>
                                <appendAssemblyId>false</appendAssemblyId>
                                <descriptors>
                                    <descriptor>src/main/assembly/zip.xml</descriptor>
                                </descriptors>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    </plugins>
    </build>
    

    ZIP.xml:

    <assembly 
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 " 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0    http://maven.apache.org/xsd/assembly-1.1.0.xsd">
        <id>zip</id>
        <formats>
            <format>zip</format>
        </formats>
        <includeBaseDirectory>false</includeBaseDirectory>
        <fileSets>
            <fileSet>
                <directory>${project.build.directory}</directory>
                <outputDirectory>./</outputDirectory>
                <includes>
                    <include>*.jar</include>
                </includes>
            </fileSet>
            <fileSet>
                <directory>${project.build.directory}</directory>
                <outputDirectory>./</outputDirectory>
                <includes>
                    <include>/dependency-jars/</include>
                </includes>
            </fileSet>
            <fileSet>
                <directory>${project.build.directory}</directory>
                <outputDirectory>./</outputDirectory>
                <includes>
                    <include>/dependency-resources/</include>
                </includes>
            </fileSet>
        </fileSets>
    </assembly>
    

    We can then access the additional files that are packaged in the zip uploaded to Device Farm using the path ./dependency-resources/somefilename

    Device Farm's SDK will unzip the test package to the Device host machine to the /tmp directory. If you export the /tmp directory on the specify device state page you can export the same test package you uploaded using custom artifacts.

    The extra data feature you mentioned will only put additional files in the device and not the device host running the tests. Also using appium to pull and push files I believe only works on simulators and not real device currently.

    https://discuss.appium.io/t/pull-file-from-ios-device/1541/3

    -James

    这篇关于访问AWS设备场上的Appium测试的其他测试文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆