How to use MobileOptions class of io.appium.java_client.remote package

Best io.appium code snippet using io.appium.java_client.remote.MobileOptions

MobileOptions.java

Source:MobileOptions.java Github

copy

Full Screen

...19import org.openqa.selenium.ScreenOrientation;20import org.openqa.selenium.remote.CapabilityType;21import java.net.URL;22import java.time.Duration;23public class MobileOptions<T extends MobileOptions<T>> extends MutableCapabilities {24 /**25 * Creates new instance with no preset capabilities.26 */27 public MobileOptions() {28 }29 /**30 * Creates new instance with provided capabilities capabilities.31 *32 * @param source is Capabilities instance to merge into new instance33 */34 public MobileOptions(Capabilities source) {35 merge(source);36 }37 /**38 * Set the kind of mobile device or emulator to use.39 *40 * @param platform the kind of mobile device or emulator to use.41 * @return this MobileOptions, for chaining.42 * @see org.openqa.selenium.remote.CapabilityType#PLATFORM_NAME43 */44 public T setPlatformName(String platform) {45 return amend(CapabilityType.PLATFORM_NAME, platform);46 }47 /**48 * Get the kind of mobile device or emulator to use.49 *50 * @return String representing the kind of mobile device or emulator to use.51 * @see org.openqa.selenium.remote.CapabilityType#PLATFORM_NAME52 */53 public String getPlatformName() {54 return (String) getCapability(CapabilityType.PLATFORM_NAME);55 }56 /**57 * Set the absolute local path for the location of the App.58 * The or remote http URL to a {@code .ipa} file (IOS),59 *60 * @param path is a String representing the location of the App61 * @return this MobileOptions, for chaining.62 * @see MobileCapabilityType#APP63 */64 public T setApp(String path) {65 return amend(MobileCapabilityType.APP, path);66 }67 /**68 * Set the remote http URL for the location of the App.69 *70 * @param url is the URL representing the location of the App71 * @return this MobileOptions, for chaining.72 * @see MobileCapabilityType#APP73 */74 public T setApp(URL url) {75 return setApp(url.toString());76 }77 /**78 * Get the app location.79 *80 * @return String representing app location81 * @see MobileCapabilityType#APP82 */83 public String getApp() {84 return (String) getCapability(MobileCapabilityType.APP);85 }86 /**87 * Set the automation engine to use.88 *89 * @param name is the name of the automation engine90 * @return this MobileOptions, for chaining.91 * @see MobileCapabilityType#AUTOMATION_NAME92 */93 public T setAutomationName(String name) {94 return amend(MobileCapabilityType.AUTOMATION_NAME, name);95 }96 /**97 * Get the automation engine to use.98 *99 * @return String representing the name of the automation engine100 * @see MobileCapabilityType#AUTOMATION_NAME101 */102 public String getAutomationName() {103 return (String) getCapability(MobileCapabilityType.AUTOMATION_NAME);104 }105 /**106 * Set the app to move directly into Webview context.107 *108 * @return this MobileOptions, for chaining.109 * @see MobileCapabilityType#AUTO_WEBVIEW110 */111 public T setAutoWebview() {112 return setAutoWebview(true);113 }114 /**115 * Set whether the app moves directly into Webview context.116 *117 * @param bool is whether the app moves directly into Webview context.118 * @return this MobileOptions, for chaining.119 * @see MobileCapabilityType#AUTO_WEBVIEW120 */121 public T setAutoWebview(boolean bool) {122 return amend(MobileCapabilityType.AUTO_WEBVIEW, bool);123 }124 /**125 * Get whether the app moves directly into Webview context.126 *127 * @return true if app moves directly into Webview context.128 * @see MobileCapabilityType#AUTO_WEBVIEW129 */130 public boolean doesAutoWebview() {131 return (boolean) getCapability(MobileCapabilityType.AUTO_WEBVIEW);132 }133 /**134 * Set the app to delete any generated files at the end of a session.135 *136 * @return this MobileOptions, for chaining.137 * @see MobileCapabilityType#CLEAR_SYSTEM_FILES138 */139 public T setClearSystemFiles() {140 return setClearSystemFiles(true);141 }142 /**143 * Set whether the app deletes generated files at the end of a session.144 *145 * @param bool is whether the app deletes generated files at the end of a session.146 * @return this MobileOptions, for chaining.147 * @see MobileCapabilityType#CLEAR_SYSTEM_FILES148 */149 public T setClearSystemFiles(boolean bool) {150 return amend(MobileCapabilityType.CLEAR_SYSTEM_FILES, bool);151 }152 /**153 * Get whether the app deletes generated files at the end of a session.154 *155 * @return true if the app deletes generated files at the end of a session.156 * @see MobileCapabilityType#CLEAR_SYSTEM_FILES157 */158 public boolean doesClearSystemFiles() {159 return (boolean) getCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES);160 }161 /**162 * Set the name of the device.163 *164 * @param deviceName is the name of the device.165 * @return this MobileOptions, for chaining.166 * @see MobileCapabilityType#DEVICE_NAME167 */168 public T setDeviceName(String deviceName) {169 return amend(MobileCapabilityType.DEVICE_NAME, deviceName);170 }171 /**172 * Get the name of the device.173 *174 * @return String representing the name of the device.175 * @see MobileCapabilityType#DEVICE_NAME176 */177 public String getDeviceName() {178 return (String) getCapability(MobileCapabilityType.DEVICE_NAME);179 }180 /**181 * Set the app to enable performance logging.182 *183 * @return this MobileOptions, for chaining.184 * @see MobileCapabilityType#ENABLE_PERFORMANCE_LOGGING185 */186 public T setEnablePerformanceLogging() {187 return setEnablePerformanceLogging(true);188 }189 /**190 * Set whether the app logs performance.191 *192 * @param bool is whether the app logs performance.193 * @return this MobileOptions, for chaining.194 * @see MobileCapabilityType#ENABLE_PERFORMANCE_LOGGING195 */196 public T setEnablePerformanceLogging(boolean bool) {197 return amend(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING, bool);198 }199 /**200 * Get the app logs performance.201 *202 * @return true if the app logs performance.203 * @see MobileCapabilityType#ENABLE_PERFORMANCE_LOGGING204 */205 public boolean isEnablePerformanceLogging() {206 return (boolean) getCapability(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING);207 }208 /**209 * Set the app to report the timings for various Appium-internal events.210 *211 * @return this MobileOptions, for chaining.212 * @see MobileCapabilityType#EVENT_TIMINGS213 */214 public T setEventTimings() {215 return setEventTimings(true);216 }217 /**218 * Set whether the app reports the timings for various Appium-internal events.219 *220 * @param bool is whether the app enables event timings.221 * @return this MobileOptions, for chaining.222 * @see MobileCapabilityType#EVENT_TIMINGS223 */224 public T setEventTimings(boolean bool) {225 return amend(MobileCapabilityType.EVENT_TIMINGS, bool);226 }227 /**228 * Get whether the app reports the timings for various Appium-internal events.229 *230 * @return true if the app reports event timings.231 * @see MobileCapabilityType#EVENT_TIMINGS232 */233 public boolean doesEventTimings() {234 return (boolean) getCapability(MobileCapabilityType.EVENT_TIMINGS);235 }236 /**237 * Set the app to do a full reset.238 *239 * @return this MobileOptions, for chaining.240 * @see MobileCapabilityType#FULL_RESET241 */242 public T setFullReset() {243 return setFullReset(true);244 }245 /**246 * Set whether the app does a full reset.247 *248 * @param bool is whether the app does a full reset.249 * @return this MobileOptions, for chaining.250 * @see MobileCapabilityType#FULL_RESET251 */252 public T setFullReset(boolean bool) {253 return amend(MobileCapabilityType.FULL_RESET, bool);254 }255 /**256 * Get whether the app does a full reset.257 *258 * @return true if the app does a full reset.259 * @see MobileCapabilityType#FULL_RESET260 */261 public boolean doesFullReset() {262 return (boolean) getCapability(MobileCapabilityType.FULL_RESET);263 }264 /**265 * Set language abbreviation for use in session.266 *267 * @param language is the language abbreviation.268 * @return this MobileOptions, for chaining.269 * @see MobileCapabilityType#LANGUAGE270 */271 public T setLanguage(String language) {272 return amend(MobileCapabilityType.LANGUAGE, language);273 }274 /**275 * Get language abbreviation for use in session.276 *277 * @return String representing the language abbreviation.278 * @see MobileCapabilityType#LANGUAGE279 */280 public String getLanguage() {281 return (String) getCapability(MobileCapabilityType.LANGUAGE);282 }283 /**284 * Set locale abbreviation for use in session.285 *286 * @param locale is the locale abbreviation.287 * @return this MobileOptions, for chaining.288 * @see MobileCapabilityType#LOCALE289 */290 public T setLocale(String locale) {291 return amend(MobileCapabilityType.LOCALE, locale);292 }293 /**294 * Get locale abbreviation for use in session.295 *296 * @return String representing the locale abbreviation.297 * @see MobileCapabilityType#LOCALE298 */299 public String getLocale() {300 return (String) getCapability(MobileCapabilityType.LOCALE);301 }302 /**303 * Set the timeout for new commands.304 *305 * @param duration is the allowed time before seeing a new command.306 * @return this MobileOptions, for chaining.307 * @see MobileCapabilityType#NEW_COMMAND_TIMEOUT308 */309 public T setNewCommandTimeout(Duration duration) {310 return amend(MobileCapabilityType.NEW_COMMAND_TIMEOUT, duration.getSeconds());311 }312 /**313 * Get the timeout for new commands.314 *315 * @return allowed time before seeing a new command.316 * @see MobileCapabilityType#NEW_COMMAND_TIMEOUT317 */318 public Duration getNewCommandTimeout() {319 Object duration = getCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT);320 return Duration.ofSeconds(Long.parseLong("" + duration));321 }322 /**323 * Set the app not to do a reset.324 *325 * @return this MobileOptions, for chaining.326 * @see MobileCapabilityType#NO_RESET327 */328 public T setNoReset() {329 return setNoReset(true);330 }331 /**332 * Set whether the app does not do a reset.333 *334 * @param bool is whether the app does not do a reset.335 * @return this MobileOptions, for chaining.336 * @see MobileCapabilityType#NO_RESET337 */338 public T setNoReset(boolean bool) {339 return amend(MobileCapabilityType.NO_RESET, bool);340 }341 /**342 * Get whether the app does not do a reset.343 *344 * @return true if the app does not do a reset.345 * @see MobileCapabilityType#NO_RESET346 */347 public boolean doesNoReset() {348 return (boolean) getCapability(MobileCapabilityType.NO_RESET);349 }350 /**351 * Set the orientation of the screen.352 *353 * @param orientation is the screen orientation.354 * @return this MobileOptions, for chaining.355 * @see MobileCapabilityType#ORIENTATION356 */357 public T setOrientation(ScreenOrientation orientation) {358 return amend(MobileCapabilityType.ORIENTATION, orientation);359 }360 /**361 * Get the orientation of the screen.362 *363 * @return ScreenOrientation of the app.364 * @see MobileCapabilityType#ORIENTATION365 */366 public ScreenOrientation getOrientation() {367 return (ScreenOrientation) getCapability(MobileCapabilityType.ORIENTATION);368 }369 /**370 * Set the location of the app(s) to install before running a test.371 *372 * @param apps is the apps to install.373 * @return this MobileOptions, for chaining.374 * @see MobileCapabilityType#OTHER_APPS375 */376 public T setOtherApps(String apps) {377 return amend(MobileCapabilityType.OTHER_APPS, apps);378 }379 /**380 * Get the list of apps to install before running a test.381 *382 * @return String of apps to install.383 * @see MobileCapabilityType#OTHER_APPS384 */385 public String getOtherApps() {386 return (String) getCapability(MobileCapabilityType.OTHER_APPS);387 }388 /**389 * Set the version of the platform.390 *391 * @param version is the platform version.392 * @return this MobileOptions, for chaining.393 * @see MobileCapabilityType#PLATFORM_VERSION394 */395 public T setPlatformVersion(String version) {396 return amend(MobileCapabilityType.PLATFORM_VERSION, version);397 }398 /**399 * Get the version of the platform.400 *401 * @return String representing the platform version.402 * @see MobileCapabilityType#PLATFORM_VERSION403 */404 public String getPlatformVersion() {405 return (String) getCapability(MobileCapabilityType.PLATFORM_VERSION);406 }407 /**408 * Set the app to print page source when a find operation fails.409 *410 * @return this MobileOptions, for chaining.411 * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE412 */413 public T setPrintPageSourceOnFindFailure() {414 return setPrintPageSourceOnFindFailure(true);415 }416 /**417 * Set whether the app to print page source when a find operation fails.418 *419 * @param bool is whether to print page source.420 * @return this MobileOptions, for chaining.421 * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE422 */423 public T setPrintPageSourceOnFindFailure(boolean bool) {424 return amend(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE, bool);425 }426 /**427 * Get whether the app to print page source when a find operation fails.428 *429 * @return true if app prints page source.430 * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE431 */432 public boolean doesPrintPageSourceOnFindFailure() {433 return (boolean) getCapability(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE);434 }435 /**436 * Set the id of the device.437 *438 * @param id is the unique device identifier.439 * @return this MobileOptions, for chaining.440 * @see MobileCapabilityType#UDID441 */442 public T setUdid(String id) {443 return amend(MobileCapabilityType.UDID, id);444 }445 /**446 * Get the id of the device.447 *448 * @return String representing the unique device identifier.449 * @see MobileCapabilityType#UDID450 */451 public String getUdid() {452 return (String) getCapability(MobileCapabilityType.UDID);453 }...

Full Screen

Full Screen

SetUpSteps.java

Source:SetUpSteps.java Github

copy

Full Screen

1package stepdefinition;2import java.io.File;3import java.net.URL;4import java.util.Arrays;5import java.util.Collection;6import java.util.HashMap;7import java.util.LinkedHashMap;8import java.util.Set;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.chrome.ChromeOptions;11import org.openqa.selenium.remote.CapabilityType;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.remote.RemoteWebDriver;14import org.testng.Reporter;15import io.appium.java_client.AppiumDriver;16import io.cucumber.core.api.Scenario;17import io.cucumber.java.After;18import io.cucumber.java.AfterStep;19import io.cucumber.java.Before;20import utils.DriverUtils;21public class SetUpSteps {22 private static boolean initialized = false;23 protected String url;24 25 public static HashMap<String,String> testMap = new HashMap<String,String>();26 27 private static ThreadLocal<AppiumDriver> threadAppiumDriver = new ThreadLocal<AppiumDriver>();28 private static ThreadLocal<RemoteWebDriver> threadMobileWebDriver = new ThreadLocal<RemoteWebDriver>();29 private static ThreadLocal<RemoteWebDriver> threadDesktopWebDriver = new ThreadLocal<RemoteWebDriver>();30 private static ThreadLocal<String> featureFile = new ThreadLocal<String>();31 private static ThreadLocal<String> scenarioName = new ThreadLocal<String>();32 private static ThreadLocal<String> featureGroup = new ThreadLocal<String>();33 private static ThreadLocal<String> threadUrl = new ThreadLocal<String>();34 private static ThreadLocal<String> threadAccountInfo = new ThreadLocal<String>();35 private static ThreadLocal<LinkedHashMap<String,String>> contextVariables = new ThreadLocal<LinkedHashMap<String,String>>();36 37 protected static String testDataPath = null;38 39 40 public WebDriver getMobileWebDriver() {41 WebDriver wdriver = threadMobileWebDriver.get();42 return wdriver;43 }44 45 public AppiumDriver getAppiumDriver() {46 AppiumDriver wdriver = threadAppiumDriver.get();47 return wdriver;48 }49 50 public WebDriver getDesktopWebDriver() {51 WebDriver wdriver = threadDesktopWebDriver.get();52 return wdriver;53 }54 55 public static void setMobileWebDriver(RemoteWebDriver driver) {56 threadMobileWebDriver.set(driver);57 }58 59 public static void setAppiumDriver(AppiumDriver driver) {60 threadAppiumDriver.set(driver);61 }62 63 public static void setDesktopWebDriver(RemoteWebDriver driver) {64 threadDesktopWebDriver.set(driver);65 }66 67 68 @Before69 public void beforeScenario(Scenario scenario) throws Exception {70 try{71 String currentFeaturePath = scenario.getUri();72 String currentFeatureName = currentFeaturePath.substring(currentFeaturePath.lastIndexOf("/") +1, currentFeaturePath.lastIndexOf(".")).toLowerCase();73 74 Collection<String> scenarioTag = scenario.getSourceTagNames();75 76 scenarioName.set(scenario.getName().split(":")[0]);77 String hub = System.getProperty("hub");78 String browser = System.getProperty("browser");79 if (!initialized) 80 featureFile.set(currentFeatureName);81 82 Reporter.log("Execution details: [{Feature = " + featureFile.get() + "} , {Scenario = " + scenarioName.get().toUpperCase() + "}, {Hub = " + hub + "}]", true);83 84 initializeDriver(hub,browser,scenarioTag);85 86 testDataPath = getResourcesPath() + "testdata/";87 }88 catch(Exception e) {89 e.printStackTrace();90 }91 }92 93 public void initializeDriver(String hub,String browserName,Collection<String> platform) {94 HashMap<String, Object> plugin = new HashMap<String, Object>();95 String downloadPath = "X:/MMP_Downloads/Client/";96 97 try {98 if (browserName.equalsIgnoreCase("chrome") && platform.contains("@desktopWeb")) {99 100 ChromeOptions options = new ChromeOptions();101 plugin.put("enabled", false);102 plugin.put("name", "Chrome PDF Viewer");103 104 HashMap<String, Object> prefs = new HashMap<String, Object>();105 prefs.put("profile.default_content_settings.popups", 0);106 prefs.put("download.default_directory", downloadPath);107 prefs.put("profile.default_content_settings.popups", 0);108 prefs.put("credentials_enable_service", false);109 prefs.put("profile.password_manager_enabled", false);110 prefs.put("plugins.plugins_list", Arrays.asList(plugin));111 112 options.setExperimentalOption("prefs", prefs);113 options.addArguments("start-maximized");114 options.addArguments("--disable-infobars");115 options.addArguments("--dns-prefetch-disable");116 117 setDesktopWebDriver(new RemoteWebDriver(new URL(hub), options)); 118 } if (browserName.equalsIgnoreCase("chrome") && platform.contains("@mobileWeb")) {119 ChromeOptions mobileoptions = new ChromeOptions();120 HashMap<String, String> mobileEmulation = new HashMap<String, String>();121 mobileEmulation.put("deviceName", "Galaxy S5");122 mobileoptions.setExperimentalOption("mobileEmulation", mobileEmulation);123 setMobileWebDriver(new RemoteWebDriver(new URL(hub), mobileoptions)); 124 } if (browserName.equalsIgnoreCase("chrome") && platform.contains("@nativemobileapp")){125 DesiredCapabilities capabilities = new DesiredCapabilities();126 capabilities.setCapability(CapabilityType.BROWSER_NAME, "");127 capabilities.setCapability("deviceName", "9243934");128 capabilities.setCapability("platformVersion", "9");129 capabilities.setCapability("platformName", "Android");130 capabilities.setCapability("appPackage", "com.google.android.youtube");131 capabilities.setCapability("appActivity", "com.google.android.apps.youtube.app.WatchWhileActivity");132 setAppiumDriver(new AppiumDriver(new URL(hub), capabilities)); 133 }134 //mmpController = new Controller(browserName,getDesktopWebDriver(),getMobileWebDriver(),getAppiumDriver());135 Reporter.log("Test trigerred from machine: " + System.getenv().get("COMPUTERNAME"), true);136 setContextVariable("screenShot","notRequired");137 //Reporter.log("Executing " + scenarioName.get().toUpperCase() + " on grid node: " +getGridExecutionNode(hub), true);138 initialized = true;139 } catch(Exception e) {140 e.printStackTrace();141 }142 }143 144 public void setUrl(String url) {145 setContextVariable("baseURL", url); 146 threadUrl.set(url); 147 }148 149 public String getUrl() {150 this.url = threadUrl.get();151 return url;152 }153 154 /*public Controller getController() {155 return mmpController;156 }*/157 158 public static void setAccountInfo(String accountInfo) {159 threadAccountInfo.set(accountInfo);160 }161 162 public static String getContextVariable(String key) {163 return contextVariables.get().get(key);164 }165 public static Set<String> getContextVariableKeys() {166 return contextVariables.get().keySet();167 }168 169 public static void setContextVariable(String key, String value) {170 LinkedHashMap<String, String> contextVarHash = new LinkedHashMap<String, String>();171 LinkedHashMap<String, String> existingHash = new LinkedHashMap<String, String>();172 if(contextVariables.get()!=null) existingHash.putAll(contextVariables.get());173 contextVarHash.put(key, value);174 existingHash.putAll(contextVarHash);175 contextVariables.set(existingHash);176 }177 178 public static void setContextVariable(HashMap<String, String> contextVarHash) {179 LinkedHashMap<String, String> existingHash = new LinkedHashMap<String, String>();180 existingHash.putAll(contextVarHash);181 contextVariables.set(existingHash);182 }183 184 public static String getFeatureFile() {185 return featureFile.get();186 }187 188 public static String getScenarioName() {189 return scenarioName.get();190 }191 public static String getFeatureGroup() {192 return featureGroup.get();193 }194 195 public static void setFeatureGroup(String str_featureGroup) {196 featureGroup.set(str_featureGroup);197 }198 199 @After200 public void afterScenario(Scenario scenario) throws Exception {201 initialized = false;202 File directory = new File(".");203 System.out.println("Path in getpath" + directory.getCanonicalPath());204 try{205 if(getDesktopWebDriver()!=null)206 getDesktopWebDriver().quit();207 if(getAppiumDriver()!=null)208 getAppiumDriver().quit();209 210 }catch(Exception e){211 Reporter.log("Error in Initializing the test", true);212 e.printStackTrace();213 }214 finally{215 //if(mmpController != null){216 //getDesktopWebDriverClient().quit();217 //mmpController.getMobileWebDriverClient().quit();218 //}219 }220 }221 222 223 @AfterStep224 public void afterScnearioStep(Scenario scenario) throws Exception{225 if(getContextVariable("screenShot").equals("required")) {226 DriverUtils.takeScreenShot(scenario, getDesktopWebDriver());227 setContextVariable("screenShot","notRequired");228 }229 230 }231 232 /*public String getGridExecutionNode(String hubUrl){233 String node = null;234 try{235 String hub = hubUrl.split("//")[1].split(":")[0]; // Grid Hub hostname236 if(hub.toUpperCase().contains("LOCALHOST")) return hubUrl;237 238 int port = Integer.parseInt(hubUrl.split("//")[1].split(":")[1].split("/")[0]); // Grid Hub port number239 240 OkHttpClient client = new OkHttpClient();241 242 HttpUrl url = new HttpUrl.Builder()243 .scheme("http")244 .host(hub)245 .port(port)246 .addPathSegments("grid/api/testsession")247 .addQueryParameter("session",threadDriver.get().getSessionId().toString())248 .build();249 250 Request request = new Request.Builder()251 .url(url)252 .build();253 254 Response response = client.newCall(request).execute();255 JSONObject object = new JSONObject(response.body().string());256 String proxyID = (String) object.get("proxyId");257 node = proxyID.split("//")[1].split(":")[0];258 }catch(Exception e){259 Reporter.log("Error in figuring out grid node running this test", true);260 e.printStackTrace();261 262 }263 return node;264 }*/265 public static String getTestDataPath() {266 return testDataPath;267 }268 269 public static String getResourcesPath() {270 if(File.separator.equals("/")){271 return "test-classes/";272 } 273 else{274 return System.getProperty("user.dir") + "/src/test/resources/";275 }276 }277 278}...

Full Screen

Full Screen

LocalBrowserUtilWap.java

Source:LocalBrowserUtilWap.java Github

copy

Full Screen

...59 case ("pwa"):60 String pwaBrowserDriver = !(Platform.getCurrent().toString().equalsIgnoreCase("MAC")) ? "chromedriver.exe"61 : "chromedriver_mac";62 System.setProperty("webdriver.chrome.driver", browser_driver_path + pwaBrowserDriver);63 ChromeOptions pwaMobileOptions = new ChromeOptions();64 Map<String, String> pwaMobileEmulation = new HashMap<String, String>();65 pwaMobileEmulation.put("deviceName", "Nexus 5");66 Map<String, Object> pwaChromeOptions = new HashMap<String, Object>();67 pwaChromeOptions.put("mobileEmulation", pwaMobileEmulation);68 pwaMobileOptions.setExperimentalOption("mobileEmulation", pwaMobileEmulation);69 driver = new ChromeDriver(pwaMobileOptions);70 break;71 case ("specificDevice"):72 String deviceBrowserDriver = !(Platform.getCurrent().toString().equalsIgnoreCase("MAC"))73 ? "chromedriver.exe" : "chromedriver_mac";74 System.setProperty("webdriver.chrome.driver", browser_driver_path + deviceBrowserDriver);75 ChromeOptions deviceMobileOptions = new ChromeOptions();76 Map<String, String> deviceMobileEmulation = new HashMap<String, String>();77 deviceMobileEmulation.put("deviceName", BaseTest.deviceName);78 Map<String, Object> deviceChromeOptions = new HashMap<String, Object>();79 deviceChromeOptions.put("mobileEmulation", deviceMobileEmulation);80 deviceMobileOptions.setExperimentalOption("mobileEmulation", deviceMobileEmulation);81 driver = new ChromeDriver(deviceMobileOptions);82 break;8384 case ("specificUserAgent"):85 String userAgentBrowserDriver = !(Platform.getCurrent().toString().equalsIgnoreCase("MAC"))86 ? "chromedriver.exe" : "chromedriver_mac";87 System.setProperty("webdriver.chrome.driver", browser_driver_path + userAgentBrowserDriver);88 ChromeOptions userAgentMobileOptions = new ChromeOptions();89 Map<String, Object> userAgentMobileEmulation = new HashMap<String, Object>();90 Map<String, Object> deviceMetrics = new HashMap<>();91 deviceMetrics.put("width", 375);92 deviceMetrics.put("height", 700);93 deviceMetrics.put("pixelRatio", 3.0);94 userAgentMobileEmulation.put("deviceMetrics", deviceMetrics);95 userAgentMobileEmulation.put("userAgent", BaseTest.userAgent);96 Map<String, Object> userAgentChromeOptions = new HashMap<String, Object>();97 userAgentChromeOptions.put("mobileEmulation", userAgentMobileEmulation);98 userAgentMobileOptions.setExperimentalOption("mobileEmulation", userAgentMobileEmulation);99 driver = new ChromeDriver(userAgentMobileOptions);100 break;101102 default:103104 String browserDriver = !(Platform.getCurrent().toString().equalsIgnoreCase("MAC")) ? "chromedriver.exe"105 : "chromedriver_mac";106 System.setProperty("webdriver.chrome.driver", browser_driver_path + browserDriver);107 ChromeOptions mobileOptions = new ChromeOptions();108 Map<String, String> mobileEmulation = new HashMap<String, String>();109 mobileEmulation.put("deviceName", "iPhone 6");110 Map<String, Object> chromeOptions = new HashMap<String, Object>();111 chromeOptions.put("mobileEmulation", mobileEmulation);112 mobileOptions.setExperimentalOption("mobileEmulation", mobileEmulation);113 driver = new ChromeDriver(mobileOptions); ...

Full Screen

Full Screen

MobileOptionsTest.java

Source:MobileOptionsTest.java Github

copy

Full Screen

...21import java.net.URL;22import java.time.Duration;23import java.util.ArrayList;24import static org.junit.Assert.*;25public class MobileOptionsTest {26 private MobileOptions mobileOptions = new MobileOptions<>();27 @Test28 public void acceptsExistingCapabilities() {29 MutableCapabilities capabilities = new MutableCapabilities();30 capabilities.setCapability("deviceName", "Pixel");31 capabilities.setCapability("platformVersion", "10");32 capabilities.setCapability("newCommandTimeout", 60);33 mobileOptions = new MobileOptions<>(capabilities);34 assertEquals("Pixel", mobileOptions.getDeviceName());35 assertEquals("10", mobileOptions.getPlatformVersion());36 assertEquals(Duration.ofSeconds(60), mobileOptions.getNewCommandTimeout());37 }38 @Test39 public void acceptsMobileCapabilities() throws MalformedURLException {40 mobileOptions.setApp(new URL("http://example.com/myapp.apk"))41 .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)42 .setPlatformVersion("10")43 .setDeviceName("Pixel")44 .setOtherApps("/path/to/app.apk")45 .setLocale("fr_CA")46 .setUdid("1ae203187fc012g")47 .setOrientation(ScreenOrientation.LANDSCAPE)...

Full Screen

Full Screen

SupportsAppLocaleOption.java

Source:SupportsAppLocaleOption.java Github

copy

Full Screen

...31 * list of available language abbreviations.32 * Example: {"language": "zh", "country": "CN", "variant": "Hans"}.33 *34 * @param locale App locale data.35 * @return this MobileOptions, for chaining.36 */37 default T setAppLocale(AppLocale locale) {38 return amend(APP_LOCALE_OPTION, locale.toMap());39 }40 /**41 * Get the locale for the app under test.42 *43 * @return App locale data.44 */45 default Optional<AppLocale> getAppLocale() {46 //noinspection unchecked47 return Optional.ofNullable(getCapability(APP_LOCALE_OPTION))48 .map((v) -> new AppLocale((Map<String, Object>) v));49 }...

Full Screen

Full Screen

SupportsLocaleScriptOption.java

Source:SupportsLocaleScriptOption.java Github

copy

Full Screen

...26 * for example zh-Hans-CN.27 * See https://developer.android.com/reference/java/util/Locale.html for more details.28 *29 * @param localeScript is the language abbreviation.30 * @return this MobileOptions, for chaining.31 */32 default T setLocaleScript(String localeScript) {33 return amend(LOCALE_SCRIPT_OPTION, localeScript);34 }35 /**36 * Get canonical name of the locale to be set for the app under test.37 *38 * @return Locale script value.39 */40 default Optional<String> getLocaleScript() {41 return Optional.ofNullable((String) getCapability(LOCALE_SCRIPT_OPTION));42 }43}...

Full Screen

Full Screen

AndroidOptions.java

Source:AndroidOptions.java Github

copy

Full Screen

...13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.appium.java_client.android;17import io.appium.java_client.remote.MobileOptions;18import io.appium.java_client.remote.MobilePlatform;19import org.openqa.selenium.Capabilities;20public class AndroidOptions extends MobileOptions<AndroidOptions> {21 public AndroidOptions() {22 setPlatformName(MobilePlatform.ANDROID);23 }24 public AndroidOptions(Capabilities source) {25 this();26 merge(source);27 }28}...

Full Screen

Full Screen

IOSOptions.java

Source:IOSOptions.java Github

copy

Full Screen

...13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.appium.java_client.ios;17import io.appium.java_client.remote.MobileOptions;18import io.appium.java_client.remote.MobilePlatform;19import org.openqa.selenium.Capabilities;20public class IOSOptions extends MobileOptions<IOSOptions> {21 public IOSOptions() {22 setPlatformName(MobilePlatform.IOS);23 }24 public IOSOptions(Capabilities source) {25 this();26 merge(source);27 }28}...

Full Screen

Full Screen

MobileOptions

Using AI Code Generation

copy

Full Screen

1MobileOptions options = new MobileOptions();2options.setCapability("deviceName", "Android Emulator");3options.setCapability("platformName", "Android");4options.setCapability("platformVersion", "6.0");5options.setCapability("appPackage", "com.android.calculator2");6options.setCapability("appActivity", "com.android.calculator2.Calculator");7options.setCapability("noReset", true);

Full Screen

Full Screen

MobileOptions

Using AI Code Generation

copy

Full Screen

1MobileOptions options = new MobileOptions();2options.setCapability("deviceName", "Pixel 2");3options.setCapability("platformName", "Android");4options.setCapability("appPackage", "com.android.calculator2");5options.setCapability("appActivity", "com.android.calculator2.Calculator");6options.setCapability("automationName", "UiAutomator2");

Full Screen

Full Screen

MobileOptions

Using AI Code Generation

copy

Full Screen

1MobileOptions options = new MobileOptions();2options.setCapability("deviceName", "Samsung Galaxy S8");3options.setCapability("platformName", "Android");4options.setCapability("platformVersion", "7.0");5options.setCapability("appPackage", "com.android.calculator2");6options.setCapability("appActivity", "com.android.calculator2.Calculator");7options.setCapability("noReset", true);8options.setCapability("fullReset", false);9options.setCapability("automationName", "UiAutomator2");10AndroidOptions options = new AndroidOptions();11options.setCapability("deviceName", "Samsung Galaxy S8");12options.setCapability("platformName", "Android");13options.setCapability("platformVersion", "7.0");14options.setCapability("appPackage", "com.android.calculator2");15options.setCapability("appActivity", "com.android.calculator2.Calculator");16options.setCapability("noReset", true);17options.setCapability("fullReset", false);18options.setCapability("automationName", "UiAutomator2");19IOSOptions options = new IOSOptions();20options.setCapability("deviceName", "iPhone 8");21options.setCapability("platformName", "iOS");22options.setCapability("platformVersion", "12.1");23options.setCapability("app", "/Users/<username>/Downloads/Calculator.app");24options.setCapability("noReset", true);25options.setCapability("fullReset", false);26options.setCapability("automationName", "XCUITest");

Full Screen

Full Screen

MobileOptions

Using AI Code Generation

copy

Full Screen

1MobileOptions mobileOptions = new MobileOptions();2mobileOptions.setCapability("platformName", "Android");3mobileOptions.setCapability("deviceName", "emulator-5554");4mobileOptions.setCapability("app", "C:\\Users\\username\\Downloads\\APK\\sample.apk");5AndroidOptions androidOptions = new AndroidOptions();6androidOptions.merge(mobileOptions);

Full Screen

Full Screen

MobileOptions

Using AI Code Generation

copy

Full Screen

1package appium.java;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.remote.DesiredCapabilities;5import io.appium.java_client.android.AndroidDriver;6import io.appium.java_client.remote.MobileCapabilityType;7import io.appium.java_client.remote.MobileOptions;8public class AppiumJava {9public static void main(String[] args) throws MalformedURLException {10DesiredCapabilities caps = new DesiredCapabilities();11caps.setCapability("deviceName", "Pixel 2 API 28");12caps.setCapability("platformName", "Android");13caps.setCapability("platformVersion", "9.0");14caps.setCapability("appPackage", "com.android.calculator2");15caps.setCapability("appActivity", "com.android.calculator2.Calculator");16caps.setCapability("noReset", "true");

Full Screen

Full Screen

MobileOptions

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.remote.MobileCapabilityType;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.remote.MobileOptions;4MobileOptions options = new MobileOptions();5options.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel 2");6options.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");7options.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.0");8options.setCapability(MobileCapabilityType.APP, "C:\\Users\\user1\\Downloads\\ApiDemos-debug.apk");9AndroidDriver driver = null;10try {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful