Friday, September 11, 2015

GPU-emulation for Android Emulator on a headless Linux

Eventually Google've released GPU emulation to public with new SDK 24.3.4

With GPU-EMULATION  it is possible to move your Android test farm to clouds like AWS without pay lots of money for instances with GPU.

Here is a how-to configure a headless GNU/Linux for Android with GPU emulation.

# install packages for android sdk
dpkg --add-architecture i386
apt-get update
apt-get install libncurses5:i386 libstdc++6:i386 zlib1g:i386 lib32stdc++6 lib32z1 -y

# install Xorg (along with 32bit libs) for emulator to work with imaginary GPU
apt-get install xserver-xorg xserver-xorg-video-dummy x11-xserver-utils \
 x11vnc libgl1-mesa-dev libx11-6 libx11-dev libx11-6:i386 libx11-dev:i386 -y

# create config file /etc/X11/xorg.conf

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "Files"
EndSection

Section "InputDevice"
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
    HorizSync       28.0 - 33.0
    VertRefresh     43.0 - 72.0
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "dummy"
    VendorName     "Dummy Corporation"
    Option "NoDDC" "true"
    Option "IgnoreEDID" "true"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "NoLogo" "True"
    Option         "UseDisplayDevice" "none"
    SubSection     "Display"
        Virtual     1024 768
        Depth       24
    EndSubSection
EndSection

# start Xorg
Xorg :0


# get fresh SDK
wget http://dl.google.com/android/android-sdk_r24.3.4-linux.tgz
.....

# do not forget about environment variables
JAVA_HOME=...

ANDROID_HOME=/usr/local/android/android-sdk-linux

LD_LIBRARY_PATH=${ANDROID_HOME}/tools/lib/gles_mesa:${ANDROID_HOME}/tools/lib/:${LD_LIBRARY_PATH}

PATH=${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${PATH}

export JAVA_HOME ANDROID_HOME PATH LD_LIBRARY_PATH

# after creating android virtual device, add to config.ini :
hw.gpu.enabled=true
hw.gpu.mode=mesa


# start emulator
DISPLAY=:0 emulator -avd a442 -no-boot-anim -noaudio -no-jni -gpu mesa

# see in logs
emulator: Initializing hardware OpenGLES emulation support
emulator: OpenGL Vendor=[Google (VMware, Inc.)]
emulator: OpenGL Renderer=[Android Emulator OpenGL ES Translator (Gallium 0.4 on llvmpipe (LLVM 3.5, 256 bits))]
emulator: OpenGL Version=[OpenGL ES 2.0 (3.0 Mesa 10.4.2 (git-))]

Ansible Rocks

Even when you don't want to create playbooks http://docs.ansible.com/ansible/intro_adhoc.html

Real help with farms of virtual appliances in OpenStack or AWS

Saturday, August 29, 2015

iOS 8 Safari screenshots with variable browser header height

Capturing shots when a browser has variable header height
In iOS 8 Safari comes with a feature when browser's header might be 65px or 41px (when address bar is hidden on scroll, aka minimal-ui) .


For example to capture pages on iPad 2 one could use AShot utility with a strategy that can detect current height of browser's header.

int minHeader = 41;
int maxHeader = 65;
int minViewPortHeight = 960; // Height of viewport when address bar shown
HeaderDetectionStrategy strategy =
    new VariableHeaderDetectionStrategy(minHeader, maxHeader, minViewPortHeight);
new AShot()
  .shootingStrategy(new ViewportPastingStrategy(strategy))
  .takeScreenshot(webDriver);
When in JavaScript to guess the height of browser's header - whether address bar is shown, window.innerHeight property could be used.

Wednesday, July 22, 2015

Android remote control - Smartphone Test Farm

Really great piece of software for a QA engineer and even for a QA team!

Allows to control and manage real Android smartphone devices from your browser.


Tuesday, July 7, 2015

Maven-style continuous delivery

Let's say you have a java program.
Also you have a continuous integration server,
that builds java jar file (artifact) and deploys it to artifactory
(or you just use mvn clean compile deploy to upload latest version to artifactory).

Let's say you also have a bunch of hosts that suppose to run the artifact.
How do you deploy (deliver) the artifact to all the hosts?

We'll use maven for that - exec:java goal and dependency management would help a lot.

On target hosts:

1. create file pom.xml (a bit of xml)

    <modelVersion>4.0.0</modelVersion>

    <groupId>my.cool.sw</groupId>
    <artifactId>cool-program</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>my.cool.sw</groupId>
            <artifactId>my-cool-deployed-jar</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

2. exec 
mvn exec:java -Dexec.mainClass="my.cool.sw.MainClass"


That's it.
  • No need to copy jar file to hosts each time sw is updated and uploaded to artifactory.
  • All the hosts would run latest possible version from artifactory.
  • Easy to automate and to maintain.

Thursday, June 11, 2015

Maven single jar with dependencies

just add the following to pom.xml file

<build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>fully.qualified.MainClass</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>

  </build>

and you run it with
mvn clean compile assembly:single
Compile goal should be added before assembly:single or otherwise the code on your own project is not included.
See more details in comments.

Commonly this goal is tied to a build phase to execute automatically. This ensures the JAR is built when executing mvn install or performing a deployment/release.

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <mainClass>fully.qualified.MainClass</mainClass>
        </manifest>
      </archive>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id>
 <!-- this is used for inheritance merges -->
        <phase>package</phase>
 <!-- bind to the packaging phase -->
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>


src: StackOverflow :-)

Wednesday, June 10, 2015

TextArea scrollbar width in Firefox

To get scroll bar width of text area - use

element.offsetWidth - element.clientWidth

spent an hour fighting with scroll bar....

Friday, April 10, 2015

Java Mission Control - profiling at your hands

Just add this to your java arg line

-XX:+UnlockCommercialFeatures
-XX:+UnlockExperimentalVMOptions
-XX:-UseFastUnorderedTimeStamps
-XX:+FlightRecorder
-XX:StartFlightRecording=duration=120m,filename=recording1.jfr


when java app exits, file recording1.jfr will be available for viewing with Java Mission Control
since JDK 1.7.40

Thursday, April 9, 2015

Thread stop in Java

Install Oracle's JDK to any linux again

untargz java jdk distro

define JAVA_HOME and export it

cd $JAVA_HOME/bin

fix alternatives - use as root or append sudo

for i in `ls`; do update-alternatives --install "/usr/bin/$i" "$i" "`pwd`/$i" 1; done;


Find files and tar them

/note to myself

Finding files with most powerful utility find sending them to tarball
  find . -maxdepth 2 -type f -print0 | tar -czvf backup.tar.gz --null -T -  

It will:
  • deal with files with spaces, newlines, leading dashes, and other funniness
  • handle an unlimited number of files
  • won't repeatedly overwrite your backup.tar.gz like using tar -c with xargs will do when you have a large number of files

chrome dev tools truncate text in console

Things can get long.
For example location.href.

To copy looong location.href to clipboard with chrome dev tools use 

copy(location.href)

Start Google Chrome on Android Emulator

Prepare Android emulator

  • Use Android emulator with enabled GPU - start emulator with -gpu on 
  • Use larger system and data partition - start emulator with -partition-size 1024


Get a binary of Chrome - I use apk from http://www.apkmirror.com/apk/google-inc/chrome/

adb install com.android.chrome...apk


For web test automation one can use appium bundled with chromedriver, as well as chromedriver solely.


Thursday, February 19, 2015

Android SDK and Maven project

Haven't found modern android.jar on mvnrepo (only some old from2012).

So to add android 19 to your maven project:


1st: Install android jars as dependencies to your local repo (~/.m2)

cd ${ANDROID_HOME}/platforms/android-19


$ mvn install:install-file -Dfile=android.jar \
  -DgroupId=com.google.android -DartifactId=android -Dversion=4.4.2

$ mvn install:install-file -Dfile=uiautomator.jar \
  -DgroupId=com.google.android -DartifactId=android-test \
  -Dversion=4.4.2 -Dpackaging=jar


2nd: Add dependencies to your pom.xml

<dependency>
    <groupId>com.google.android</groupId>
    <artifactId>android</artifactId>
    <version>4.4.2</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.google.android</groupId>
    <artifactId>android-test</artifactId>
    <version>4.4.2</version>
    <scope>test</scope>
</dependency>


Should be good to go!