Skip to content

Commit 4d4ffc4

Browse files
author
plamen5kov
committed
test-app is now able to run on device and emulator depending on passed arguments described in /test-app/app/build.gradle
1 parent 58361eb commit 4d4ffc4

3 files changed

Lines changed: 27 additions & 13 deletions

File tree

test-app/app/build.gradle

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
/*
2+
* run from dir: test-app/
3+
* run on emulator: ./gradlew :app:runtest //default
4+
* run on device: ./gradlew :app:runtest -PrunOnDevice
5+
*
6+
*/
7+
8+
19
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
210

311
apply plugin: 'com.android.model.application'
412

13+
def runOnDevice = project.hasProperty("runOnDevice");
14+
def runOnDeviceOrEmulator = runOnDevice ? "-d" : "-e";
15+
516
model {
617
android {
718
compileSdkVersion = 23
@@ -49,12 +60,12 @@ task deleteDist (type: Delete) {
4960
task installApk (type: Exec) {
5061
doFirst {
5162
println "Attempting to install buit apk"
52-
63+
5364
if(isWinOs) {
54-
commandLine "cmd", "/c", "node", "$rootDir\\tools\\deploy-apk.js", "$rootDir\\app\\build\\outputs\\apk\\app-debug.apk"
65+
commandLine "cmd", "/c", "node", "$rootDir\\tools\\deploy-apk.js", "$rootDir\\app\\build\\outputs\\apk\\app-debug.apk", runOnDeviceOrEmulator
5566
}
5667
else {
57-
commandLine "node", "$rootDir/tools/deploy-apk.js", "$rootDir/app/build/outputs/apk/app-debug.apk"
68+
commandLine "node", "$rootDir/tools/deploy-apk.js", "$rootDir/app/build/outputs/apk/app-debug.apk", runOnDeviceOrEmulator
5869
}
5970
}
6071

@@ -66,12 +77,12 @@ task installApk (type: Exec) {
6677
task deletePreviousResultXml (type: Exec) {
6778
doFirst {
6879
println "Removing previous android_unit_test_results.xml"
69-
80+
7081
if(isWinOs) {
71-
commandLine "cmd", "/c", "adb", "shell", "rm", "-rf", "/sdcard/android_unit_test_results.xml"
82+
commandLine "cmd", "/c", "adb", runOnDeviceOrEmulator , "shell", "rm", "-rf", "/sdcard/android_unit_test_results.xml"
7283
}
7384
else {
74-
commandLine "adb", "shell", "rm", "-rf", "/sdcard/android_unit_test_results.xml"
85+
commandLine "adb", runOnDeviceOrEmulator, "shell", "rm", "-rf", "/sdcard/android_unit_test_results.xml"
7586
}
7687
}
7788
}
@@ -81,10 +92,10 @@ task startInstalledApk (type: Exec) {
8192
println "Starting test application"
8293

8394
if(isWinOs) {
84-
commandLine "cmd", "/c", "adb", "shell", "am", "start", "-n", "com.tns.android_runtime_testapp/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
95+
commandLine "cmd", "/c", "adb", runOnDeviceOrEmulator, "shell", "am", "start", "-n", "com.tns.android_runtime_testapp/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
8596
}
8697
else {
87-
commandLine "adb", "shell", "am", "start", "-n", "com.tns.android_runtime_testapp/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
98+
commandLine "adb", runOnDeviceOrEmulator, "shell", "am", "start", "-n", "com.tns.android_runtime_testapp/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
8899
}
89100
}
90101
}
@@ -101,10 +112,10 @@ task waitForUnitTestResultFile (type: Exec) {
101112
println "Waiting for tests to finish..."
102113

103114
if(isWinOs) {
104-
commandLine "cmd", "/c", "node", "$rootDir\\tools\\try_to_find_test_result_file.js"
115+
commandLine "cmd", "/c", "node", "$rootDir\\tools\\try_to_find_test_result_file.js", runOnDeviceOrEmulator
105116
}
106117
else {
107-
commandLine "node", "$rootDir/tools/try_to_find_test_result_file.js"
118+
commandLine "node", "$rootDir/tools/try_to_find_test_result_file.js", runOnDeviceOrEmulator
108119
}
109120
}
110121
}

test-app/tools/deploy-apk.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ if (process.argv.length < 2) {
88
}
99

1010
var apk = process.argv[2];
11+
var runOnDeviceOrEmulator = process.argv[3];
1112

1213
var proc = require('child_process');
1314

1415
var deployTimeout = 180000; // 3 minutes to deploy and launch.
1516

16-
var cmd = 'adb -e install -r ' + apk;
17+
var cmd = 'adb '+ runOnDeviceOrEmulator +' install -r ' + apk;
1718

1819
function timeoutFunction(msg) {
1920
console.error(msg);

test-app/tools/try_to_find_test_result_file.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ var
1010

1111
searchForFile("", getFile);
1212

13+
var runOnDeviceOrEmulator = process.argv[2];
14+
1315
function getFile(error, stdout, stderr) {
1416
closeProcessAfter(processTimeout);
1517
setInterval(tryToGetFile, searchInterval);
@@ -21,7 +23,7 @@ function closeProcessAfter(timeout) {
2123
}
2224

2325
function tryToGetFile() {
24-
execFindFile("adb pull /sdcard/android_unit_test_results.xml", checkIfFileExists);
26+
execFindFile("adb " + runOnDeviceOrEmulator + " pull /sdcard/android_unit_test_results.xml", checkIfFileExists);
2527
}
2628

2729
function checkIfFileExists(err, stout, stderr) {
@@ -39,4 +41,4 @@ function checkIfFileExists(err, stout, stderr) {
3941
process.exit();
4042
}
4143
}
42-
}
44+
}

0 commit comments

Comments
 (0)