How to deal with Network Connection in Appium
Elias Nogueira
66

Hi,

i read your blog related with network connection in appium. and use the following code in eclipse:

package testNetwork;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.mobile.NetworkConnection;
import org.openqa.selenium.mobile.NetworkConnection.ConnectionType;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import appiumGestures.Launchmethod;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.Connection;
import io.appium.java_client.android.HasNetworkConnection;

public class SetNetworkConnection {

public static AndroidDriver driver;

@BeforeTest
 public static void setnetworkconn() throws MalformedURLException, InterruptedException{
 DesiredCapabilities capabilities = new DesiredCapabilities();
 capabilities.setCapability(“deviceName”, “35a374310104”);
 capabilities.setCapability(CapabilityType.VERSION, “6.0.1”);
 capabilities.setCapability(“platformName”, “Android”);
 capabilities.setCapability(“appPackage”, “io.appium.android.apis”);
 capabilities.setCapability(“appActivity”, “io.appium.android.apis.ApiDemos”);
 driver = new AndroidDriver(new URL(“http://127.0.0.1:4722/wd/hub"), capabilities);
 driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
 }

@Test
 public void networkSettings() throws InterruptedException{
 driver.setConnection(Connection.ALL);
 Thread.sleep(3000);
 Connection con = driver.getConnection();
 System.out.println(con);
 System.out.println(con.toString());
 }

}

**********************************************************

getting Output:

NONE

NONE

PASSED: networkSettings

===============================================

Default test

Tests run: 1, Failures: 0, Skips: 0

===============================================

  • **************************************************************

i am getting “none” in output.

so what may be the issue?

should i change some device setting and capabilities for the network setting.?

please help.

Show your support

Clapping shows how much you appreciated Pragya Saxena’s story.