How to use withAirplaneModeDisabled method of io.appium.java_client.android.connection.ConnectionStateBuilder class

Best io.appium code snippet using io.appium.java_client.android.connection.ConnectionStateBuilder.withAirplaneModeDisabled

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

MobileConnectionType.java

Source: MobileConnectionType.java Github

copy
1package com.synergy.server.enums;
2
3import io.appium.java_client.android.connection.ConnectionState;
4import io.appium.java_client.android.connection.ConnectionStateBuilder;
5
6public enum MobileConnectionType {
7
8    WIFI ("wifi"),
9    NONE ("none"),
10    AIRPLANE ("airplane"),
11    DATA ("data"),
12    ALL ("all");
13
14    private final String value;
15
16    MobileConnectionType(String value) {
17    this.value = value;
18  }
19
20    public String value() {
21    return value;
22  }
23  
24    public static MobileConnectionType getEnumByString(String value) {
25        if (value == null) {
26            return null;
27        }
28        
29        for (MobileConnectionType connection : MobileConnectionType.values()) {
30    	    if (value.equalsIgnoreCase(connection.value)) {
31        	    return connection;
32            }
33         }
34        return null;
35    }
36
37    public static ConnectionState getConnection(MobileConnectionType type) {
38        if (type.equals(NONE)) {
39            return new ConnectionStateBuilder().withAirplaneModeDisabled().withDataDisabled().withWiFiDisabled()
40                    .build();
41        } else if (type.equals(AIRPLANE)) {
42            return new ConnectionStateBuilder().withAirplaneModeEnabled().withDataDisabled().withWiFiDisabled()
43                    .build();
44        } else if (type.equals(WIFI)) {
45            return new ConnectionStateBuilder().withAirplaneModeDisabled().withDataDisabled().withWiFiEnabled()
46                    .build();
47        } else if (type.equals(DATA)) {
48            return new ConnectionStateBuilder().withAirplaneModeDisabled().withDataEnabled().withWiFiDisabled()
49                    .build();
50        } else if (type.equals(ALL)) {
51            return new ConnectionStateBuilder().withAirplaneModeDisabled().withDataEnabled().withWiFiEnabled()
52                    .build();
53        }
54
55        return null;
56    }
57  
58}
59
Full Screen

LearnwifiOn.java

Source: LearnwifiOn.java Github

copy
1package week2.day2;
2
3import java.net.MalformedURLException;
4import java.net.URL;
5import java.util.HashMap;
6import java.util.Map;
7import java.util.concurrent.TimeUnit;
8
9import org.openqa.selenium.ScreenOrientation;
10import org.openqa.selenium.WebElement;
11import org.openqa.selenium.remote.DesiredCapabilities;
12
13import io.appium.java_client.android.Activity;
14import io.appium.java_client.android.AndroidBatteryInfo;
15import io.appium.java_client.android.AndroidDriver;
16import io.appium.java_client.android.connection.ConnectionState;
17import io.appium.java_client.android.connection.ConnectionStateBuilder;
18
19public class LearnwifiOn {
20
21	public static void main(String[] args) throws MalformedURLException, InterruptedException {
22
23		DesiredCapabilities dc = new DesiredCapabilities();
24		dc.setCapability("appPackage", "net.oneplus.launcher");
25		dc.setCapability("appActivity", "net.oneplus.launcher.Launcher");
26		dc.setCapability("deviceName", "OnePlus 6");
27		dc.setCapability("platformName", "Android");
28		dc.setCapability("automationName", "UiAutomator2");
29		dc.setCapability("noReset", true);
30
31		AndroidDriver<WebElement> driver = new AndroidDriver<WebElement>(new URL("http://0.0.0.0:4723/wd/hub"), dc);
32
33		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
34
35		ConnectionStateBuilder csb = new ConnectionStateBuilder();
36		ConnectionState state = csb.withAirplaneModeDisabled().build();
37		driver.setConnection(state);
38		driver.openNotifications();
39
40
41		ConnectionStateBuilder csb1 = new ConnectionStateBuilder();
42		ConnectionState state1 = csb1.withAirplaneModeDisabled().build();
43		driver.setConnection(state1);
44
45		driver.setConnection(new ConnectionStateBuilder().withAirplaneModeEnabled().build());		
46		driver.openNotifications();
47
48
49	}
50
51}
52
Full Screen

AndroidConnectionTest.java

Source: AndroidConnectionTest.java Github

copy
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * See the NOTICE file distributed with this work for additional
5 * information regarding copyright ownership.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.appium.java_client.android;
18
19import static org.junit.Assert.assertFalse;
20import static org.junit.Assert.assertTrue;
21
22import io.appium.java_client.android.connection.ConnectionState;
23import io.appium.java_client.android.connection.ConnectionStateBuilder;
24import org.junit.FixMethodOrder;
25import org.junit.Test;
26import org.junit.runners.MethodSorters;
27
28@FixMethodOrder(MethodSorters.NAME_ASCENDING)
29public class AndroidConnectionTest extends BaseAndroidTest {
30
31    @Test
32    public void test1() {
33        ConnectionState state = driver.setConnection(new ConnectionStateBuilder()
34                .withWiFiEnabled()
35                .build());
36        assertTrue(state.isWiFiEnabled());
37    }
38
39    @Test
40    public void test2() {
41        ConnectionState state = driver.setConnection(new ConnectionStateBuilder()
42                .withAirplaneModeDisabled()
43                .build());
44        assertFalse(state.isAirplaneModeEnabled());
45        assertFalse(state.isWiFiEnabled());
46        assertFalse(state.isDataEnabled());
47        state = driver.setConnection(new ConnectionStateBuilder(state)
48                .withAirplaneModeEnabled()
49                .build());
50        assertTrue(state.isAirplaneModeEnabled());
51    }
52
53    @Test
54    public void test3() {
55        ConnectionState state = driver.setConnection(
56                new ConnectionStateBuilder(driver.getConnection())
57                        .withAirplaneModeDisabled()
58                        .withWiFiEnabled()
59                        .withDataEnabled()
60                        .build());
61        assertFalse(state.isAirplaneModeEnabled());
62        assertTrue(state.isWiFiEnabled());
63        assertTrue(state.isDataEnabled());
64    }
65}
66
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger withAirplaneModeDisabled code on LambdaTest Cloud Grid

Execute automation tests with withAirplaneModeDisabled on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)