Merge pull request #3034 from NativeScript/nnikolov/WriteTestResultsOnAPI23

Adding request for write storage permissions for tests app.
This commit is contained in:
Vasil Chimev
2016-11-22 15:10:07 +02:00
committed by GitHub
6 changed files with 56 additions and 8 deletions

1
.gitignore vendored
View File

@ -11,6 +11,7 @@ dist/
package/
*.js
!tests/hooks/**/*.*
!gruntfile.js
!js-libs/**/*.*
!css/**/*.*

View File

@ -45,7 +45,7 @@ script:
grunt buildOnlyTestsApp --verbose --platform=Android --modulesPath=./bin/dist/$PACKAGE_NAME-$FULL_PACKAGE_VERSION.tgz --runtimeVersion=$RUNTIMEVERSION --emuPId=.*emulator.* --avd=$AVD_NAME --showEmu=false > /dev/null &&
grunt runOnlyTestsApp --verbose --platform=Android --modulesPath=./bin/dist/$PACKAGE_NAME-$FULL_PACKAGE_VERSION.tgz --emuPId=.*emulator.* --avd=$AVD_NAME --showEmu=false
- node ./build/travis-scripts/check-testrun-broken.js
- adb pull /data/data/org.nativescript.TestsApp/files/test-results.xml &&
- adb pull /storage/sdcard/Documents/test-results.xml &&
mv test-results.xml ~/test-run-results$PACKAGE_VERSION.xml
before_deploy:
- mv bin/dist/$PACKAGE_NAME-$FULL_PACKAGE_VERSION.tgz ../.deploymentpackage

View File

@ -2,6 +2,8 @@
import * as trace from "trace";
import tests = require("../testRunner");
import {Label} from "ui/label";
import * as application from "application";
import * as platform from "platform";
trace.enable();
trace.addCategories(trace.categories.Test + "," + trace.categories.Error);
@ -21,14 +23,38 @@ page.id = "mainPage";
page.on(Page.navigatedToEvent, onNavigatedTo);
function runTests() {
setTimeout(function () {
tests.runAll();
}, 10);
}
function onNavigatedTo(args) {
let label = new Label();
label.text = "Running non-UI tests...";
page.content = label;
args.object.off(Page.navigatedToEvent, onNavigatedTo);
setTimeout(function () {
tests.runAll();
}, 10);
if (parseInt(platform.device.sdkVersion) >= 23) {
let handler = (args: application.AndroidActivityRequestPermissionsEventData) => {
application.android.off(application.AndroidApplication.activityRequestPermissionsEvent, handler);
if (args.requestCode === 1234 && args.grantResults.length > 0 && args.grantResults[0] === android.content.pm.PackageManager.PERMISSION_GRANTED) {
runTests();
} else {
trace.write("Permission for write to external storage not granted!", trace.categories.Error, trace.messageType.error);
}
};
application.android.on(application.AndroidApplication.activityRequestPermissionsEvent, handler);
if ((<any>android.support.v4.content.ContextCompat).checkSelfPermission(application.android.currentContext, (<any>android).Manifest.permission.WRITE_EXTERNAL_STORAGE) !== android.content.pm.PackageManager.PERMISSION_GRANTED) {
(<any>android.support.v4.app.ActivityCompat).requestPermissions(application.android.currentContext, [(<any>android).Manifest.permission.WRITE_EXTERNAL_STORAGE], 1234);
} else {
runTests();
}
} else {
runTests();
}
}
export function createPage() {

View File

@ -176,7 +176,9 @@ function printRunTestStats() {
testFileContent.push("</testsuite>");
testFileContent.push("</testsuites>");
let testFilePath = fs.path.join(fs.knownFolders.documents().path, "test-results.xml");
let testFilePath = fs.path.join(android.os.Environment.getExternalStorageDirectory().getAbsolutePath(), "Documents", "test-results.xml");
console.log("testFilePath =====>>>>>>> " + testFilePath);
let testFile = fs.File.fromPath(testFilePath);
testFile.writeTextSync(testFileContent.join(""));

View File

@ -0,0 +1,19 @@
var childProcess = require("child_process");
module.exports = function(logger, platformsData, projectData, hookArgs) {
if (/apk$/.test(hookArgs.packageFilePath)) {
var writeCommand = "adb shell pm grant " + projectData.projectId + " android.permission.WRITE_EXTERNAL_STORAGE";
var readCommand = "adb shell pm grant " + projectData.projectId + " android.permission.READ_EXTERNAL_STORAGE";
var callback = function(error, stdout, stderr) {
if (error) {
console.log(error);
}
};
childProcess.exec(writeCommand, {
cwd: projectData.projectDir
}, callback);
childProcess.exec(readCommand, {
cwd: projectData.projectDir
}, callback);
}
}

View File

@ -300,12 +300,12 @@ declare module "application" {
/**
* The Permissions
*/
permissions: Array<String>,
permissions: Array<string>,
/**
* The Granted.
*/
grantResults: Array<Number>
grantResults: Array<number>
}
/**
@ -480,7 +480,7 @@ declare module "application" {
/**
* This event is raised on the back button is pressed in an android application.
*/
on(event: "activityRequestPermissions", callback: (args: AndroidActivityBackPressedEventData) => void, thisArg?: any);
on(event: "activityRequestPermissions", callback: (args: AndroidActivityRequestPermissionsEventData) => void, thisArg?: any);
/**
* String value used when hooking to activityCreated event.