How to use withCountry method of io.appium.java_client.android.options.localization.AppLocale class

Best io.appium code snippet using io.appium.java_client.android.options.localization.AppLocale.withCountry

Run io.appium automation tests on LambdaTest cloud grid

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

AppLocale.java

Source: AppLocale.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.options.localization;
18
19import io.appium.java_client.remote.options.BaseMapOptionData;
20
21import java.util.Map;
22import java.util.Optional;
23
24public class AppLocale extends BaseMapOptionData<AppLocale> {
25    public AppLocale() {
26        super();
27    }
28
29    public AppLocale(Map<String, Object> options) {
30        super(options);
31    }
32
33    /**
34     * Language identifier. See
35     * https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers#language-identifiers
36     * for the list of available values.
37     *
38     * @param lang Language identifier, for example "zh".
39     * @return self instance for chaining.
40     */
41    public AppLocale withLanguage(String lang) {
42        return assignOptionValue("language", lang);
43    }
44
45    /**
46     * Get the language identifier.
47     *
48     * @return Language identifier.
49     */
50    public Optional<String> getLanguage() {
51        return getOptionValue("language");
52    }
53
54    /**
55     * Allows to set a country identifier.
56     *
57     * @param country Country identifier, for example "CN".
58     * @return self instance for chaining.
59     */
60    public AppLocale withCountry(String country) {
61        return assignOptionValue("country", country);
62    }
63
64    /**
65     * Get the country identifier.
66     *
67     * @return Country identifier.
68     */
69    public Optional<String> getCountry() {
70        return getOptionValue("country");
71    }
72
73    /**
74     * Allows to set an optional language variant value.
75     *
76     * @param variant Language variant, for example "Hans".
77     * @return self instance for chaining.
78     */
79    public AppLocale withVariant(String variant) {
80        return assignOptionValue("variant", variant);
81    }
82
83    /**
84     * Get the language variant.
85     *
86     * @return Language variant.
87     */
88    public Optional<String> getVariant() {
89        return getOptionValue("variant");
90    }
91}
92
Full Screen

OptionsBuildingTest.java

Source: OptionsBuildingTest.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.drivers.options;
18
19import com.google.common.collect.ImmutableList;
20import com.google.common.collect.ImmutableMap;
21import io.appium.java_client.android.options.EspressoOptions;
22import io.appium.java_client.android.options.UiAutomator2Options;
23import io.appium.java_client.android.options.localization.AppLocale;
24import io.appium.java_client.android.options.server.EspressoBuildConfig;
25import io.appium.java_client.android.options.signing.KeystoreConfig;
26import io.appium.java_client.gecko.options.GeckoOptions;
27import io.appium.java_client.gecko.options.Verbosity;
28import io.appium.java_client.ios.options.XCUITestOptions;
29import io.appium.java_client.ios.options.other.CommandTimeouts;
30import io.appium.java_client.ios.options.simulator.Permissions;
31import io.appium.java_client.mac.options.AppleScriptData;
32import io.appium.java_client.mac.options.Mac2Options;
33import io.appium.java_client.remote.AutomationName;
34import io.appium.java_client.safari.options.SafariOptions;
35import io.appium.java_client.safari.options.WebrtcData;
36import io.appium.java_client.windows.options.PowerShellData;
37import io.appium.java_client.windows.options.WindowsOptions;
38import org.junit.Test;
39import org.openqa.selenium.Platform;
40
41import java.net.MalformedURLException;
42import java.net.URL;
43import java.time.Duration;
44
45import static org.junit.Assert.assertEquals;
46import static org.junit.Assert.assertFalse;
47import static org.junit.Assert.assertNotNull;
48import static org.junit.Assert.assertTrue;
49
50@SuppressWarnings("ConstantConditions")
51public class OptionsBuildingTest {
52    @Test
53    public void canBuildXcuiTestOptions() throws MalformedURLException {
54        XCUITestOptions options = new XCUITestOptions();
55        assertEquals(Platform.IOS, options.getPlatformName());
56        assertEquals(AutomationName.IOS_XCUI_TEST, options.getAutomationName().orElse(null));
57        options.setNewCommandTimeout(Duration.ofSeconds(10))
58                .noReset()
59                .setWdaBaseUrl("http://localhost:8000")
60                .setPermissions(new Permissions()
61                        .withAppPermissions("com.apple.MobileSafari",
62                                ImmutableMap.of("calendar", "YES")))
63                .setSafariSocketChunkSize(10)
64                .setCommandTimeouts(new CommandTimeouts()
65                        .withCommandTimeout("yolo", Duration.ofSeconds(1)));
66        assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));
67        assertEquals(new URL("http://localhost:8000"), options.getWdaBaseUrl().orElse(null));
68        assertNotNull(options.getPermissions()
69                .map((v) -> v.getAppPermissions("com.apple.MobileSafari"))
70                .orElse(null));
71        assertEquals(10L, (long) options.getSafariSocketChunkSize().orElse(0));
72        assertEquals(1L, options.getCommandTimeouts().orElse(null).left()
73                .getCommandTimeout("yolo").orElse(null).getSeconds());
74    }
75
76    @Test
77    public void canBuildUiAutomator2Options() throws MalformedURLException {
78        UiAutomator2Options options = new UiAutomator2Options();
79        assertEquals(Platform.ANDROID, options.getPlatformName());
80        assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, options.getAutomationName().orElse(null));
81        options.setNewCommandTimeout(Duration.ofSeconds(10))
82                .noReset()
83                .setAdbExecTimeout(Duration.ofSeconds(3))
84                .suppressKillServer()
85                .setMjpegScreenshotUrl(new URL("http://yolo.com"))
86                .setKeystoreConfig(new KeystoreConfig("path", "password", "keyAlias", "keyPassword"));
87        assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));
88        assertEquals(Duration.ofSeconds(3), options.getAdbExecTimeout().orElse(null));
89        assertEquals(new URL("http://yolo.com"), options.getMjpegScreenshotUrl().orElse(null));
90        assertEquals("path", options.getKeystoreConfig().orElse(null).getPath());
91        assertEquals("keyAlias", options.getKeystoreConfig().orElse(null).getKeyAlias());
92        assertTrue(options.doesSuppressKillServer().orElse(false));
93    }
94
95    @Test
96    public void canBuildEspressoOptions() {
97        EspressoOptions options = new EspressoOptions();
98        assertEquals(Platform.ANDROID, options.getPlatformName());
99        assertEquals(AutomationName.ESPRESSO, options.getAutomationName().orElse(null));
100        options.setNewCommandTimeout(Duration.ofSeconds(10))
101                .forceEspressoRebuild()
102                .setAppLocale(new AppLocale()
103                        .withCountry("CN")
104                        .withLanguage("zh")
105                        .withVariant("hans"))
106                .setEspressoBuildConfig(new EspressoBuildConfig()
107                        .withAdditionalAppDependencies(ImmutableList.of(
108                                "com.dep1:1.2.3",
109                                "com.dep2:1.2.3"
110                        ))
111                );
112        assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));
113        assertEquals("CN", options.getAppLocale().orElse(null).getCountry().orElse(null));
114        assertEquals(2, options.getEspressoBuildConfig().orElse(null)
115                        .left().getAdditionalAppDependencies().orElse(null).size());
116        assertTrue(options.doesForceEspressoRebuild().orElse(false));
117    }
118
119    @Test
120    public void canBuildWindowsOptions() {
121        WindowsOptions options = new WindowsOptions();
122        assertEquals(Platform.WINDOWS, options.getPlatformName());
123        assertEquals(AutomationName.WINDOWS, options.getAutomationName().orElse(null));
124        options.setNewCommandTimeout(Duration.ofSeconds(10))
125                .setPrerun(new PowerShellData().withScript("yolo prescript"))
126                .setPostrun(new PowerShellData().withCommand("yolo command"));
127        assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));
128        assertEquals("yolo prescript", options.getPrerun().orElse(null).getScript().orElse(null));
129        assertEquals("yolo command", options.getPostrun().orElse(null).getCommand().orElse(null));
130    }
131
132    @Test
133    public void canBuildMac2Options() {
134        Mac2Options options = new Mac2Options();
135        assertEquals(Platform.MAC, options.getPlatformName());
136        assertEquals(AutomationName.MAC2, options.getAutomationName().orElse(null));
137        options.setNewCommandTimeout(Duration.ofSeconds(10))
138                .skipAppKill()
139                .setPrerun(new AppleScriptData().withScript("yolo prescript"))
140                .setPostrun(new AppleScriptData().withCommand("yolo command"));
141        assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));
142        assertEquals("yolo prescript", options.getPrerun().orElse(null).getScript().orElse(null));
143        assertEquals("yolo command", options.getPostrun().orElse(null).getCommand().orElse(null));
144        assertTrue(options.doesSkipAppKill().orElse(false));
145        assertFalse(options.doesEventTimings().isPresent());
146    }
147
148    @Test
149    public void canBuildGeckoOptions() {
150        GeckoOptions options = new GeckoOptions();
151        options.setPlatformName(Platform.MAC.toString());
152        assertEquals(Platform.MAC, options.getPlatformName());
153        assertEquals(AutomationName.GECKO, options.getAutomationName().orElse(null));
154        options.setNewCommandTimeout(Duration.ofSeconds(10))
155                .setVerbosity(Verbosity.TRACE)
156                .setMozFirefoxOptions(ImmutableMap.of(
157                    "profile", "yolo"
158                ));
159        assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));
160        assertEquals(Verbosity.TRACE, options.getVerbosity().orElse(null));
161        assertEquals("yolo", options.getMozFirefoxOptions().orElse(null)
162                .get("profile"));
163    }
164
165    @Test
166    public void canBuildSafariOptions() {
167        SafariOptions options = new SafariOptions();
168        assertEquals(Platform.IOS, options.getPlatformName());
169        assertEquals(AutomationName.SAFARI, options.getAutomationName().orElse(null));
170        options.setNewCommandTimeout(Duration.ofSeconds(10))
171                .safariUseSimulator()
172                .setWebkitWebrtc(new WebrtcData()
173                        .withDisableIceCandidateFiltering(true)
174                        .withDisableInsecureMediaCapture(true)
175                );
176        assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));
177        assertTrue(options.doesSafariUseSimulator().orElse(false));
178        assertTrue(options.getWebkitWebrtc().orElse(null)
179                .doesDisableIceCandidateFiltering().orElse(false));
180        assertTrue(options.getWebkitWebrtc().orElse(null)
181                .doesDisableInsecureMediaCapture().orElse(false));
182    }
183}
184
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 withCountry code on LambdaTest Cloud Grid

Execute automation tests with withCountry 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)