Access additional test files for Appium tests on AWS device farm

£可爱£侵袭症+ 提交于 2019-12-06 12:32:42

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!