Android tool

For my control tests I use Robotium. Basically I can check everything except offline affairs.

As soon as I turn off the data (using adb, the F8 shortcut in the emulator, etc.), the test is disabled. It continues in the device / emulator, but the results are not reported.

So, I have an idea to place only the application offline, and not on the entire device. The problem is that I do not know how ...

Using iptablesApi, I will need to start my device. I read that the Mobiwol application uses some kind of VPN to restrict access to Internet applications without the need to root the device.

Question How does the Mobiwol application block the Internet connection for each application? Or is there another way to test apks offline?

EDIT 12/30/2014

I forgot to say that I can run tests offline, but I need to start tests when the device is offline. Currently, I have divided my tests into OFFLINE and ONLINE. After starting ONLINEs, I run the famous adb kill-server and adb start-server . After that I do OFFLINE.

+8
source share
4 answers

Just make a few suggestions as there seem to be different questions here. 1) If all you want to do is turn off the data before running the OFFLINE test case, you can just try using robotics to do this.

Example: For Wi-Fi:

 WifiManager wifi=(WifiManager)solo.getCurrentActivity().getSystemService(Context.WIFI_SERVICE); wifi.setWifiEnabled(false); 

For mobile data (using reflections):

 ConnectivityManager dataManager=(ConnectivityManager)solo.getCurrentActivity().getSystemService(Context.CONNECTIVITY_SERVICE); Method dataClass = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class); dataClass.setAccessible(true); dataClass.invoke(dataManager, true); 

You can make the two above calls in the setup() method before running a separate test case in the OFFLINE package. After all the test cases in the OFFLINE package are completed, you can turn on WiFi / DATA back in the teardown() method at the very end.

2) Looking at the application that you placed in the OP, it seems that it:

  • Uses ipTables based on OS version

  • Creates a UID-based script header for all applications that need WiFi / Data p>

  • You need to get a list of installed applications on the device along with any hidden applications, etc. from the package manager.

  • And again, it runs the scripts based on the user selection for the blacklist and redefines the existing rules in ipTable with the desired user rules.

Pretty sure, although it must have been quite difficult to put all this together ... Sounds are much simpler as marker points.

Hope this helps you.

PS: If you find out something, write an updated answer, I would like to know how you worked it.

Update: Make sure you have the necessary permissions to set WiFi / data in your application . NOT a test apk manifest. THIS SHOULD BE A MANIFESTATION OF THE APPLICATION OF MYSELF. This library can help you. Its extension for solo. http://adventuresinqa.com/2014/02/17/extsolo-library-to-extend-your-robotium-test-automation/

+5
source

There is an excellent library from the LinkedIn Test Butler, you can enable, disable both WiFi and mobile data by simply calling:

 TestButler.setGsmState(false); TestButler.setWifiState(false); 

The main advantage of this library is that it does not require any permissions in your manifest, more detailed information can be found on the project website:

https://github.com/linkedin/test-butler

+2
source

Sorry if I simplify this, but what about just putting your phone / emulator in airplane mode? Through the actual user interface. This is what I do to test standalone cases.

+1
source

After spending several hours trying to do this similarly to user2511882 , I still had an exception due to the lack of permissions (yes, the permission to "change system settings" was activated).

I ended up doing this using the UI Automator:

 public static void setAirplaneMode(boolean enable) { if ((enable ? 1 : 0) == Settings.System.getInt(getInstrumentation().getContext().getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0)) { return; } UiDevice device = UiDevice.getInstance(getInstrumentation()); device.openQuickSettings(); // Find the text of your language BySelector description = By.desc("Airplane mode"); // Need to wait for the button, as the opening of quick settings is animated. device.wait(Until.hasObject(description), 500); device.findObject(description).click(); getInstrumentation().getContext().sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); } 

You will need ACCESS_NETWORK_STATE in the androidTest manifest file:

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

Remember to disable it after the test.

If you have languages ​​other than English, you need to change the “Airplane Mode” to the text of your language. Since I have several translations, I am reading this from the resource line.

0
source

Source: https://habr.com/ru/post/980079/


All Articles