Commit 9c8feee8 authored by Aneta Steimarova's avatar Aneta Steimarova

#691 WIP running test bundle on more connected devices

parent 1f52ad10
......@@ -266,11 +266,11 @@ idea {
}
}
def runTest(String iTestName) {
println "[iTest] STARTING TEST: " + iTestName
def runTest(String iTestName, String device) {
println "[iTest-" + device + "] STARTING TEST: " + iTestName
def adb = doAndroidSettings()
exec {
commandLine "$adb", 'shell', 'am', 'start', '-n', 'cz.nic.tablexia.itest/cz.nic.tablexia.android.AndroidITestLauncher', '-e', 'testClassName', iTestName
commandLine "$adb", '-s', device, 'shell', 'am', 'start', '-n', 'cz.nic.tablexia.itest/cz.nic.tablexia.android.AndroidITestLauncher', '-e', 'testClassName', iTestName
}
......@@ -280,7 +280,7 @@ def runTest(String iTestName) {
if(adbStdOut.toString().trim().contains("PROCESSING")){
def adbPSOut = new ByteArrayOutputStream()
exec {
commandLine "$adb", 'shell', "ps", "|", "grep", "cz.nic.tablexia.itest"
commandLine "$adb", '-s', device, 'shell', "ps", "|", "grep", "cz.nic.tablexia.itest"
standardOutput = adbPSOut
}
if(!adbPSOut.toString().contains("cz.nic.tablexia.itest")) return //stop if test is not running anymore
......@@ -288,25 +288,25 @@ def runTest(String iTestName) {
if(adbStdOut.toString().trim().contains("OK")) return
if(adbStdOut.toString().trim().contains("FAIL")) return
exec {
commandLine "$adb", 'shell', "ls", "/sdcard/iTest_results"
commandLine "$adb", '-s', device, 'shell', "ls", "/sdcard/iTest_results"
standardOutput = adbStdOut
}
sleep(1000)
timeout++;
}
println "[iTest] Test " + iTestName + " timed out."
println "[iTest-" + device + "] Test " + iTestName + " timed out."
}
task runAndroidITestBundle (dependsOn:'assembleITest'){
doLast{
def androidITestBundle(String device){
int testsCount = 0;
int successfulTestsCount = 0;
def tablexiaApk = project.tablexiaAppName + "-iTest-" + "$tablexiaVersionName" + ".apk"
def apkFolder = "${project(':android').projectDir}/build/outputs/apk/"
//TODO make different folders for different devices
def sdCardResults = "/sdcard/iTest_results"
println "[iTest] INSTALLING " + tablexiaApk + " into connected Android device"
println "[iTest-" + device + "] INSTALLING " + tablexiaApk + " into connected Android device"
if(!new File(apkFolder + tablexiaApk).exists()){
throw new GradleException("Could not install " + tablexiaApk + " - file does not exists!")
return
......@@ -314,29 +314,29 @@ task runAndroidITestBundle (dependsOn:'assembleITest'){
def adb = doAndroidSettings()
exec {
commandLine "$adb", 'install', '-r', apkFolder + tablexiaApk
commandLine "$adb", '-s', device, 'install', '-r', apkFolder + tablexiaApk
}
println "[iTest] INSTALLING Tablexia COMPLETED"
println "[iTest-" + device + "] INSTALLING Tablexia COMPLETED"
println "[iTest] CREATING NEW iTest OUTPUT DIRECTORY"
println "[iTest-" + device + "] CREATING NEW iTest OUTPUT DIRECTORY"
def iTestOutputFile = new File(apkFolder + "iTest_results/")
if (iTestOutputFile.exists()) {
println "[iTest] REMOVING OLD iTest OUTPUT DIRECTORY"
println "[iTest-" + device + "] REMOVING OLD iTest OUTPUT DIRECTORY"
iTestOutputFile.deleteDir()
}
new File("${project(':itest').projectDir}/iTestBundle.txt").eachLine { iTestName ->
exec {
commandLine "$adb", 'shell', 'rm', '-r', sdCardResults
commandLine "$adb", '-s', device, 'shell', 'rm', '-r', sdCardResults
}
println "[iTest] OLD FILES on SDCARD REMOVED"
println "[iTest-" + device + "] OLD FILES on SDCARD REMOVED"
testsCount++
runTest(iTestName)
println "[iTest] TEST: " + iTestName + " FINISHED"
runTest(iTestName, device)
println "[iTest-" + device + "] TEST: " + iTestName + " FINISHED"
exec {
commandLine "$adb", 'pull', sdCardResults, apkFolder
commandLine "$adb", '-s', device, 'pull', sdCardResults, apkFolder
}
println "[iTest] LOG FILES WERE MOVED INTO " + iTestOutputFile.toString()
println "[iTest-" + device + "] LOG FILES WERE MOVED INTO " + iTestOutputFile.toString()
}
file("$iTestOutputFile").eachFile { logFile ->
......@@ -344,5 +344,29 @@ task runAndroidITestBundle (dependsOn:'assembleITest'){
}
if (testsCount != successfulTestsCount) throw new GradleException("Failed to complete all iTests! Check iTest log files in: " + iTestOutputFile.toString())
}
task runAndroidITestBundle (dependsOn:'assembleITest'){
doLast {
def adbOut = new ByteArrayOutputStream()
def adb = doAndroidSettings()
exec {
commandLine "$adb", 'devices'
standardOutput = adbOut
}
def connectedDevices = 0
adbOut.toString().eachLine { line ->
if (!line.contains("List") && line.contains("device")) {
connectedDevices++;
int i;
for (i=0; i<20; i++) {
if(line.charAt(i)=='\t') break
}
def device = line.substring(0, i)
println "Connected device: " + device
androidITestBundle(device)
}
}
if(connectedDevices<1) throw new GradleException("NO CONNECTED DEVICE WAS FOUND!")
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment