Not able to set connection through Appium

Hello,

I am using setConnection(Connection.NONE) method to switch on/off wifi settings in my device. However it doesn’t work… Any workaround of this? I don’t want to use adb because later on, I will be running the tests on perfecto cloud.

Here is my code -

driver.setConnection(Connection.NONE);
		Thread.sleep(5000);
		Assert.assertEquals(Connection.NONE, driver.getConnection());

I get assertion failure -

junit.framework.AssertionFailedError: expected:<NONE> but was:<ALL>

It gives nothing in error, but also does nothing in device.

Here is the logs from Appium -

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running ‘C:\Users\AppData\Local\Android\sdk\platform-tools\adb.exe’ with args:
[“-P”,5037,“-s”,“34044ca3af9f3269”,“shell”,“settings”,“get”,“global”,“airplane_mode_on”]
[debug] [ADB] Getting connected devices…
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running ‘C:\Users\AppData\Local\Android\sdk\platform-tools\adb.exe’ with args:
[“-P”,5037,“-s”,“34044ca3af9f3269”,“shell”,“settings”,“get”,“global”,“wifi_on”]
[debug] [ADB] Getting connected devices…
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running ‘C:\Users\AppData\Local\Android\sdk\platform-tools\adb.exe’ with args:
[“-P”,5037,“-s”,“34044ca3af9f3269”,“shell”,“settings”,“get”,“global”,“mobile_data”]
[debug] [MJSONWP] Responding to client with driver.setNetworkConnection() result: 6
[HTTP] ← POST /wd/hub/session/1b6370aa-ce54-4406-8238-01198e70eef7/network_connection 200 24457 ms

  • 73
    [HTTP] → DELETE /wd/hub/session/1b6370aa-ce54-4406-8238-01198e70eef7 {}
    [debug] [MJSONWP] Calling AppiumDriver.deleteSession() with args: [“1b6370aa-ce54-4406-8238-01198e70
    eef7”]
    [debug] [BaseDriver] Event ‘quitSessionRequested’ logged at 1501677171926 (18:02:51 GMT+0530 (India
    Standard Time))
    [debug] [AndroidDriver] Shutting down Android driver
    [debug] [ADB] Getting connected devices…
    [debug] [ADB] 1 device(s) connected
    [debug] [ADB] Running ‘C:\Users\AppData\Local\Android\sdk\platform-tools\adb.exe’ with args:
    [“-P”,5037,“-s”,“34044ca3af9f3269”,“shell”,“am”,“force-stop”,“com.mp”]
    [debug] [ADB] Pressing the HOME button
    [debug] [ADB] Getting connected devices…
    [debug] [ADB] 1 device(s) connected
    [debug] [ADB] Running ‘C:\Users\AppData\Local\Android\sdk\platform-tools\adb.exe’ with args:
    [“-P”,5037,“-s”,“34044ca3af9f3269”,“shell”,“input”,“keyevent”,3]
    [debug] [AndroidBootstrap] Sending command to android: {“cmd”:“shutdown”}
    [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“shutdown”}
    [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
    [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:“OK, shutting down”
    }
    [debug] [AndroidBootstrap] Received command result from bootstrap
    [debug] [UiAutomator] Shutting down UiAutomator
    [debug] [UiAutomator] Moving to state ‘stopping’

Libraries -
Java-client - 4.1.2
Appium - 1.6.4
Device - Sony Xperia Z5
Device OS - 5.1.1

Kindly help…

Many thanks!

Hi,
Currently we are using Java client 3.2.0
appium 1.6.4
For wifi on and off
We are using opennotification and the turnoff wifi by clicking on wifi icon… this is being identified using appium session

public void setWiFiAndroid(boolean status) {
int screenHeight =getDriver().manage().window().getSize().height;
int screenWidth = getDriver().manage().window().getSize().width;
((AndroidDriver<?>)getDriver()).openNotifications();
tapElement(wifiButton);
tapUsingXY(screenHeight/2, screenWidth);
sleepTime(5000);
}

I understand that there are other workarounds by which we can do it, but if appium and java-client is providing such capability, then why it is not working?

I’ve found set_network_connection to work using the ruby client. I’ve noticed that it tends to kill uiautomator on the device, but this does not appear to be fatal. I thought there might be some exception for Samsung devices, but we appear to be using that call on all devices.

Have you tried a device with a different manufacturer/model/android release?

@willosser - I see there are 2 different classes which are there in Appium java client… But one of them is deprecated… I am not sure whether I should use the deprecated one in order to run my tests on older devices having os <=5… Please advice… Here is the release note which indicates the depreciation. Unfortunately, I don’t have another device to test.

the io.appium.java_client.NetworkConnectionSetting class was marked deprecated
the enum io.appium.java_client.android.Connection was added. All supported network bitmasks are defined there.

I’d recommend some testing to determine the best solution. As I said, I use the Ruby client, so I have no recommendation as to the api you should use with the Java client