GithubHelp home page GithubHelp logo

lholmquist / arquillian-extension-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arquillian/arquillian-extension-android

0.0 3.0 0.0 7.03 MB

Arquillian Android Platform Containers

arquillian-extension-android's Introduction

Arquillian Extension for the Android Platform

This extensions allows you to bring Arquillian Drone WebDriver based testing to Android devices. Extensions currently supports:

  • Creating new Android Virtual Devices
  • Reusing already existing Android Virtual Devices
  • Connecting to real devices

Usage

You have to do following steps, expecting your project was already set up to use Drone

  1. Download Android SDK from http://developer.android.com/sdk/index.html and point ANDROID_HOME system variable to directory where you extracted it. You should also update it via running android and navigating in the GUI.

  2. Add Android extension to dependencies

     <dependency>
         <groupId>org.jboss.arquillian.extension</groupId>
         <artifactId>arquillian-android-depchain</artifactId>
         <version>1.0.0.Alpha1-SNAPSHOT</version>
         <type>pom</type>
         <scope>test</scope>
     </dependency>
    

    *Note: Make sure you have NOT Arquillian Drone Selenium Server on the classpath, as it will collide unless configured to a different port. If you cannot remove it from classpath, you should disable it in arquillian.xml.

     <extension qualifier="selenium-server">
         <!-- this must be skipped, we run /wd/hub on emulator -->
         <property name="skip">true</property>
     </extension>
    
  3. Download Android Server APK to be installed to you mobile device from http://code.google.com/p/selenium/downloads/list Use android-server-2.6.0.apk for devices including Android 2.3.4, latest version for Android 3.0 and newer.

  4. Set up WebDriver in arquillian.xml

     <extension qualifier="webdriver">
         <!-- this is optional if you set -->
         <property name="implementationClass">org.openqa.selenium.android.AndroidDriver</property>
         <!-- this makes WebDriver connect hub on Android device -->
         <property name="remoteAddress">http://localhost:14444/wd/hub</property>
     </extension>
    
  5. Set up Android in arquillian.xml

    You should be aware that following might change in the future. You've been warned!

     <extension qualifier="android">
         <!-- this is optional, can be set via ANDROID_HOME property -->
         <property name="home">/home/kpiwko/apps/android-sdk-linux_x86</property>
         <!-- Nexus S -->
         <!-- <property name="serialId">3233E8EDB21700EC</property>-->
    
         <property name="apiLevel">13</property>
         <property name="avdName">SnapshotEnabled</property>
         <property name="emulatorBootupTimeoutInSeconds">180</property>
     </extension>
    

    Properties explained, required in bold:

    • home - ANDROID_HOME, can be ommited if set via ANDROID_HOME property
    • avdName - name of the Android Virtual Device. It will be either created or reused
    • apiLevel - (13) denotates API level, use android list target to get more variants
    • serialId - replaces avdName if set and availabel, represents a real device. Use adb devics to get the list
    • skip - (false) skip execution
    • force - (false) force emulator recreationg
    • sdSize - (128M) SD card size for emulator
    • emulatorBootupTimeoutInSeconds - (180) maximal time to get emulator started, use Snapshot enabled device if it takes too long
    • emulatorOptions - emulator options
    • abi - specify ABI

    Emulators are created by default in ${basedir}/${avdName}.

  6. Set up Android Drone in arquillian.xml

    You should be aware that following might change in the future. You've been warned!

     <extension qualifier="android-drone">
         <property name="androidServerApk">android-server-2.16.apk</property>
     </extension>
    

    Properties explained, required in bold:

    • androidServerApk - path to the Android Server APK you've downloaded
    • skip - (false) skip execution
    • webdriverPortHost - (14444) port on Host connected with port on device
    • webdriverPortGuest - (8080) port on Guest connected with port on Host

Interacting with Android Device from a test

You have the possibility to inject an instance of AndroidDevice into test using @ArquillianResource annotation. This is handy if you want for instance execute a shell command on the device or install an application, like in following:

@ArquillianResource AndroidDevice device;

@RunWith(Arquillian.class)
public class AndroidApkInstallationTestCase {

    private final String INSTALLED_PACKAGES_CMD = "pm list packages";
    private final String CALCULATOR_APP = "com.calculator";

    @ArquillianResource
    AndroidDevice device;

    @Test
    public void installAndUninstallApk() throws AndroidExecutionException {
        device.installPackage(new File("src/test/apk/calculator.apk"), true);

        List<String> installedApps = getInstalledPackages(device);

        Assert.assertTrue("Calculator app was installed", installedApps.contains(CALCULATOR_APP));

        device.uninstallPackage(CALCULATOR_APP);

        installedApps = getInstalledPackages(device);
        Assert.assertFalse("Calculator app was uninstalled", installedApps.contains(CALCULATOR_APP));
    }
}

Logging

If you need to have more detailed logging, you have to provide logging.properties file as well as set it in Surefire plugin. Logging file can look like:

handlers= java.util.logging.ConsoleHandler

.level= FINEST

java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = %4$s: %5$s
java.util.logging.ConsoleHandler.level = FINEST

If you placed this file in src/test/resources/logging.propreties, Surefire execution will pick it up if following is defined:

<build>
    ...
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <systemPropertyVariables>
                    <java.util.logging.config.file>${project.build.testOutputDirectory}/logging.properties</java.util.logging.config.file>
                </systemPropertyVariables>
            </configuration>
        </plugin>
    </plugins>
    ...
</build>

arquillian-extension-android's People

Contributors

kpiwko avatar aslakknutsen avatar papousek avatar

Watchers

James Cloos avatar Lucas Holmquist avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.