How to turn off wifi in iOS device, iOS11, xcode 9

Please some one suggest how to turn off wifi in iOS devices

Real device? And have you verified that you can access native apps outside of the app you are automating?

Create a iOSdriver but pass the bundle id as com.apple.Preferences
This will open the setting page and you can do any action in setting page.
Code:
public static void main(String[] args) throws Exception {

IOSDriver driver = null;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
capabilities.setCapability(MobileCapabilityType.APPIUM_VERSION, "1.6.5");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.0");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "RDEiPhone");
capabilities.setCapability("newCommandTimeout", 60*5);
capabilities.setCapability("--session-override", true);
//desiredCapabilities.setCapability("preventWDAAttachments", true);
//capabilities.setCapability(MobileCapabilityType.LAUNCH_TIMEOUT, 500000);
capabilities.setCapability("showXcodeLog", false);
capabilities.setCapability("xcodeOrgId", "Pass your developer team id");
capabilities.setCapability("xcodeSigningId", "iPhone Developer");
capabilities.setCapability(MobileCapabilityType.UDID, "e010e19ee4428664afc53d50999c138c861ea22e");
//capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT , 2000);
//capabilities.setCapability(MobileCapabilityType.APP , "/Users/rderpg/Desktop/sukrit_chill_debug/19-817/iXpand Base Auto-3.ipa");
capabilities.setCapability("bundleId", "com.apple.Preferences");
//capabilities.setCapability("xcodeConfigFile", "/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Configurations/ProjectSettings.xcconfig");
capabilities.setCapability("usePrebuiltWDA", true);
capabilities.setCapability("clearSystemFiles", true);
//capabilities.setCapability("noReset", true);
capabilities.setCapability("updatedWDABundleId", "com.facebook.WebDriverAgentAppiumTest");
//launchAppiumServer1();	
//launchAppiumServer();
try {

driver = new IOSDriver(new URL(“http://127.0.0.1:4723/wd/hub”),capabilities);
System.out.println(“jitu”);
driver.findElement(By.id(“Wi-Fi”)).click();
driver.findElement(By.xpath("//XCUIElementTypeSwitch")).click();

} catch (Exception e) {

	System.out.println(e);


}

}

@Jitu1888 thats a way :slight_smile: I never tested it.

What I do, is:

  1. Testing my app normally and if I want to change something in settings:
  2. Go to background
  3. Tap on Settings icon (I have the icon on bottom bar)
  4. Change whatever I want
  5. Go to background
  6. Tap on my app icon (I may need to swipe between icons until i find it.

Thanks for the reply but if app is in background how you access setting page ??
driver.runAppInBackground(int) wont release the driver till app comes to foreground.

Or are you using javascriptexecutor??? @Telmo_Cardoso

I will send a youtube link for it

@Jitu1888

  driver.runAppInBackground(Duration.ofSeconds(-1));

I’v published that answer in here:

@Telmo_Cardoso : Which java client jar you are using , I need to work on same scenario to put app in backround and do some verification on home screen.

Currently in production:
5.0.4

and in development:
6.0.0-BETA2

Thanks , i will try this

@Telmo_Cardoso

I am getting [debug] [MJSONWP] Calling AppiumDriver.background() with args: [{“timeout”:-1000},“652f2f4d-97af-4230-9920-69a575b61f53”]
[debug] [iOS] Executing iOS command ‘background’
[debug] [UIAuto] Sending command to instruments: au.background([object Object])
[debug] [Instruments] [INST] 2018-02-08 12:26:02 +0000 Debug: Got new command 3 from instruments: au.background([object Object])
[debug] [Instruments] [INST] 2018-02-08 12:26:02 +0000 Debug: evaluating au.background([object Object])
[debug] [Instruments] [INST] 2018-02-08 12:26:02 +0000 Error: SyntaxError: Unexpected identifier ‘Object’. Expected either a closing ‘]’ or a ‘,’ following an array element.
[debug] [UIAuto] Socket data received (124 bytes)
[debug] [UIAuto] Got result from instruments: {“status”:17,“value”:“Unexpected identifier ‘Object’. Expected either a closing ‘]’ or a ‘,’ following an array element.”}

error with both java client jars ,please help!
tried with selenium 2.48 ,2.53 jars
xcode version 7.3.1

You should update XCode, use “XCUITest” driver and update all the dependencies.

Please let me know xcode & appium version on which you tried this
Thanks!

I have two configurations.
Prod with (and this week will be upgraded to dev confs.)
XCode8.3.3
Appium 1.7.1

Dev with
XCode 9.2
Appium 1.7.2

Thanks ! , I am able to put app in back ground , but how to identify element on home screen , I am not able to interact with home screen element.

I am using https://github.com/mykola-mokhnach/Appium-iOS-Inspector to identify element.

Hi,

I had been using the steps as suggested by you above.

Please find code snippet below.

    driver.runAppInBackground(Duration.ofSeconds(-1));
    Map<String, Object> params = new HashMap<>();
    JavascriptExecutor js = (JavascriptExecutor) driver;
    params.put("bundleId", "com.apple.Preferences");
    js.executeScript("mobile: launchApp", params);

    SeleniumMethods.performSleep(5);

    Assert.assertTrue(Actions.click("Settings_Wifi"));

However when I try to click on the element, it does not perform the action. Please help.