问题
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?
回答1:
There are two way that I know of to access additional files on the device host.
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(); }
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
来源:https://stackoverflow.com/questions/50361940/access-additional-test-files-for-appium-tests-on-aws-device-farm