我目前正在使用Robotium进行
android测试,当我在
Android 2.3模拟器中执行以下测试用例时,我遇到了错误
“java.lang.SecurityException:WifiService:用户10038和当前进程都没有android.permission.CHANGE_WIFI_STATE.”
“java.lang.SecurityException:WifiService:用户10038和当前进程都没有android.permission.CHANGE_WIFI_STATE.”
测试代码:
public void testScheduledPayments() { solo.clickOnButton(0); solo.enterText(0,"demo"); solo.enterText(1,"password"); solo.clickOnButton("Log In"); WifiManager wifiMan = (WifiManager) solo.getCurrentActivity().getSystemService(Context.WIFI_SERVICE); wifiMan.setWifiEnabled(false); solo.clickOnText("Payments"); solo.clickInList(2); solo.waitForText("Loading paymnets"); solo.clickInList(0); solo.clickOnMenuItem("logout"); solo.clickOnButton("logout"); solo.finishOpenedActivities(); }
在My Manifest文件中:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tesaptra" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="10" /> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.info.native" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <uses-library android:name="android.test.runner" /> </application> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> </manifest>
这是我的日志cat文件
java.lang.SecurityException: WifiService: Neither user 10038 nor current process has android.permission.CHANGE_WIFI_STATE. at android.os.Parcel.readException(Parcel.java:1322) at android.os.Parcel.readException(Parcel.java:1276) at android.net.wifi.IWifiManager$Stub$Proxy.setWifiEnabled(IWifiManager.java:614) at android.net.wifi.WifiManager.setWifiEnabled(WifiManager.java:713) at com.testaptra.Payments.testScheduledPaymnets(Payments.java:113) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204) at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194) at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
我已将所有权限添加到manifest.xml但没有运气.如果您熟悉以下问题,请帮助我吗?
提前致谢
解决方法
必须在目标应用程序中设置权限.测试应用程序中的权限完全被忽略.这意味着instrumnetation apk从来没有比目标应用程序更多的特权.