Access additional test files for Appium tests on AWS device farm - appium

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.
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

Related

How to download multi files from swagger

I've an issue when try to download file from swagger.
When I compiled a code with config below, I got an error:
Could not find goal 'download' in plugin io.swagger:swagger-codegen-maven-plugin:2.3.1 among available goals generate
I've tried to break to 2 plugins and it compiles successfully, but just one file is downloaded.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>download</goal>
</goals>
<configuration>
<api>Addresses</api>
<owner>test</owner>
<version>2.13.0</version>
<format>yaml</format>
<token>test</token>
<outputFile>${address-service-swagger.file}</outputFile>
</configuration>
</execution>
<execution>
<id>aec</id>
<phase>generate-sources</phase>
<goals>
<goal>download</goal>
</goals>
<configuration>
<api>Shipper</api>
<owner>test</owner>
<version>2.13.0</version>
<format>yaml</format>
<token>test</token>
<outputFile>${shipper-service-swagger.file}</outputFile>
</configuration>
</execution>
</executions>
</plugin>
By the way, I want to define outputFile is a file in the folder target, and I've tried to change outputFile by the target path, but It compiles fail. Do you have any idea for this case?
Thank you for your helps
As mentioned in the comments, to download API definitions from SwaggerHub you need to use the swaggerhub-maven-plugin, not swagger-codegen-maven-plugin.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swaggerhub-maven-plugin</artifactId>
...
</plugin>
You are using the wrong plugins and you can do like this
If your swaggerhub api link is like this https://app.swaggerhub.com/apis/massivebet/betting/0.9.0 then you config this and run
mvn clean generate-resources to download as yaml file
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swaggerhub-maven-plugin</artifactId>
<version>1.0.8</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>download</goal>
</goals>
<configuration>
<api>betting</api>
<owner>massivebet</owner>
<version>0.9.0</version>
<host>api.swaggerhub.com</host>
<format>yaml</format>
<token>your token if private apis</token>-->
<outputFile>target/test.yaml</outputFile>
</configuration>
</execution>
</executions>
</plugin>

Maven Assembly : How to generate a zip file for each environment ?

I have a static project with html, js, css and conf files like this :
project
- static
- conf
conf-int.json
conf-rec.json
conf-prd.json
-js
-html
-images
- pom.xml
- assemblyDescriptor.xml
Here is my assembly descriptor :
<id>zip</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>static/conf/</directory>
</fileSet>
</fileSets>
</assembly>
Here is my build conf in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>zip.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>trigger-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I want to generate my zip with either conf-int.json or conf-rec.json or conf-prd.json corresponding to differents environments i have. If it were a java project i would use profil maven with profil and/or classifier. But i don't know how to generate a zip file for each environment with maven-assembly. Could you give me some advice please ?
You can have multiple execution defined in your assembly plugin (each with distinct execution id and different assembly descriptor file). In the respective descriptor you define which file to include.

Create datasource and deploy application

I have a maven project which creates a war file and this should be deployed to a bundled wildfly server via wildfly:run.
That works so far, but I need to create a datasource before deploying.
I have tried to bind the add-resource goal to different phases like deploy, install or package. None of them worked.
What is wrong?
An idea would be to use the wildfly:start attach an execution to add the datasource and deploy the application, but I don't know how.
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<executions>
<execution>
<id>add-datasource</id>
<phase>deploy</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<address>subsystem=datasources,data-source=java:jboss/testDB</address>
<resources>
<resource>
<properties>
<jndi-name>java:jboss/testDB</jndi-name>
<enabled>true</enabled>
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver-class>org.h2.Driver</driver-class>
<driver-name>h2</driver-name>
<user-name>sa</user-name>
<password>sa</password>
</properties>
</resource>
</resources>
</configuration>
</execution>
</executions>
My solution is to use the run goal and the beforeDeployment goal:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<beforeDeployment>
<commands>
<command>data-source add --jndi-name=java:jboss/datasources/OracleDS --name=testDB --connection-url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 --driver-name=h2 --user-name=sa --password=sa</command>
</commands>
</beforeDeployment>
</configuration>
</plugin>

move the maven-onejar generated jar to a custom location

I am using the onejar-maven-plugin to generate the jar for my project and it all goes well. But, when I try to change it to a sub-folder, for eg. dist, the jar from maven-jar-plugin gets generated, not the jar from onejar.
The onejar plugin does not have an output directory option.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<archive>
<manifest>
<mainClass>com.ss.itempriceclient.ItemPriceUploader</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<classifier>onejar</classifier>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
How do I change the output directory of the onejar generated file to a subfolder, eg. dist?
I finally went with maven-assembly-plugin. Has lots of configuration options.

m2 release plugin couldn't recognize assembly file with parameterized name

In my POM.xml file, I am using assembly plug in. I want the build to assemble things based on the assembly file, whose name is parametrized. The build works fine. However, if I use m2 release plug in using perform release action in jenkins, the release plugin could not substitute the value for $env and pick up the assembly.xml file. I get the following exception.
Caused by: org.apache.maven.plugin.assembly.io.AssemblyReadException: Error locating assembly descriptor: src/main/assembly/${env}.xml
I have attached the log and POM file.
POM file build portion:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
<execution>
<id>dist</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuraenter code heretion>
<descriptors>
<descriptor>src/main/assembly/${env}.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>

Resources