How to use AndroidOptions class of io.appium.java_client.android package

Best io.appium code snippet using io.appium.java_client.android.AndroidOptions

DriverParameterResolverExtension.java

Source:DriverParameterResolverExtension.java Github

copy

Full Screen

...159 FirefoxOptions firefoxOptions;160 ChromeOptions chromeOptions;161 EdgeOptions edgeOptions;162 InternetExplorerOptions internetExplorerOptions;163 AndroidOptions androidOptions;164 IOsOptions iOsOptions;165 // use new option modifiers if the list is not empty166 if (!modifiers.isEmpty()) {167 OptionCombiner optionCombiner = new OptionCombiner(modifiers);168 firefoxOptions = optionCombiner.getBrowserOptions(FirefoxOptions.class);169 chromeOptions = optionCombiner.getBrowserOptions(ChromeOptions.class);170 edgeOptions = optionCombiner.getBrowserOptions(EdgeOptions.class);171 internetExplorerOptions = optionCombiner.getBrowserOptions(InternetExplorerOptions.class);172 androidOptions = optionCombiner.getBrowserOptions(AndroidOptions.class);173 iOsOptions = optionCombiner.getBrowserOptions(IOsOptions.class);174 } else {175 firefoxOptions = new FirefoxOptions();176 chromeOptions = new ChromeOptions();177 edgeOptions = new EdgeOptions();178 internetExplorerOptions = new InternetExplorerOptions();179 androidOptions = new AndroidOptions();180 iOsOptions = new IOsOptions();181 }182 if (isRemote()) {183 if (getRemotePlatform() == BROWSERSTACK) {184 List<BrowserstackEnvironment> browserstackEnvironments = BrowserstackEnvironment.parseFromSystemProperties();185 if (browserstackEnvironments.size() != 1) {186 throw new BrowserstackEnvironmentException("Exactly one browserstack environment must be specified. " +187 "See BrowserstackSystemProperties class for more information.");188 }189 BrowserstackEnvironment browserstackEnv = browserstackEnvironments.get(0);190 firefoxOptions = browserstackEnv.addToCapabilities(firefoxOptions, testName);191 chromeOptions = browserstackEnv.addToCapabilities(chromeOptions, testName);192 edgeOptions = browserstackEnv.addToCapabilities(edgeOptions, testName);193 internetExplorerOptions = browserstackEnv.addToCapabilities(internetExplorerOptions, testName);...

Full Screen

Full Screen

AndroidDevice.java

Source:AndroidDevice.java Github

copy

Full Screen

1package com.daxiang.core.mobile.android;2import com.android.ddmlib.IDevice;3import com.android.ddmlib.InstallException;4import com.daxiang.App;5import com.daxiang.core.PortProvider;6import com.daxiang.core.mobile.Mobile;7import com.daxiang.core.mobile.appium.AppiumNativePageSourceHandler;8import com.daxiang.model.page.Page;9import com.daxiang.server.ServerClient;10import com.daxiang.core.mobile.MobileDevice;11import com.daxiang.core.mobile.android.scrcpy.Scrcpy;12import com.daxiang.core.mobile.android.scrcpy.ScrcpyVideoRecorder;13import com.daxiang.core.mobile.android.stf.AdbKit;14import com.daxiang.core.mobile.android.stf.Minicap;15import com.daxiang.core.mobile.android.stf.Minitouch;16import com.daxiang.core.mobile.appium.AndroidNativePageSourceHandler;17import com.daxiang.core.mobile.appium.AppiumServer;18import com.daxiang.utils.Terminal;19import com.daxiang.utils.UUIDUtil;20import io.appium.java_client.android.AndroidDriver;21import io.appium.java_client.android.AndroidStartScreenRecordingOptions;22import io.appium.java_client.remote.AndroidMobileCapabilityType;23import io.appium.java_client.remote.AutomationName;24import io.appium.java_client.remote.MobileCapabilityType;25import io.appium.java_client.remote.MobilePlatform;26import lombok.extern.slf4j.Slf4j;27import org.apache.commons.io.FileUtils;28import org.openqa.selenium.By;29import org.openqa.selenium.Capabilities;30import org.openqa.selenium.remote.DesiredCapabilities;31import org.openqa.selenium.remote.RemoteWebDriver;32import org.springframework.util.StringUtils;33import java.io.File;34import java.io.IOException;35import java.net.MalformedURLException;36import java.net.URL;37import java.nio.file.Files;38import java.nio.file.attribute.PosixFilePermission;39import java.time.Duration;40import java.util.Base64;41import java.util.HashSet;42import java.util.Set;43import java.util.concurrent.Executors;44import java.util.concurrent.ScheduledExecutorService;45import java.util.concurrent.TimeUnit;46/**47 * Created by jiangyitao.48 */49@Slf4j50public class AndroidDevice extends MobileDevice {51 public static final int PLATFORM = 1;52 public static final String TMP_FOLDER = "/data/local/tmp";53 private Integer sdkVersion;54 private IDevice iDevice;55 private Scrcpy scrcpy;56 private Minicap minicap;57 private Minitouch minitouch;58 private AdbKit adbKit;59 private boolean canUseAppiumRecordVideo = true;60 private ScrcpyVideoRecorder scrcpyVideoRecorder;61 public AndroidDevice(Mobile mobile, IDevice iDevice, AppiumServer appiumServer) {62 super(mobile, appiumServer);63 this.iDevice = iDevice;64 }65 @Override66 public RemoteWebDriver newDriver() {67 return new AndroidDriver(deviceServer.getUrl(), caps);68 }69 @Override70 protected Capabilities newCaps(Capabilities capsToMerge) {71 DesiredCapabilities capabilities = new DesiredCapabilities();72 capabilities.setCapability(MobileCapabilityType.NO_RESET, true);73 capabilities.setCapability(AndroidMobileCapabilityType.UNICODE_KEYBOARD, true);74 capabilities.setCapability(AndroidMobileCapabilityType.RESET_KEYBOARD, true);75 capabilities.setCapability("recreateChromeDriverSessions", true);76 // 加速初始化速度77 capabilities.setCapability("skipServerInstallation", true);78 capabilities.setCapability("skipDeviceInitialization", true);79 capabilities.setCapability("skipUnlock", true);80 if (!greaterOrEqualsToAndroid5()) { // 小于安卓5,必须指定app,否则会创建driver失败81 capabilities.setCapability("appPackage", "io.appium.android.apis");82 capabilities.setCapability("appActivity", "io.appium.android.apis.ApiDemos");83 }84 // **** 以上capabilities可被传入的caps覆盖 ****85 capabilities.merge(capsToMerge);86 // **** 以下capabilities具有更高优先级,将覆盖传入的caps ****87 if (greaterOrEqualsToAndroid5()) {88 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2); // UIAutomation2 is only supported since Android 5.0 (Lollipop)89 } else {90 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UIAutomator1");91 }92 capabilities.setCapability(AndroidMobileCapabilityType.SYSTEM_PORT, PortProvider.getUiautomator2ServerAvailablePort());93 capabilities.setCapability("chromedriverPort", PortProvider.getAndroidChromeDriverAvailablePort());94 String chromedriverFilePath = getChromedriverFilePath();95 if (!StringUtils.isEmpty(chromedriverFilePath)) {96 capabilities.setCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE, chromedriverFilePath);97 }98 capabilities.setCapability(MobileCapabilityType.UDID, getId());99 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, mobile.getName());100 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);101 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, mobile.getSystemVersion());102 capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, NEW_COMMAND_TIMEOUT);103 return capabilities;104 }105 public boolean greaterOrEqualsToAndroid5() {106 if (sdkVersion == null) {107 sdkVersion = AndroidUtil.getSdkVersion(iDevice); // 21 android5.0108 }109 return sdkVersion >= 21;110 }111 @Override112 public void installApp(String app) {113 boolean appIsUrl = true;114 try {115 new URL(app);116 } catch (MalformedURLException e) {117 appIsUrl = false;118 }119 if (appIsUrl) {120 try {121 File appFile = new File(UUIDUtil.getUUID());122 FileUtils.copyURLToFile(new URL(app), appFile);123 app = appFile.getAbsolutePath();124 } catch (IOException e) {125 throw new RuntimeException(e);126 }127 }128 ScheduledExecutorService scheduleService = handleInstallBtnAsync();129 try {130 // 若使用appium安装,将导致handleInstallBtnAsync无法继续处理安装时的弹窗131 // 主要因为appium server无法在安装app时,响应其他请求,所以这里用ddmlib安装132 AndroidUtil.installApk(iDevice, app);133 } catch (InstallException e) {134 throw new RuntimeException(String.format("[%s]安装app失败: %s", getId(), e.getMessage()), e);135 } finally {136 if (!scheduleService.isShutdown()) {137 scheduleService.shutdown();138 }139 if (appIsUrl) {140 FileUtils.deleteQuietly(new File(app));141 }142 }143 }144 @Override145 public int getNativePageType() {146 return Page.TYPE_ANDROID_NATIVE;147 }148 @Override149 public AppiumNativePageSourceHandler newAppiumNativePageSourceHandler() {150 return new AndroidNativePageSourceHandler();151 }152 @Override153 public String getLogType() {154 return "logcat";155 }156 @Override157 public void uninstallApp(String app) throws InstallException {158 AndroidUtil.uninstallApk(iDevice, app);159 }160 @Override161 public boolean acceptAlert() {162 try {163 driver.executeScript("mobile:acceptAlert");164 return true;165 } catch (Exception e) {166 return false;167 }168 }169 @Override170 public boolean dismissAlert() {171 try {172 driver.executeScript("mobile:dismissAlert");173 return true;174 } catch (Exception e) {175 return false;176 }177 }178 @Override179 public void startRecordingScreen() {180 if (canUseAppiumRecordVideo) {181 try {182 AndroidStartScreenRecordingOptions androidOptions = new AndroidStartScreenRecordingOptions();183 // Since Appium 1.8.2 the time limit can be up to 1800 seconds (30 minutes).184 androidOptions.withTimeLimit(Duration.ofMinutes(30));185 androidOptions.withBitRate(Integer.parseInt(App.getProperty("androidRecordVideoBitRate")) * 1000000); // default 4000000186 ((AndroidDriver) driver).startRecordingScreen(androidOptions);187 return;188 } catch (Exception e) {189 log.warn("[{}]无法使用appium录制视频", getId(), e);190 canUseAppiumRecordVideo = false;191 }192 }193 if (scrcpyVideoRecorder == null) {194 scrcpyVideoRecorder = new ScrcpyVideoRecorder(getId());195 }196 scrcpyVideoRecorder.start();197 }198 @Override199 public File stopRecordingScreen() throws IOException {200 if (canUseAppiumRecordVideo) {201 File videoFile = new File(UUIDUtil.getUUID() + ".mp4");202 String base64Video = ((AndroidDriver) driver).stopRecordingScreen();203 FileUtils.writeByteArrayToFile(videoFile, Base64.getDecoder().decode(base64Video), false);204 return videoFile;205 } else {206 return scrcpyVideoRecorder.stop();207 }208 }209 /**210 * 异步处理安装app时弹窗211 */212 private ScheduledExecutorService handleInstallBtnAsync() {213 String installBtnXpath = "//android.widget.Button[" +214 "contains(@text, '安装') " +215 "or contains(@text, '下一步') " +216 "or contains(@text, '确定') " +217 "or contains(@text, '确认')" +218 "]";219 By installBtnBy = By.xpath(installBtnXpath);220 ScheduledExecutorService scheduleService = Executors.newSingleThreadScheduledExecutor();221 scheduleService.scheduleAtFixedRate(() -> {222 try {223 driver.findElement(installBtnBy).click();224 } catch (Exception ign) {225 }226 }, 0, 1, TimeUnit.SECONDS);227 return scheduleService;228 }229 public synchronized String getChromedriverFilePath() {230 String downloadUrl = ServerClient.getInstance().getChromedriverDownloadUrl(getId());231 if (StringUtils.isEmpty(downloadUrl)) {232 return null;233 }234 String fileName = downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1);235 File chromedriverFile = new File("vendor/driver/" + fileName);236 if (!chromedriverFile.exists()) {237 try {238 log.info("[{}]download chromedriver from {}", getId(), downloadUrl);239 FileUtils.copyURLToFile(new URL(downloadUrl), chromedriverFile);240 if (!Terminal.IS_WINDOWS) {241 // 权限242 Set<PosixFilePermission> permissions = new HashSet<>();243 permissions.add(PosixFilePermission.OWNER_READ);244 permissions.add(PosixFilePermission.OWNER_WRITE);245 permissions.add(PosixFilePermission.OWNER_EXECUTE);246 // 赋予权限247 Files.setPosixFilePermissions(chromedriverFile.toPath(), permissions);248 }249 } catch (Exception e) {250 log.error(e.getMessage(), e);251 return null;252 }253 }254 return chromedriverFile.getAbsolutePath();255 }256 public IDevice getIDevice() {257 return iDevice;258 }259 public void setIDevice(IDevice iDevice) {260 // mobile重新插拔后,IDevice需要更新261 this.iDevice = iDevice;262 if (minicap != null) {263 minicap.setIDevice(iDevice);264 }265 if (minitouch != null) {266 minitouch.setIDevice(iDevice);267 }268 if (scrcpy != null) {269 scrcpy.setIDevice(iDevice);270 }271 }272 public Scrcpy getScrcpy() {273 return scrcpy;274 }275 public void setScrcpy(Scrcpy scrcpy) {276 this.scrcpy = scrcpy;277 }278 public Minicap getMinicap() {279 return minicap;280 }281 public void setMinicap(Minicap minicap) {282 this.minicap = minicap;283 }284 public Minitouch getMinitouch() {285 return minitouch;286 }287 public void setMinitouch(Minitouch minitouch) {288 this.minitouch = minitouch;289 }290 public AdbKit getAdbKit() {291 return adbKit;292 }293 public void setAdbKit(AdbKit adbKit) {294 this.adbKit = adbKit;295 }296}...

Full Screen

Full Screen

WebDriverFactory.java

Source:WebDriverFactory.java Github

copy

Full Screen

1/*2 * Copyright (c) 2021, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root6 * or https://opensource.org/licenses/MIT7 */8/*9 * @Copyright, 1999-2018, salesforce.com10 * All Rights Reserved11 * Company Confidential12 * Project LPOP13 */14package utam.core.selenium.factory;15import static utam.core.driver.DriverConfig.TEST_SIMULATOR_DRIVER_CONFIG;16import io.appium.java_client.AppiumDriver;17import io.appium.java_client.android.AndroidDriver;18import io.appium.java_client.ios.IOSDriver;19import io.appium.java_client.service.local.AppiumDriverLocalService;20import java.io.IOException;21import java.util.HashMap;22import java.util.Map;23import org.openqa.selenium.Platform;24import org.openqa.selenium.WebDriver;25import org.openqa.selenium.chrome.ChromeDriver;26import org.openqa.selenium.chrome.ChromeDriverService;27import org.openqa.selenium.chrome.ChromeOptions;28import org.openqa.selenium.firefox.FirefoxDriver;29import org.openqa.selenium.remote.DesiredCapabilities;30import utam.core.driver.Driver;31import utam.core.driver.DriverConfig;32import utam.core.driver.DriverType;33import utam.core.selenium.appium.MobileDriverAdapter;34import utam.core.selenium.element.DriverAdapter;35/**36 * web driver factory37 *38 * @author elizaveta.ivanova39 * @since 21640 */41public class WebDriverFactory {42 static final String ERR_UNKNOWN_DRIVER_TYPE = "Browser [%s] not supported";43 private static final String ERR_APPIUM_LOCAL_SERVER = "Need to start an Appium Server at local";44 private static boolean isLocalRun() {45 return !Boolean.TRUE.toString().equals(System.getProperty("Jenkins"));46 }47 /**48 * Creates a WebDriver instance49 *50 * @param browserType the browser type to create the instance51 * @return the created WebDriver instance52 */53 public static WebDriver getWebDriver(DriverType browserType) {54 return getWebDriver(browserType, null, null);55 }56 /**57 * creates a DriverAdapter58 *59 * @param webDriver the WebDriver instance to wrap60 * @param driverConfig the configuration object to configure the driver adapter61 * @return the driver adapter62 */63 public static Driver getAdapter(WebDriver webDriver, DriverConfig driverConfig) {64 return webDriver instanceof AppiumDriver ? new MobileDriverAdapter((AppiumDriver) webDriver, driverConfig)65 : new DriverAdapter(webDriver, driverConfig);66 }67 /**68 * creates DriverAdapter for testing purposes with very low explicit wait69 *70 * @param driver mock of WebDriver71 * @return instance of Driver72 */73 public static Driver getAdapterMock(WebDriver driver) {74 return getAdapter(driver, TEST_SIMULATOR_DRIVER_CONFIG);75 }76 /**77 * Creates a WebDriver instance78 * 79 * @param browserType the type of browser for which to create the WebDriver instance80 * @param service the service to create the driver81 * @param desiredCapabilities the desired capabilities of the resulting WebDriver instance82 * @return the created WebDriver instance83 */84 @SuppressWarnings("WeakerAccess")85 public static WebDriver getWebDriver(86 DriverType browserType,87 AppiumDriverLocalService service,88 AppiumCapabilityProvider desiredCapabilities) {89 WebDriver driver;90 if (DriverType.chrome.equals(browserType)) {91 driver = chrome();92 } else if (DriverType.firefox.equals(browserType)) {93 driver = firefox();94 } else if (DriverType.ios.equals(browserType)) {95 driver = ios(service, desiredCapabilities);96 } else if (DriverType.android.equals(browserType)) {97 driver = android(service, desiredCapabilities);98 } else {99 throw new IllegalArgumentException(String.format(ERR_UNKNOWN_DRIVER_TYPE, browserType));100 }101 return driver;102 }103 static ChromeOptions defaultChromeOptions(boolean isJenkinsRun) {104 Map<Object, Object> chromePrefs = new HashMap<>();105 chromePrefs.put("profile.default_content_setting_values.notifications", 2);106 ChromeOptions chromeOptions = new ChromeOptions();107 chromeOptions.addArguments("--use-fake-ui-for-media-stream");108 if (isJenkinsRun) {109 chromeOptions.addArguments("headless");110 chromeOptions.addArguments("no-sandbox");111 chromeOptions.addArguments("window-size=1200x600");112 }113 chromeOptions.setExperimentalOption("prefs", chromePrefs);114 return chromeOptions;115 }116 private static ChromeDriverService initializeChromeDriverService() throws IOException {117 ChromeDriverService.Builder serviceBuilder =118 new ChromeDriverService.Builder().usingAnyFreePort();119 ChromeDriverService chromeDriverService = serviceBuilder.build();120 chromeDriverService.start();121 return chromeDriverService;122 }123 private static WebDriver chrome() {124 SystemProperties.setChromeDriverPath();125 ChromeOptions chromeOptions = defaultChromeOptions(!isLocalRun());126 try {127 ChromeDriverService service = initializeChromeDriverService();128 return new ChromeDriver(service, chromeOptions);129 } catch (IOException e) {130 throw new RuntimeException(e);131 }132 }133 private static WebDriver firefox() {134 SystemProperties.setGeckoDriverPath();135 return new FirefoxDriver();136 }137 private static DesiredCapabilities iOSOptions() {138 SystemProperties.setIOSDeviceName();139 SystemProperties.setIOSAppPath();140 141 DesiredCapabilities caps = new DesiredCapabilities();142 caps.setPlatform(Platform.IOS);143 caps.setCapability(AppiumCustomCapabilityType.AUTOMATION_NAME, "XCUITest");144 caps.setCapability(AppiumCustomCapabilityType.NATIVE_WEB_TAP, true);145 caps.setCapability(AppiumCustomCapabilityType.DEVICE_NAME, SystemProperties.getIOSDeviceName());146 caps.setCapability(AppiumCustomCapabilityType.APP, SystemProperties.getIOSAppPath());147 return caps;148 }149 private static DesiredCapabilities androidOptions() {150 SystemProperties.setAppBundleID();151 SystemProperties.setAndroidAppPath();152 SystemProperties.setAppActivity();153 DesiredCapabilities caps = new DesiredCapabilities();154 caps.setPlatform(Platform.ANDROID);155 caps.setCapability(AppiumCustomCapabilityType.AUTOMATION_NAME, "UIAutomator2");156 caps.setCapability(AppiumCustomCapabilityType.APP_PACKAGE, SystemProperties.getAppBundleID());157 caps.setCapability(AppiumCustomCapabilityType.APP_ACTIVITY, SystemProperties.getAppActivity());158 caps.setCapability(AppiumCustomCapabilityType.APP, SystemProperties.getAndroidAppPath());159 return caps;160 }161 private static AppiumDriver ios(AppiumDriverLocalService service,162 AppiumCapabilityProvider desiredCapabilities) {163 if (service == null) {164 throw new NullPointerException(ERR_APPIUM_LOCAL_SERVER);165 }166 DesiredCapabilities caps = iOSOptions();167 caps.merge(desiredCapabilities.getDesiredCapabilities());168 return new IOSDriver(service, caps);169 }170 private static AppiumDriver android(AppiumDriverLocalService service,171 AppiumCapabilityProvider desiredCapabilities) {172 if (service == null) {173 throw new NullPointerException(ERR_APPIUM_LOCAL_SERVER);174 }175 DesiredCapabilities caps = androidOptions();176 caps.merge(desiredCapabilities.getDesiredCapabilities());177 return new AndroidDriver(service, caps);178 }179}...

Full Screen

Full Screen

AndroidOptionsTest.java

Source:AndroidOptionsTest.java Github

copy

Full Screen

...22import java.net.MalformedURLException;23import java.net.URL;24import java.time.Duration;25import static org.junit.Assert.assertEquals;26public class AndroidOptionsTest {27 private AndroidOptions androidOptions = new AndroidOptions();28 @Test29 public void setsPlatformNameByDefault() {30 assertEquals(MobilePlatform.ANDROID, androidOptions.getPlatformName());31 }32 @Test33 public void acceptsExistingCapabilities() {34 MutableCapabilities capabilities = new MutableCapabilities();35 capabilities.setCapability("deviceName", "Pixel");36 capabilities.setCapability("platformVersion", "10");37 capabilities.setCapability("newCommandTimeout", 60);38 androidOptions = new AndroidOptions(capabilities);39 assertEquals("Pixel", androidOptions.getDeviceName());40 assertEquals("10", androidOptions.getPlatformVersion());41 assertEquals(Duration.ofSeconds(60), androidOptions.getNewCommandTimeout());42 }43 @Test44 public void acceptsMobileCapabilities() throws MalformedURLException {45 androidOptions.setApp(new URL("http://example.com/myapp.apk"))46 .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)47 .setPlatformVersion("10")48 .setDeviceName("Pixel")49 .setOtherApps("/path/to/app.apk")50 .setLocale("fr_CA")51 .setUdid("1ae203187fc012g")52 .setOrientation(ScreenOrientation.LANDSCAPE)...

Full Screen

Full Screen

AbstractAndroidTest.java

Source:AbstractAndroidTest.java Github

copy

Full Screen

1package android.utils;2import io.appium.java_client.AppiumDriver;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.android.AndroidOptions;5import io.appium.java_client.android.AndroidStartScreenRecordingOptions;6import io.appium.java_client.remote.MobileCapabilityType;7import io.appium.java_client.screenrecording.ScreenRecordingUploadOptions;8import org.junit.jupiter.api.BeforeEach;9import org.openqa.selenium.Platform;10import org.openqa.selenium.WebElement;11import utils.AbstractMobileTest;12import utils.AbstractPage;13import java.io.IOException;14import java.lang.reflect.InvocationTargetException;15import java.nio.file.Files;16import java.nio.file.Paths;17import java.util.Base64;18import java.util.function.Consumer;19public abstract class AbstractAndroidTest<T extends AbstractPage<T>> extends AbstractMobileTest<AndroidDriver<?>>20{21 protected T page;22 public abstract Class<T> getPageClass();23 @Override24 public AndroidDriver<WebElement> getWebDriver()25 {26 var appPath = getAppPath();27 var capability = new AndroidOptions();28 capability.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID.getPartOfOsName()[0]);29 capability.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10");30 capability.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554"); // Pixel 4 API 2931 //capability.setCapability(MobileCapabilityType.DEVICE_NAME, "uoono7ovnf9ljnae");32 capability.setCapability(MobileCapabilityType.APP, appPath);33 capability.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");34 capability.setCapability("unicodeKeyboard", false);35 capability.setCapability("resetKeyboard", true);36 return new AndroidDriver<>(appiumServerUrl, capability);37 }38 @BeforeEach39 public void initDriver()40 {41 driver = getWebDriver();...

Full Screen

Full Screen

CustomWebDriverInterceptor.java

Source:CustomWebDriverInterceptor.java Github

copy

Full Screen

1package com.seleniumToolkit.selenium.setting;2import com.seleniumToolkit.selenium.framework.interceptor.driver.WebDriverInterceptor;3import io.appium.java_client.android.AndroidOptions;4import io.appium.java_client.ios.IOSOptions;5import org.openqa.selenium.chrome.ChromeOptions;6import org.openqa.selenium.edge.EdgeOptions;7import org.openqa.selenium.firefox.FirefoxOptions;8import org.openqa.selenium.ie.InternetExplorerOptions;9import org.openqa.selenium.opera.OperaOptions;10import org.openqa.selenium.safari.SafariOptions;11public class CustomWebDriverInterceptor implements com.seleniumToolkit.selenium.framework.interceptor.driver.WebDriverInterceptor {12 @Override13 public ChromeOptions chromeInterceptor(ChromeOptions chromeOptions, boolean localExecution) {14 return chromeOptions;15 }16 @Override17 public FirefoxOptions firefoxInterceptor(FirefoxOptions firefoxOptions, boolean localExecution) {18 return firefoxOptions;19 }20 @Override21 public InternetExplorerOptions internetExplorerInterceptor(InternetExplorerOptions internetExplorerOptions, boolean localExecution) {22 return internetExplorerOptions;23 }24 @Override25 public EdgeOptions edgeInterceptor(EdgeOptions edgeOptions, boolean localExecution) {26 return edgeOptions;27 }28 @Override29 public OperaOptions operaInterceptor(OperaOptions operaOptions, boolean localExecution) {30 return operaOptions;31 }32 @Override33 public SafariOptions safariInterceptor(SafariOptions safariOptions, boolean localExecution) {34 return safariOptions;35 }36 @Override37 public AndroidOptions androidInterceptor(AndroidOptions androidOptions, boolean localExecution) {38 return androidOptions;39 }40 @Override41 public IOSOptions iosInterceptor(IOSOptions iOSOptions, boolean localExecution) {42 return iOSOptions;43 }44}...

Full Screen

Full Screen

AndroidOptions.java

Source:AndroidOptions.java Github

copy

Full Screen

...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

AndroidAppUser.java

Source:AndroidAppUser.java Github

copy

Full Screen

2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.WebElement;5import io.appium.java_client.AppiumDriver;6import io.appium.java_client.android.AndroidOptions;7import io.appium.java_client.remote.MobilePlatform;8public class AndroidAppUser extends BrowserUser {9 public AndroidAppUser(String userName, int timeOfWaitInSeconds, String appPath) {10 super(userName, timeOfWaitInSeconds);11 AndroidOptions options = new AndroidOptions();12 options.setAutomationName("UiAutomator2");13 options.setPlatformVersion("12.0");14 options.setPlatformName(MobilePlatform.ANDROID);15 options.setAutomationName("UiAutomator2");16 options.setDeviceName("Android device");17 options.setAutoWebview(true);18 options.setApp(appPath);19 URL url = null;20 try {21 url = new URL("http://172.17.0.1:4723/wd/hub");22 } catch (MalformedURLException e) {23 e.printStackTrace();24 }25 this.driver = new AppiumDriver<WebElement>(url, options);...

Full Screen

Full Screen

AndroidOptions

Using AI Code Generation

copy

Full Screen

1AndroidOptions androidOptions = new AndroidOptions();2androidOptions.setCapability("platformName", "Android");3androidOptions.setCapability("deviceName", "Android Emulator");4androidOptions.setCapability("automationName", "UiAutomator2");5androidOptions.setCapability("app", "path/to/your.apk");6androidOptions.setCapability("appPackage", "com.example.android.contactmanager");7androidOptions.setCapability("appActivity", ".ContactManager");8androidOptions.setCapability("noReset", "true");

Full Screen

Full Screen

AndroidOptions

Using AI Code Generation

copy

Full Screen

1AndroidOptions options = new AndroidOptions();2options.setCapability("deviceName", "emulator-5554");3options.setCapability("platformName", "Android");4options.setCapability("appPackage", "com.android.calculator2");5options.setCapability("appActivity", "com.android.calculator2.Calculator");6options.setCapability("noReset", true);7options.setCapability("automationName", "UiAutomator2");

Full Screen

Full Screen

AndroidOptions

Using AI Code Generation

copy

Full Screen

1AndroidOptions options = new AndroidOptions();2options.setCapability("deviceName", "Android Emulator");3options.setCapability("platformName", "Android");4options.setCapability("platformVersion", "9.0");5options.setCapability("automationName", "UiAutomator2");6options.setCapability("appPackage", "com.android.calculator2");7options.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

AndroidOptions

Using AI Code Generation

copy

Full Screen

1AndroidOptions androidOptions = new AndroidOptions();2androidOptions.setCapability("deviceName", "Android Emulator");3androidOptions.setCapability("platformName", "Android");4androidOptions.setCapability("app", "C:/Users/abc/Desktop/ApiDemos-debug.apk");5androidOptions.setCapability("appPackage", "io.appium.android.apis");6androidOptions.setCapability("appActivity", "io.appium.android.apis.ApiDemos");7androidOptions.setCapability("noReset", "true");8androidOptions.setCapability("fullReset", "false");9androidOptions.setCapability("automationName", "UiAutomator2");10androidOptions.setCapability("autoGrantPermissions", "true");11androidOptions.setCapability("dontStopAppOnReset", "true");

Full Screen

Full Screen

AndroidOptions

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.android.AndroidOptions;2import io.appium.java_client.remote.MobileCapabilityType;3AndroidOptions options = new AndroidOptions();4options.setCapability("deviceName", "Android Emulator");5options.setCapability("platformName", "Android");6options.setCapability("platformVersion", "7.1.1");7options.setCapability("appPackage", "com.android.calculator2");8options.setCapability("appActivity", "com.android.calculator2.Calculator");9import io.appium.java_client.AppiumDriver;

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.

Run io.appium automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful