浓缩咖啡 - &gt; Java.lang.SecurityException:由于Package不属于<process>,测试失败

时间:2018-02-25 17:24:29

标签: android android-espresso

我有一个Android Espresso代码尝试点击一个按钮,但它出现安全错误而失败。

这是Espresso命令:

angular.module('resultsApp', ['ngCookies'])

    .config(['$qProvider', function ($qProvider) {
        $qProvider.errorOnUnhandledRejections(false);
    }])



      .controller('resultsController', function($scope) {
        var code = localStorage.getItem('code');
        $scope.data = "";

            var dataRef = firebase.database().ref("0/"+code);

            dataRef.on('value', function(snapshot){
                console.log(snapshot.val());
                $scope.data = snapshot.val();
            });
            console.log($scope.data)
      });

这是我收到的错误:

Espresso.onData(Matchers.allOf(Matchers.is(Matchers.instanceOf(Preference.class)), withKey(PreferenceKey.pref_custom_server_base_url.toString()), withSummaryText(Configurations.DEFAULT_SERVER_URL))).check(matches(isCompletelyDisplayed()));

知道为什么会这样吗? 谢谢! 代码在Emulators和Cloud设备上运行,但具有相同的错误。

1 个答案:

答案 0 :(得分:1)

我在这个stackoverflow问题的答案中找到了解决该问题的方法: java.lang.SecurityException: Permission Denial: getIntentSender() when using UiAutomation in a test

在指定数据库的位置时,使用getTargetContext()代替getContext(),即

File dbFolder = InstrumentationRegistry.getInstrumentation().getTargetContext().getExternalCacheDir();

代替

File dbFolder = InstrumentationRegistry.getInstrumentation().getContext().getExternalCacheDir();
相关问题