security exception while testing wifi on robotium
Asked Answered
S

2

6

I am currently working on android testing with Robotium , When i execute following testcase in Android 2.3 emulator i'm getting an error " java.lang.SecurityException:WifiService: Neither user 10038 nor current process has android.permission.CHANGE_WIFI_STATE.".

Test code :

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();
    }

At My Manifest file :

<?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>

And Here's My log cat file

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)

I have added all the permissions to manifest.xml but no luck.Could you please help me if you are familiar with below issue?

Thanks in advance

Scolecite answered 5/6, 2013 at 6:4 Comment(1)
@RenatoLochetti nope waiting for the solutionScolecite
X
8

Permission must be set in target application. Permissions in test application are totally ignored. It means that instrumnetation apk has never more privileges than target application.

Xylina answered 6/6, 2013 at 18:44 Comment(1)
@helloworld: This solution worked for me. Put the uses-permission in both manifests.Hurtless
T
1

It is in fact possible to give your test application more permissions than that of your real application but to do it you have to do something a bit sneaky with your android manifest.

What you have to do is to give both your apps the same android:sharedUserId in your manifest, this mean that if either adds in an extra permission that they will both have access to it. Using this it is possible to your test app with lots of permissions to do with whatever it wants, I have used both this approach and a different approach (make an intent service your test app can fire intents to do to things not normally doable by the app you are testing with) to test the sort of scenario you are trying.

Tonality answered 20/2, 2014 at 22:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.