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

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

问题描述

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

我的 JAR 文件中有必要的文件(根据 AWS 的要求,它位于 zip 文件中),但我不确定在测试运行期间 AWS 是否以及在哪里从该 JAR 中提取文件(可能不会).

有一个名为 Add extra data 的选项可用于上传文件,但我不确定如何从我的代码中访问它们.文档指出:

<块引用>

对于iOS,额外的数据其实在app安装里面directory [...] 在 Android 上,我们将其解压缩到SD卡.

这是否意味着我需要从手机中提取文件(Appium 可以这样做)并将它们放在某个临时文件夹中?我也可以尝试从 git repo 或 web 共享中提取文件,但我希望有一种更简单的方法来访问文件系统.另一个问题是是否有一些限制根本不允许我写入文件系统.

有人有这方面的经验吗?

解决方案

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

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

    您提到的额外数据功能只会在设备中放置额外的文件,而不会在运行测试的设备主机中放置.还使用 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天全站免登陆