How to use IOSOptions class of io.appium.java_client.ios package

Best io.appium code snippet using io.appium.java_client.ios.IOSOptions

DriverParameterResolverExtension.java

Source:DriverParameterResolverExtension.java Github

copy

Full Screen

1package at.willhaben.willtest.junit5.extensions;2import at.willhaben.willtest.browserstack.BrowserstackEnvironment;3import at.willhaben.willtest.browserstack.exception.BrowserstackEnvironmentException;4import at.willhaben.willtest.junit5.*;5import at.willhaben.willtest.proxy.BrowserProxyBuilder;6import at.willhaben.willtest.proxy.ProxyOptionModifier;7import at.willhaben.willtest.proxy.ProxyWrapper;8import at.willhaben.willtest.proxy.impl.ProxyWrapperImpl;9import at.willhaben.willtest.util.*;10import io.appium.java_client.AppiumDriver;11import io.appium.java_client.android.AndroidDriver;12import io.appium.java_client.ios.IOSDriver;13import net.lightbody.bmp.BrowserMobProxy;14import org.junit.jupiter.api.extension.*;15import org.junit.jupiter.api.extension.ExtensionContext.Store;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.chrome.ChromeDriver;18import org.openqa.selenium.chrome.ChromeOptions;19import org.openqa.selenium.edge.EdgeDriver;20import org.openqa.selenium.edge.EdgeOptions;21import org.openqa.selenium.firefox.FirefoxDriver;22import org.openqa.selenium.firefox.FirefoxOptions;23import org.openqa.selenium.ie.InternetExplorerDriver;24import org.openqa.selenium.ie.InternetExplorerOptions;25import org.openqa.selenium.remote.LocalFileDetector;26import org.openqa.selenium.remote.RemoteWebDriver;27import org.slf4j.Logger;28import org.slf4j.LoggerFactory;29import java.lang.reflect.Method;30import java.net.MalformedURLException;31import java.net.URL;32import java.util.ArrayList;33import java.util.Arrays;34import java.util.List;35import java.util.Optional;36import static at.willhaben.willtest.util.AnnotationHelper.getBrowserUtilExtensionList;37import static at.willhaben.willtest.util.ExceptionChecker.isAssumptionViolation;38import static at.willhaben.willtest.util.RemoteSelectionUtils.RemotePlatform.BROWSERSTACK;39import static at.willhaben.willtest.util.RemoteSelectionUtils.getRemotePlatform;40import static at.willhaben.willtest.util.RemoteSelectionUtils.isRemote;41public class DriverParameterResolverExtension implements ParameterResolver, BeforeEachCallback,42 AfterEachCallback, AfterAllCallback, TestExecutionExceptionHandler, LifecycleMethodExecutionExceptionHandler {43 public static final String DRIVER_KEY = "wh-webDriver";44 private static final String BEFOREALL_DRIVER_KEY = "wh-beforeall-webDriver";45 private static final String PROXY_KEY = "wh-proxy";46 private static final Logger LOGGER = LoggerFactory.getLogger(DriverParameterResolverExtension.class);47 @Override48 public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {49 Class<?> parameterType = parameterContext.getParameter().getType();50 return parameterType.isAssignableFrom(WebDriver.class) ||51 parameterType.isAssignableFrom(ProxyWrapper.class);52 }53 @Override54 public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {55 Class<?> parameterType = parameterContext.getParameter().getType();56 Optional<WebDriver> driverCreatedInBeforeEach = getDriverFromStore(extensionContext, DRIVER_KEY);57 Optional<ProxyWrapper> proxyCreatedInBeforeEach = getProxyFromStore(extensionContext);58 if (parameterType.isAssignableFrom(WebDriver.class) && driverCreatedInBeforeEach.isPresent()) {59 return driverCreatedInBeforeEach.get();60 } else if (parameterType.isAssignableFrom(ProxyWrapper.class) && proxyCreatedInBeforeEach.isPresent()) {61 return proxyCreatedInBeforeEach.get();62 } else if (parameterType.isAssignableFrom(WebDriver.class)) {63 List<OptionModifier> modifiers = new ArrayList<>();64 if (shouldStartProxy(extensionContext)) {65 BrowserMobProxy proxy = BrowserProxyBuilder.builder()66 .startProxy();67 modifiers.add(new ProxyOptionModifier(proxy));68 getStore(extensionContext).put(PROXY_KEY, new ProxyWrapperImpl(proxy));69 }70 List<WebDriverPostInterceptor> driverPostInterceptorList = getBrowserPostProcess(extensionContext);71 modifiers.addAll(getBrowserOptionModifiers(extensionContext));72 WebDriver driver = createDriver(modifiers, driverPostInterceptorList, getTestName(extensionContext));73 if (extensionContext.getTestMethod().isPresent()) {74 getStore(extensionContext).put(DRIVER_KEY, driver);75 } else {76 getStore(extensionContext).put(BEFOREALL_DRIVER_KEY, driver);77 }78 return driver;79 } else if (parameterType.isAssignableFrom(ProxyWrapper.class) && getProxyFromStore(extensionContext).isPresent()) {80 return getProxyFromStore(extensionContext).get();81 } else {82 return null;83 }84 }85 @Override86 public void beforeEach(ExtensionContext context) throws Exception {87 Optional<WebDriver> driver = getDriverFromStore(context, DRIVER_KEY);88 for (TestStartListener testStartListener : getBrowserUtils(context, TestStartListener.class)) {89 try {90 testStartListener.testStarted(context, getTestName(context));91 } catch (Exception e) {92 LOGGER.error("Test start listener couldn't be started", e);93 throw e;94 }95 }96 }97 @Override98 public void afterEach(ExtensionContext extensionContext) throws Exception {99 closeDriver(extensionContext, DRIVER_KEY);100 getProxyFromStore(extensionContext).ifPresent(proxyUtil -> proxyUtil.getProxy().abort());101 }102 private void closeDriver(ExtensionContext extensionContext, String driverKey) {103 getDriverFromStore(extensionContext, driverKey).ifPresent(WebDriver::quit);104 }105 @Override106 public void afterAll(ExtensionContext context) throws Exception {107 closeDriver(context, BEFOREALL_DRIVER_KEY);108 }109 @Override110 public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable {111 if (isAssumptionViolation(throwable)) {112 throw throwable;113 }114 handleValidTestFailures(context, throwable);115 throw throwable;116 }117 @Override118 public void handleAfterEachMethodExecutionException(ExtensionContext context, Throwable throwable) throws Throwable {119 if (ExceptionChecker.isAssertJMultipleFailureError(throwable)) {120 handleValidTestFailures(context, throwable);121 }122 throw throwable;123 }124 private void handleValidTestFailures(ExtensionContext context, Throwable throwable) throws Throwable {125 Optional<WebDriver> driver = getDriverFromStore(context, DRIVER_KEY);126 if (driver.isPresent()) {127 for (TestFailureListener testFailureListener : getFailureListeners(context)) {128 try {129 testFailureListener.onFailure(context, driver.get(), throwable);130 } catch (Exception e) {131 throwable.addSuppressed(e);132 }133 }134 }135 }136 public boolean shouldStartProxy(ExtensionContext context) {137 Optional<Method> testMethod = context.getTestMethod();138 if (testMethod.isPresent()) {139 return Arrays.asList(testMethod.get().getParameterTypes()).contains(ProxyWrapper.class);140 } else {141 LOGGER.debug("The test method is not present. No proxy can be started.");142 return false;143 }144 }145 public static Store getStore(ExtensionContext context) {146 return context.getStore(ExtensionContext.Namespace.create(DriverParameterResolverExtension.class));147 }148 public static Optional<WebDriver> getDriverFromStore(ExtensionContext context, String driverKey) {149 return Optional.ofNullable(getStore(context).get(driverKey, WebDriver.class));150 }151 public static Optional<ProxyWrapper> getProxyFromStore(ExtensionContext context) {152 return Optional.ofNullable(getStore(context).get(PROXY_KEY, ProxyWrapper.class));153 }154 private String getTestName(ExtensionContext context) {155 return context.getRequiredTestClass().getSimpleName() + "_" + context.getRequiredTestMethod().getName();156 }157 private WebDriver createDriver(List<OptionModifier> modifiers, List<WebDriverPostInterceptor> driverPostInterceptorList, String testName) {158 String seleniumHub = System.getProperty("seleniumHub");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);194 androidOptions = browserstackEnv.addToCapabilities(androidOptions, testName);195 iOsOptions = browserstackEnv.addToCapabilities(iOsOptions, testName);196 }197 }198 //adding a container name for moon-ui199 firefoxOptions.setCapability("name", testName);200 chromeOptions.setCapability("name", testName);201 edgeOptions.setCapability("name", testName);202 internetExplorerOptions.setCapability("name", testName);203 androidOptions.setCapability("name", testName);204 iOsOptions.setCapability("name", testName);205 WebDriver driver;206 if (PlatformUtils.isAndroid()) {207 if (isRemote()) {208 URL seleniumHubUrl = convertSeleniumHubToURL(seleniumHub);209 driver = new AndroidDriver<>(seleniumHubUrl, androidOptions);210 } else {211 driver = new AndroidDriver<>(androidOptions);212 }213 } else if (PlatformUtils.isIOS()) {214 if (isRemote()) {215 URL seleniumHubUrl = convertSeleniumHubToURL(seleniumHub);216 driver = new IOSDriver<>(seleniumHubUrl, iOsOptions);217 } else {218 driver = new IOSDriver<>(iOsOptions);219 }220 ((AppiumDriver) driver).context("NATIVE_APP");221 } else if (PlatformUtils.isLinux() || PlatformUtils.isWindows()) {222 if (isRemote()) {223 URL seleniumHubUrl = convertSeleniumHubToURL(seleniumHub);224 RemoteWebDriver remoteDriver;225 if (BrowserSelectionUtils.isFirefox()) {226 remoteDriver = new RemoteWebDriver(seleniumHubUrl, firefoxOptions);227 } else if (BrowserSelectionUtils.isChrome()) {228 remoteDriver = new RemoteWebDriver(seleniumHubUrl, chromeOptions);229 } else if (BrowserSelectionUtils.isIE()) {230 remoteDriver = new RemoteWebDriver(seleniumHubUrl, internetExplorerOptions);231 } else if (BrowserSelectionUtils.isEdge()) {232 remoteDriver = new RemoteWebDriver(seleniumHubUrl, edgeOptions);233 } else {234 throw new RuntimeException("The specified browser '" + BrowserSelectionUtils.getBrowser() + "' is not supported");235 }236 remoteDriver.setFileDetector(new LocalFileDetector());237 driver = remoteDriver;238 } else {239 if (BrowserSelectionUtils.isFirefox()) {240 driver = new FirefoxDriver(firefoxOptions);241 } else if (BrowserSelectionUtils.isChrome()) {242 driver = new ChromeDriver(chromeOptions);243 } else if (BrowserSelectionUtils.isIE()) {244 driver = new InternetExplorerDriver(internetExplorerOptions);245 } else if (BrowserSelectionUtils.isEdge()) {246 driver = new EdgeDriver(edgeOptions);247 } else {248 throw new RuntimeException("The specified browser '" + BrowserSelectionUtils.getBrowser() + "' is not supported");249 }250 }251 } else {252 throw new RuntimeException("The specified platform '" + PlatformUtils.getPlatform() + "' is not supported.");253 }254 driverPostInterceptorList.forEach(postProcessor -> postProcessor.postProcessWebDriver(driver));255 return driver;256 }257 private URL convertSeleniumHubToURL(String seleniumHub) {258 try {259 return new URL(seleniumHub);260 } catch (MalformedURLException e) {261 throw new RuntimeException("Malformed url created", e);262 }263 }264 private List<OptionModifier> getBrowserOptionModifiers(ExtensionContext context) {265 return getBrowserUtilExtensionList(context, OptionModifier.class, false);266 }267 private List<WebDriverPostInterceptor> getBrowserPostProcess(ExtensionContext context) {268 return getBrowserUtilExtensionList(context, WebDriverPostInterceptor.class, true);269 }270 private List<TestFailureListener> getFailureListeners(ExtensionContext context) {271 return getBrowserUtilExtensionList(context, TestFailureListener.class, true);272 }273 private <T extends BrowserUtilExtension> List<T> getBrowserUtils(ExtensionContext context, Class<T> type) {274 return getBrowserUtilExtensionList(context, type, true);275 }276}...

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

IosDevice.java

Source:IosDevice.java Github

copy

Full Screen

1package com.daxiang.core.mobile.ios;2import com.daxiang.App;3import com.daxiang.core.PortProvider;4import com.daxiang.core.mobile.MobileDevice;5import com.daxiang.core.mobile.appium.AppiumNativePageSourceHandler;6import com.daxiang.core.mobile.appium.AppiumServer;7import com.daxiang.core.mobile.appium.IosNativePageSourceHandler;8import com.daxiang.core.mobile.Mobile;9import com.daxiang.model.page.Page;10import com.daxiang.utils.UUIDUtil;11import io.appium.java_client.ios.IOSDriver;12import io.appium.java_client.ios.IOSStartScreenRecordingOptions;13import io.appium.java_client.remote.AutomationName;14import io.appium.java_client.remote.IOSMobileCapabilityType;15import io.appium.java_client.remote.MobileCapabilityType;16import io.appium.java_client.remote.MobilePlatform;17import lombok.extern.slf4j.Slf4j;18import org.apache.commons.exec.ShutdownHookProcessDestroyer;19import org.apache.commons.io.FileUtils;20import org.openqa.selenium.Capabilities;21import org.openqa.selenium.remote.DesiredCapabilities;22import org.openqa.selenium.remote.RemoteWebDriver;23import org.springframework.util.StringUtils;24import java.io.File;25import java.io.IOException;26import java.time.Duration;27import java.util.Base64;28/**29 * Created by jiangyitao.30 */31@Slf4j32public class IosDevice extends MobileDevice {33 public static final int PLATFORM = 2;34 private ShutdownHookProcessDestroyer mjpegServerIproxyProcessDestroyer;35 public IosDevice(Mobile mobile, AppiumServer appiumServer) {36 super(mobile, appiumServer);37 }38 @Override39 public RemoteWebDriver newDriver() {40 return new IOSDriver(deviceServer.getUrl(), caps);41 }42 @Override43 protected Capabilities newCaps(Capabilities capsToMerge) {44 DesiredCapabilities capabilities = new DesiredCapabilities();45 capabilities.setCapability(MobileCapabilityType.NO_RESET, true);46 capabilities.setCapability("waitForQuiescence", false);47 capabilities.setCapability("useJSONSource", true); // Get JSON source from WDA and parse into XML on Appium server. This can be much faster, especially on large devices.48 // https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md49 String xcodeOrgId = App.getProperty("xcodeOrgId");50 if (!StringUtils.isEmpty(xcodeOrgId)) {51 capabilities.setCapability("xcodeOrgId", xcodeOrgId);52 }53 String xcodeSigningId = App.getProperty("xcodeSigningId");54 if (!StringUtils.isEmpty(xcodeSigningId)) {55 capabilities.setCapability("xcodeSigningId", xcodeSigningId);56 }57 String updatedWDABundleId = App.getProperty("updatedWDABundleId");58 if (!StringUtils.isEmpty(updatedWDABundleId)) {59 capabilities.setCapability("updatedWDABundleId", updatedWDABundleId);60 }61 // **** 以上capabilities可被传入的caps覆盖 ****62 capabilities.merge(capsToMerge);63 // **** 以下capabilities具有更高优先级,将覆盖传入的caps ****64 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);65 capabilities.setCapability(IOSMobileCapabilityType.WDA_LOCAL_PORT, PortProvider.getWdaLocalAvailablePort());66 capabilities.setCapability("mjpegServerPort", PortProvider.getWdaMjpegServerAvailablePort());67 capabilities.setCapability("webkitDebugProxyPort", PortProvider.getWebkitDebugProxyAvalilablePort());68 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, mobile.getName());69 capabilities.setCapability(MobileCapabilityType.UDID, getId());70 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);71 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, mobile.getSystemVersion());72 capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, NEW_COMMAND_TIMEOUT);73 return capabilities;74 }75 @Override76 public void installApp(String app) {77 IosUtil.installApp(driver, app);78 }79 @Override80 public int getNativePageType() {81 return Page.TYPE_IOS_NATIVE;82 }83 @Override84 public AppiumNativePageSourceHandler newAppiumNativePageSourceHandler() {85 return new IosNativePageSourceHandler();86 }87 @Override88 public String getLogType() {89 return "syslog";90 }91 @Override92 public void uninstallApp(String app) {93 IosUtil.uninstallApp(driver, app);94 }95 @Override96 public void startRecordingScreen() {97 IOSStartScreenRecordingOptions iosOptions = new IOSStartScreenRecordingOptions();98 // The maximum value is 30 minutes.99 iosOptions.withTimeLimit(Duration.ofMinutes(30));100 iosOptions.withFps(10); // default 10101 iosOptions.withVideoQuality(IOSStartScreenRecordingOptions.VideoQuality.LOW);102 iosOptions.withVideoType("libx264");103 ((IOSDriver) driver).startRecordingScreen(iosOptions);104 }105 @Override106 public File stopRecordingScreen() throws IOException {107 File videoFile = new File(UUIDUtil.getUUID() + ".mp4");108 String base64Video = ((IOSDriver) driver).stopRecordingScreen();109 FileUtils.writeByteArrayToFile(videoFile, Base64.getDecoder().decode(base64Video), false);110 return videoFile;111 }112 public long getMjpegServerPort() {113 return (long) driver.getCapabilities().asMap().get("mjpegServerPort");114 }115 public long startMjpegServerIproxy() throws IOException {116 long mjpegServerPort = getMjpegServerPort();117 log.info("[{}]startMjpegServerIproxy", getId());118 mjpegServerIproxyProcessDestroyer = IosUtil.iproxy(mjpegServerPort, mjpegServerPort, getId());119 return mjpegServerPort;120 }121 public void stopMjpegServerIproxy() {122 if (mjpegServerIproxyProcessDestroyer != null) {123 log.info("[{}]stopMjpegServerIproxy", getId());124 mjpegServerIproxyProcessDestroyer.run();125 }126 }127}...

Full Screen

Full Screen

BaseTest.java

Source:BaseTest.java Github

copy

Full Screen

...3import io.appium.java_client.MobileBy;4import io.appium.java_client.MobileElement;5import io.appium.java_client.android.AndroidDriver;6import io.appium.java_client.ios.IOSDriver;7import io.appium.java_client.ios.IOSOptions;8import io.appium.java_client.remote.AndroidMobileCapabilityType;9import io.appium.java_client.remote.AutomationName;10import io.appium.java_client.remote.IOSMobileCapabilityType;11import io.appium.java_client.remote.MobileCapabilityType;12import io.appium.java_client.service.local.AppiumDriverLocalService;13import io.appium.java_client.service.local.AppiumServiceBuilder;14import io.appium.java_client.service.local.flags.GeneralServerFlag;15import org.openqa.selenium.remote.DesiredCapabilities;16import org.openqa.selenium.support.ui.ExpectedConditions;17import org.openqa.selenium.support.ui.WebDriverWait;18import org.testng.annotations.AfterClass;19import org.testng.annotations.BeforeClass;20import java.io.IOException;21import java.net.ServerSocket;22import java.time.Duration;23public class BaseTest {24 private AppiumDriverLocalService service;25 public AppiumDriver<MobileElement> driver;26 public WebDriverWait wait;27 @BeforeClass28 public void beforeClass() throws Exception {29 service = AppiumDriverLocalService.buildService(30 new AppiumServiceBuilder().usingAnyFreePort().withArgument(GeneralServerFlag.BASEPATH, "/wd/hub")31 .withArgument(GeneralServerFlag.RELAXED_SECURITY));32 service.start();33 if (service == null || !service.isRunning()) {34 throw new RuntimeException("An appium server node is not started!");35 }36 androidCaps();37 //iosCaps();38 }39 @AfterClass40 public void afterClass() {41 if (driver != null) {42 driver.quit();43 }44 if (service != null) {45 service.stop();46 }47 }48 private void androidCaps() throws IOException {49 DesiredCapabilities capabilities = new DesiredCapabilities();50 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");51 capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 900000);52 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);53 capabilities.setCapability(AndroidMobileCapabilityType.SYSTEM_PORT, new ServerSocket(0).getLocalPort());54 capabilities.setCapability(MobileCapabilityType.APP, System.getProperty("user.dir") + "/apps/VodQA.apk");55 driver = new AndroidDriver<>(service.getUrl(), capabilities);56 wait = new WebDriverWait(driver, 30);57 }58 private void iosCaps() throws IOException {59 /* DesiredCapabilities capabilities = new DesiredCapabilities();60 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "13.3");61 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 11");62 capabilities.setCapability(IOSMobileCapabilityType.WDA_LOCAL_PORT, new ServerSocket(0).getLocalPort());63 //sometimes environment has performance problems64 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);65 capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 700000);66 capabilities.setCapability(MobileCapabilityType.APP, System.getProperty("user.dir") + "/apps/vodqa.zip");67 */68 IOSOptions iosOptions = new IOSOptions();69 iosOptions.setApp(System.getProperty("user.dir") + "/apps/vodqa.zip")70 .setAutomationName(AutomationName.IOS_XCUI_TEST)71 .setDeviceName("iPhone 11")72 .setNewCommandTimeout(Duration.ofSeconds(60))73 .setPlatformVersion("13.3")74 .setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 700000);75 driver = new IOSDriver<>(service.getUrl(), iosOptions);76 wait = new WebDriverWait(driver, 30);77 }78 public void login() {79 System.out.print( "My SessionId: "+driver.getSessionId());80 wait.until(ExpectedConditions.81 elementToBeClickable(MobileBy.AccessibilityId("login"))).click();82 }...

Full Screen

Full Screen

IOSOptionsTest.java

Source:IOSOptionsTest.java Github

copy

Full Screen

...23import java.net.MalformedURLException;24import java.net.URL;25import java.time.Duration;26import static org.junit.Assert.assertEquals;27public class IOSOptionsTest {28 private IOSOptions iosOptions = new IOSOptions();29 @Test30 public void setsPlatformNameByDefault() {31 assertEquals(Platform.IOS, iosOptions.getPlatformName());32 }33 @Test34 public void acceptsExistingCapabilities() {35 MutableCapabilities capabilities = new MutableCapabilities();36 capabilities.setCapability("deviceName", "Pixel");37 capabilities.setCapability("platformVersion", "10");38 capabilities.setCapability("newCommandTimeout", 60);39 iosOptions = new IOSOptions(capabilities);40 assertEquals("Pixel", iosOptions.getDeviceName());41 assertEquals("10", iosOptions.getPlatformVersion());42 assertEquals(Duration.ofSeconds(60), iosOptions.getNewCommandTimeout());43 }44 @Test45 public void acceptsMobileCapabilities() throws MalformedURLException {46 iosOptions.setApp(new URL("http://example.com/myapp.apk"))47 .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)48 .setPlatformVersion("10")49 .setDeviceName("Pixel")50 .setOtherApps("/path/to/app.apk")51 .setLocale("fr_CA")52 .setUdid("1ae203187fc012g")53 .setOrientation(ScreenOrientation.LANDSCAPE)...

Full Screen

Full Screen

AbstractIosTest.java

Source:AbstractIosTest.java Github

copy

Full Screen

1package ios.utils;2import io.appium.java_client.AppiumDriver;3import io.appium.java_client.ios.IOSDriver;4import io.appium.java_client.ios.IOSOptions;5import io.appium.java_client.remote.MobileCapabilityType;6import org.junit.jupiter.api.BeforeEach;7import org.openqa.selenium.Platform;8import org.openqa.selenium.WebElement;9import utils.AbstractMobileTest;10import utils.AbstractPage;11import java.lang.reflect.InvocationTargetException;12public abstract class AbstractIosTest<T extends AbstractPage<T>> extends AbstractMobileTest<IOSDriver<?>>13{14 protected T page;15 public abstract Class<T> getPageClass();16 @Override17 public IOSDriver<WebElement> getWebDriver()18 {19// var appPath = Paths.get("./apps/ApiDemos-debug.apk").toAbsolutePath().toString();20 var capability = new IOSOptions();21// capability.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");22// capability.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10");23// capability.setCapability(MobileCapabilityType.DEVICE_NAME, "uoono7ovnf9ljnae");24// capability.setCapability(MobileCapabilityType.APP, appPath);25// capability.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");26 return new IOSDriver<>(appiumServerUrl, capability);27 }28 @BeforeEach29 public void initDriver()30 {31 var appPath = getAppPath();32 var capability = new IOSOptions();33 capability.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.IOS.getPartOfOsName()[0]);34 capability.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10");35 capability.setCapability(MobileCapabilityType.DEVICE_NAME, "uoono7ovnf9ljnae");36 capability.setCapability(MobileCapabilityType.APP, appPath);37 capability.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");38 driver = new IOSDriver<>(appiumServerUrl, capability);39 try40 {41 page = getPageClass().getConstructor(AppiumDriver.class).newInstance(driver);42 }43 catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e)44 {45 e.printStackTrace();46 }...

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

IOSOptions.java

Source:IOSOptions.java Github

copy

Full Screen

...21 * Use the specific options class for your driver,22 * for example XCUITestOptions.23 */24@Deprecated25public class IOSOptions extends MobileOptions<IOSOptions> {26 public IOSOptions() {27 setIOSPlatformName();28 }29 public IOSOptions(Capabilities source) {30 super(source);31 setIOSPlatformName();32 }33 private void setIOSPlatformName() {34 setPlatformName(MobilePlatform.IOS);35 }36}...

Full Screen

Full Screen

IOSOptions

Using AI Code Generation

copy

Full Screen

1IOSOptions options = new IOSOptions();2options.setCapability("platformName", "iOS");3options.setCapability("platformVersion", "10.3");4options.setCapability("deviceName", "iPhone 7");5options.setCapability("app", "/Users/username/Documents/iosapp.app");6options.setCapability("automationName", "XCUITest");7options.setCapability("browserName", "Safari");8options.setCapability("udid", "00008020-000C2F0A2E40002E");9options.setCapability("bundleId", "com.apple.mobilesafari");

Full Screen

Full Screen

IOSOptions

Using AI Code Generation

copy

Full Screen

1IOSOptions options = new IOSOptions();2options.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");3options.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone X");4options.setCapability(MobileCapabilityType.PLATFORM_VERSION, "12.2");5options.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");6options.setCapability(MobileCapabilityType.APP, "/path/to/ios/app");7IOSXCUITestOptions options = new IOSXCUITestOptions();8options.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");9options.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone X");10options.setCapability(MobileCapabilityType.PLATFORM_VERSION, "12.2");11options.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");12options.setCapability(MobileCapabilityType.APP, "/path/to/ios/app");

Full Screen

Full Screen

IOSOptions

Using AI Code Generation

copy

Full Screen

1IOSOptions options = new IOSOptions();2options.setCapability("platformName", "iOS");3options.setCapability("platformVersion", "13.2");4options.setCapability("deviceName", "iPhone 11");5options.setCapability("automationName", "XCUITest");6options.setCapability("bundleId", "com.example.apple-samplecode.UICatalog");7options.setCapability("noReset", true);

Full Screen

Full Screen

IOSOptions

Using AI Code Generation

copy

Full Screen

1IOSOptions options = new IOSOptions();2options.setCapability("deviceName", "iPhone 6");3options.setCapability("platformVersion", "10.3");4options.setCapability("platformName", "iOS");5options.setCapability("app", "/path/to/MyiOS.app");6options.setCapability("automationName", "XCUITest");7options.setCapability("showXcodeLog", true);8options.setCapability("useNewWDA", true);9options.setCapability("usePrebuiltWDA", true);10options.setCapability("wdaLocalPort", 8101);11AndroidOptions options = new AndroidOptions();12options.setCapability("deviceName", "Android Emulator");13options.setCapability("platformVersion", "7.1");14options.setCapability("platformName", "Android");15options.setCapability("app", "/path/to/MyAndroid.apk");16options.setCapability("automationName", "UiAutomator2");17AppiumOptions options = new AppiumOptions();18options.setCapability("deviceName", "Android Emulator");19options.setCapability("platformVersion", "7.1");20options.setCapability("platformName", "Android");21options.setCapability("app", "/path/to/MyAndroid.apk");22options.setCapability("automationName", "UiAutomator2");23AppiumOptions options = new AppiumOptions();24options.setCapability("deviceName", "iPhone 6");25options.setCapability("platformVersion", "10.3");26options.setCapability("platformName", "iOS");27options.setCapability("app", "/path/to/MyiOS.app");28options.setCapability("automationName", "XCUITest");29options.setCapability("showXcodeLog", true);30options.setCapability("useNewWDA", true);31options.setCapability("usePrebuiltWDA", true);32options.setCapability("wdaLocalPort", 8101);

Full Screen

Full Screen

IOSOptions

Using AI Code Generation

copy

Full Screen

1package appium.java;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.testng.annotations.Test;4import io.appium.java_client.ios.IOSDriver;5import io.appium.java_client.ios.IOSElement;6public class IOSOptions {7 public void IOSOptions() throws Exception {8 DesiredCapabilities caps = new DesiredCapabilities();9 caps.setCapability("platformName", "iOS");10 caps.setCapability("platformVersion", "12.1");11 caps.setCapability("deviceName", "iPhone 8");12 caps.setCapability("automationName", "XCUITest");13 caps.setCapability("app", "/Users/Shared/Jenkins/Home/workspace/MyApp.app");14 IOSDriver<IOSElement> driver = new IOSDriver<IOSElement>(caps);15 Thread.sleep(5000);16 driver.quit();17 }18}19package appium.java;20import org.openqa.selenium.remote.DesiredCapabilities;21import org.testng.annotations.Test;22import io.appium.java_client.ios.IOSDriver;23import io.appium.java_client.ios.IOSElement;24public class IOSOptions {25 public void IOSOptions() throws Exception {26 DesiredCapabilities caps = new DesiredCapabilities();27 caps.setCapability("platformName", "iOS");28 caps.setCapability("platformVersion", "12.1");29 caps.setCapability("deviceName", "iPhone 8");30 caps.setCapability("automationName", "XCUITest");31 caps.setCapability("app", "/Users/Shared/Jenkins/Home/workspace/MyApp.app");32 IOSDriver<IOSElement> driver = new IOSDriver<IOSElement>(caps);33 Thread.sleep(5000);34 driver.quit();35 }36}37package appium.java;38import org.openqa.selenium.remote.DesiredCapabilities;39import org

Full Screen

Full Screen

IOSOptions

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.ios.IOSOptions;2import io.appium.java_client.remote.IOSMobileCapabilityType;3public class Appium {4 public static void main(String[] args) {5 IOSOptions options = new IOSOptions();6 options.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.example.apple-samplecode.UICatalog");7 }8}9import io.appium.java_client.remote.IOSOptions;10import io.appium.java_client.remote.IOSMobileCapabilityType;11public class Appium {12 public static void main(String[] args) {13 IOSOptions options = new IOSOptions();14 options.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.example.apple-samplecode.UICatalog");15 }16}17import io.appium.java_client.remote.IOSOptions;18public class Appium {19 public static void main(String[] args) {20 IOSOptions options = new IOSOptions();21 options.setCapability("bundleId", "com.example.apple-samplecode.UICatalog");22 }23}24import io.appium.java_client.remote.IOSOptions;25public class Appium {26 public static void main(String[] args) {27 IOSOptions options = new IOSOptions();28 options.setCapability("bundleId", "com.example.apple-samplecode.UICatalog");29 }30}31import io.appium.java_client.remote.IOSOptions;32public class Appium {33 public static void main(String[] args) {34 IOSOptions options = new IOSOptions();35 options.setCapability("bundleId", "com.example.apple-samplecode.UICatalog");36 }37}

Full Screen

Full Screen

IOSOptions

Using AI Code Generation

copy

Full Screen

1IOSOptions options = new IOSOptions();2options.setCapability("platformName", "iOS");3options.setCapability("platformVersion", "11.4");4options.setCapability("deviceName", "iPhone 7");5options.setCapability("automationName", "XCUITest");6options.setCapability("app", "/path/to/your.app");

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