Last Updated: February 25, 2016
·
5.854K
· kadrei

parallel execute calabash-android tests

A simple commandline script to start a calabash-android script on all adb-connected android devices.

 #!/bin/bash 
declare -a arr
let i=0
export ANDROID_HOME=<path to android sdk>
while read line #get devices list
do
if [ -n "$line" ] && [ "`echo $line | awk '{print $2}'`" == "device" ]
    then
        device="`echo $line | awk '{print $1}'`"
        echo "Add $device"
        arr[i]="$device" # $ is optional
        let i=$i+1
fi
done < <(adb devices)

let port=34800 #starting port - can be a random port ( choosen by fair dice roll )
for deviceid in "${arr[@]}" #for each connected device start test on a specified port
do
mkdir $deviceid
#Set important variables for execution
ADB_DEVICE_ARG=$deviceid TEST_SERVER_PORT=$port SCREENSHOT_PATH=$deviceid/ calabash-android run <path to apk> --format html --out "$deviceid"_report.html & #Start test and do html report
port=$((port+1)) #increase port
done

12 Responses
Add your response

Great one. How can I do this in Windows ?

over 1 year ago ·

Sorry, I don't know the exact Code for Windows but you just need to do the same in windows.
1. get the device-ids
2. ADB_DEVICE_ARG=$deviceid TEST_SERVER_PORT=$port SCREENSHOT_PATH=$deviceid/ calabash-android run <path to apk> --format html --out "$deviceid"_report.html (should work on Windows too, just need to edit the variables)

over 1 year ago ·

Hi , I really liked the concept of this , but how do i excute this one .

over 1 year ago ·

simply run it in your shell :)

over 1 year ago ·

Any solution on this for executing this script on windows....I tried above but no success...

over 1 year ago ·

I get this:
testandroid.sh: 2: testandroid.sh: declare: not found
testandroid.sh: 3: testandroid.sh: let: not found
testandroid.sh: 14: testandroid.sh: Syntax error: redirection unexpected

over 1 year ago ·

which os are you on?

it worked for me on (x)ubuntu 12

over 1 year ago ·

will this code work on MAC ?

over 1 year ago ·

i don't know, cause i don't have a mac. but you may try.

over 1 year ago ·

parallel.sh: line 14: syntax error near unexpected token <' parallel.sh: line 14:done < <(adb devices)'

i get this error.
can you help me on this

over 1 year ago ·

I did some work around this and created this gem
https://rubygems.org/gems/parallel_calabash
https://github.com/rajdeepv/parallel_calabash

This works on osx. not yet tested on windows. please try it out and if you need any help please let me know

over 1 year ago ·

if target == 'android'

var =adb devices #list of android devices
arr = var.lines #get in to lines
arr.shift && arr.pop #crop first and last lines

split with space and crop first

arr.each {|x| kid = x.split(" ").shift
mid = kid.lines #puts #{mis}
for i in mid

mkdir Android_#{i}

export ADB_DEVICE_ARG=#{i} SCREENSHOT_PATH=Android_#{i}/ APP=prebuilt/Android-debug.apk && bundle exec calabash-android run $APP -p android #{ARGV.join(' ')} --format html --out Android_#{i}/android_"#{i}".html --format pretty

end

}
Android serial execution

over 1 year ago ·