How to use Mac2Driver class of io.appium.java_client.mac package

Best io.appium code snippet using io.appium.java_client.mac.Mac2Driver

SmartAppDriver.java

Source:SmartAppDriver.java Github

copy

Full Screen

...59import org.uitnet.testing.smartfwk.ui.core.handler.DefaultScrollElementToViewportHandler;60import org.uitnet.testing.smartfwk.ui.core.handler.ScrollElementToViewportHandler;61import io.appium.java_client.android.AndroidDriver;62import io.appium.java_client.ios.IOSDriver;63import io.appium.java_client.mac.Mac2Driver;64import io.appium.java_client.windows.WindowsDriver;65/**66 * 67 * @author Madhav Krishna68 *69 */70public class SmartAppDriver {71 private int appId;72 private String appName;73 private ApplicationType appType;74 private PlatformType testPlatformType;75 private WebDriver webDriver;76 private Screen sikuliDriver;77 private AppConfig appConfig;78 private boolean opened = false;79 private ScrollElementToViewportHandler scrollElemToViewportCallback;80 public SmartAppDriver(String appName, ApplicationType appType, PlatformType testPlatformType) {81 this.appId = AppIdGenerator.getInstance().nextValue();82 this.appName = appName;83 this.appType = appType;84 this.testPlatformType = testPlatformType;85 this.sikuliDriver = new Screen();86 this.appConfig = TestConfigManager.getInstance().getAppConfig(appName);87 }88 89 public void setScrollElementToViewportHandler(ScrollElementToViewportHandler handler) {90 scrollElemToViewportCallback = handler;91 }92 93 public ScrollElementToViewportHandler getScrollElementToViewportHandler() {94 return scrollElemToViewportCallback;95 }96 public WebDriver openAppIfNotOpened() {97 if (!opened) {98 prepareWebDriver();99 opened = true;100 }101 return webDriver;102 }103 private void prepareWebDriver() {104 scrollElemToViewportCallback = new DefaultScrollElementToViewportHandler();105 106 if (testPlatformType == PlatformType.windows) {107 if (appType == ApplicationType.native_app) {108 prepareWindowsNativeAppDriver();109 } else if (appType == ApplicationType.web_app) {110 prepareWebAppDriverForNonMobileApp();111 }112 } else if (testPlatformType == PlatformType.linux) {113 if (appType == ApplicationType.native_app) {114 Assert.fail("Automation for native app on linux platform is not supported.");115 } else if (appType == ApplicationType.web_app) {116 prepareWebAppDriverForNonMobileApp();117 }118 } else if (testPlatformType == PlatformType.mac) {119 if (appType == ApplicationType.native_app) {120 prepareMacNativeAppDriver();121 } else if (appType == ApplicationType.web_app) {122 prepareWebAppDriverForNonMobileApp();123 }124 } else if (testPlatformType == PlatformType.android_mobile) {125 if (appType == ApplicationType.native_app) {126 prepareAndroidMobileAppDriver();127 } else if (appType == ApplicationType.web_app) {128 prepareAndroidMobileAppDriver();129 }130 } else if (testPlatformType == PlatformType.ios_mobile) {131 if (appType == ApplicationType.native_app) {132 prepareIosMobileAppDriver();133 } else if (appType == ApplicationType.web_app) {134 prepareIosMobileAppDriver();135 }136 }137 }138 private void prepareWindowsNativeAppDriver() {139 AppDriverConfig webDriverCfg = appConfig.getAppDriverConfig();140 DesiredCapabilities capabilities = new DesiredCapabilities();141 capabilities.setAcceptInsecureCerts(webDriverCfg.isAcceptInsecureCertificates());142 for (Map.Entry<String, Object> entry : appConfig.getAppDriverConfig().getDriverCapabilities().entrySet()) {143 capabilities.setCapability(entry.getKey(), entry.getValue());144 }145 try {146 webDriver = new WindowsDriver<WebElement>(147 new URI(appConfig.getAppDriverConfig().getRemoteDriverURL()).toURL(), capabilities);148 } catch (Exception ex) {149 Assert.fail("Failed to initialize windows driver.", ex);150 }151 }152 private void prepareAndroidMobileAppDriver() {153 AppDriverConfig webDriverCfg = appConfig.getAppDriverConfig();154 DesiredCapabilities capabilities = new DesiredCapabilities();155 capabilities.setAcceptInsecureCerts(webDriverCfg.isAcceptInsecureCertificates());156 for (Map.Entry<String, Object> entry : appConfig.getAppDriverConfig().getDriverCapabilities().entrySet()) {157 if ("app".equals(entry.getKey())158 && !(("" + entry.getValue()).startsWith("http:") || ("" + entry.getValue()).startsWith("https:"))) {159 capabilities.setCapability(entry.getKey(), appConfig.getAppsConfigDir() + File.separator160 + appConfig.getAppName() + File.separator + entry.getValue());161 } else {162 capabilities.setCapability(entry.getKey(), entry.getValue());163 }164 }165 try {166 webDriver = new AndroidDriver<WebElement>(167 new URI(appConfig.getAppDriverConfig().getRemoteDriverURL()).toURL(), capabilities);168 169 } catch (Exception ex) {170 Assert.fail("Failed to initialize android driver.", ex);171 }172 }173 private void prepareIosMobileAppDriver() {174 AppDriverConfig webDriverCfg = appConfig.getAppDriverConfig();175 DesiredCapabilities capabilities = new DesiredCapabilities();176 capabilities.setAcceptInsecureCerts(webDriverCfg.isAcceptInsecureCertificates());177 for (Map.Entry<String, Object> entry : appConfig.getAppDriverConfig().getDriverCapabilities().entrySet()) {178 capabilities.setCapability(entry.getKey(), entry.getValue());179 }180 webDriver = new IOSDriver<WebElement>(capabilities);181 }182 private void prepareMacNativeAppDriver() {183 AppDriverConfig webDriverCfg = appConfig.getAppDriverConfig();184 DesiredCapabilities capabilities = new DesiredCapabilities();185 capabilities.setAcceptInsecureCerts(webDriverCfg.isAcceptInsecureCertificates());186 for (Map.Entry<String, Object> entry : appConfig.getAppDriverConfig().getDriverCapabilities().entrySet()) {187 capabilities.setCapability(entry.getKey(), entry.getValue());188 }189 webDriver = new Mac2Driver<WebElement>(capabilities);190 }191 private void prepareWebAppDriverForNonMobileApp() {192 AppDriverConfig webDriverCfg = appConfig.getAppDriverConfig();193 Proxy proxy;194 try {195 switch (appConfig.getAppWebBrowser()) {196 case firefox: {197 System.setProperty(webDriverCfg.getDriverSystemPropertyName(), webDriverCfg.getDriverBinaryFilePath());198 FirefoxProfile firefoxProfile = new FirefoxProfile(new File(webDriverCfg.getProfilePath()));199 if (appConfig.isEnableWebBrowserExtension()) {200 for (File file : webDriverCfg.getBrowserExtensionFiles()) {201 firefoxProfile.addExtension(file);202 }203 }...

Full Screen

Full Screen

Mac2Options.java

Source:Mac2Options.java Github

copy

Full Screen

...55 }56 /**57 * An object containing either script or command key. The value of58 * each key must be a valid AppleScript script or command to be59 * executed after before Mac2Driver session is started. See60 * https://github.com/appium/appium-mac2-driver#applescript-commands-execution61 * for more details.62 *63 * @param script A valid AppleScript snippet.64 * @return self instance for chaining.65 */66 public Mac2Options setPrerun(AppleScriptData script) {67 return amend(PRERUN_OPTION, script.toMap());68 }69 /**70 * Get the prerun script.71 *72 * @return Prerun script.73 */74 public Optional<AppleScriptData> getPrerun() {75 //noinspection unchecked76 return Optional.ofNullable(getCapability(PRERUN_OPTION))77 .map((v) -> new AppleScriptData((Map<String, Object>) v));78 }79 /**80 * An object containing either script or command key. The value of81 * each key must be a valid AppleScript script or command to be82 * executed after Mac2Driver session is stopped. See83 * https://github.com/appium/appium-mac2-driver#applescript-commands-execution84 * for more details.85 *86 * @param script A valid AppleScript snippet.87 * @return self instance for chaining.88 */89 public Mac2Options setPostrun(AppleScriptData script) {90 return amend(POSTRUN_OPTION, script.toMap());91 }92 /**93 * Get the postrun script.94 *95 * @return Postrun script.96 */...

Full Screen

Full Screen

Mac2Driver.java

Source:Mac2Driver.java Github

copy

Full Screen

...25import org.openqa.selenium.remote.HttpCommandExecutor;26import org.openqa.selenium.remote.http.HttpClient;27import java.net.URL;28/**29 * Mac2Driver is an officially supported Appium driver30 * created to automate Mac OS apps. The driver uses W3C31 * WebDriver protocol and is built on top of Apple's XCTest32 * automation framework. Read https://github.com/appium/appium-mac2-driver33 * for more details on how to configure and use it.34 *35 * @since Appium 1.20.036 */37public class Mac2Driver extends AppiumDriver implements38 PerformsTouchActions,39 CanRecordScreen {40 private static final String PLATFORM_NAME = Platform.MAC.name();41 private static final String AUTOMATION_NAME = AutomationName.MAC2;42 public Mac2Driver(HttpCommandExecutor executor, Capabilities capabilities) {43 super(executor, ensurePlatformAndAutomationNames(capabilities, PLATFORM_NAME, AUTOMATION_NAME));44 }45 public Mac2Driver(URL remoteAddress, Capabilities capabilities) {46 super(remoteAddress, ensurePlatformAndAutomationNames(47 capabilities, PLATFORM_NAME, AUTOMATION_NAME));48 }49 public Mac2Driver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities capabilities) {50 super(remoteAddress, httpClientFactory, ensurePlatformAndAutomationNames(51 capabilities, PLATFORM_NAME, AUTOMATION_NAME));52 }53 public Mac2Driver(AppiumDriverLocalService service, Capabilities capabilities) {54 super(service, ensurePlatformAndAutomationNames(capabilities, PLATFORM_NAME, AUTOMATION_NAME));55 }56 public Mac2Driver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,57 Capabilities capabilities) {58 super(service, httpClientFactory, ensurePlatformAndAutomationNames(59 capabilities, PLATFORM_NAME, AUTOMATION_NAME));60 }61 public Mac2Driver(AppiumServiceBuilder builder, Capabilities capabilities) {62 super(builder, ensurePlatformAndAutomationNames(63 capabilities, PLATFORM_NAME, AUTOMATION_NAME));64 }65 public Mac2Driver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,66 Capabilities capabilities) {67 super(builder, httpClientFactory, ensurePlatformAndAutomationNames(68 capabilities, PLATFORM_NAME, AUTOMATION_NAME));69 }70 public Mac2Driver(HttpClient.Factory httpClientFactory, Capabilities capabilities) {71 super(httpClientFactory, ensurePlatformAndAutomationNames(72 capabilities, PLATFORM_NAME, AUTOMATION_NAME));73 }74 public Mac2Driver(Capabilities capabilities) {75 super(ensurePlatformAndAutomationNames(capabilities, PLATFORM_NAME, AUTOMATION_NAME));76 }77}...

Full Screen

Full Screen

SupportsSystemHostOption.java

Source:SupportsSystemHostOption.java Github

copy

Full Screen

...22 Capabilities, CanSetCapability<T> {23 String SYSTEM_HOST_OPTION = "systemHost";24 /**25 * The name of the host for the internal server to listen on.26 * If not provided then Mac2Driver will use the default host27 * address 127.0.0.1. You could set it to 0.0.0.0 to make the28 * server listening on all available network interfaces.29 * It is also possible to set the particular interface name, for example en1.30 *31 * @param host Host name.32 * @return self instance for chaining.33 */34 default T setSystemHost(String host) {35 return amend(SYSTEM_HOST_OPTION, host);36 }37 /**38 * Get the name of the host for the internal server to listen on.39 *40 * @return System host value....

Full Screen

Full Screen

SupportsSystemPortOption.java

Source:SupportsSystemPortOption.java Github

copy

Full Screen

...23 Capabilities, CanSetCapability<T> {24 String SYSTEM_PORT_OPTION = "systemPort";25 /**26 * The number of the port for the internal server to listen on.27 * If not provided then Mac2Driver will use the default port 10100.28 *29 * @param port port number in range 0..6553530 * @return self instance for chaining.31 */32 default T setSystemPort(int port) {33 return amend(SYSTEM_PORT_OPTION, port);34 }35 /**36 * Get the number of the port for the internal server to listen on.37 *38 * @return System port value.39 */40 default Optional<Integer> getSystemPort() {41 return Optional.ofNullable(toInteger(getCapability(SYSTEM_PORT_OPTION)));...

Full Screen

Full Screen

Mac2Driver

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.mac.Mac2Driver;2import io.appium.java_client.mac.Mac2Driver;3import io.appium.java_client.mac.Mac2Driver;4import io.appium.java_client.mac.Mac2Driver;5import io.appium.java_client.mac.Mac2Driver;6import io.appium.java_client.mac.Mac2Driver;7import io.appium.java_client.mac.Mac2Driver;8import io.appium.java_client.mac.Mac2Driver;9import io.appium.java_client.mac.Mac2Driver;10import io.appium.java_client.mac.Mac2Driver;11import io.appium.java_client.mac.Mac2Driver;12import io.appium.java_client.mac.Mac2Driver;13import io.appium.java_client.mac.Mac2Driver;14import io.appium.java_client.mac.Mac2Driver;

Full Screen

Full Screen

Mac2Driver

Using AI Code Generation

copy

Full Screen

1Mac2Element element = driver.findElementByAccessibilityId("SomeId");2element.click();3Mac2Element element = driver.findElementByAccessibilityId("SomeId");4element.sendKeys("Some text");5Mac2Element element = driver.findElementByAccessibilityId("SomeId");6element.clear();7Mac2Element element = driver.findElementByAccessibilityId("SomeId");8element.submit();9Mac2Element element = driver.findElementByAccessibilityId("SomeId");10element.isDisplayed();11Mac2Element element = driver.findElementByAccessibilityId("SomeId");12element.isEnabled();13Mac2Element element = driver.findElementByAccessibilityId("SomeId");14element.isSelected();15Mac2Element element = driver.findElementByAccessibilityId("SomeId");16element.getLocation();17Mac2Element element = driver.findElementByAccessibilityId("SomeId");18element.getSize();19Mac2Element element = driver.findElementByAccessibilityId("SomeId");20element.getRect();21Mac2Element element = driver.findElementByAccessibilityId("SomeId");22element.getTagName();23Mac2Element element = driver.findElementByAccessibilityId("SomeId");24element.getAttribute("attributeName");25Mac2Element element = driver.findElementByAccessibilityId("SomeId");26element.getCssValue("cssProperty");

Full Screen

Full Screen

Mac2Driver

Using AI Code Generation

copy

Full Screen

1package appium;2import java.net.URL;3import org.openqa.selenium.remote.DesiredCapabilities;4import io.appium.java_client.mac.Mac2Driver;5public class Appium {6 public static void main(String[] args) throws Exception {7 DesiredCapabilities capabilities = new DesiredCapabilities();8 capabilities.setCapability("platformName", "Mac");9 capabilities.setCapability("app", "/Applications/Calculator.app");

Full Screen

Full Screen

Mac2Driver

Using AI Code Generation

copy

Full Screen

1package com.appium.test;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.By;5import org.openqa.selenium.remote.DesiredCapabilities;6import io.appium.java_client.mac.Mac2Driver;7import io.appium.java_client.remote.MobileCapabilityType;8public class Mac2DriverTest {9public static void main(String[] args) throws MalformedURLException {10DesiredCapabilities capabilities = new DesiredCapabilities();11capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Mac");12capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Mac");13capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.12");14capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Mac");15capabilities.setCapability(MobileCapabilityType.APP, "/Applications/Calculator.app");

Full Screen

Full Screen

Mac2Driver

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.Mac2Driver;2import io.appium.java_client.Mac2Driver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.openqa.selenium.support.ui.ExpectedConditions;6import org.openqa.selenium.support.ui.WebDriverWait;7public class Mac2DriverDemo {8 public static void main(String[] args) {9 Mac2Driver<WebElement> driver;10 DesiredCapabilities capabilities = new DesiredCapabilities();11 capabilities.setCapability("platformName", "Mac");12 capabilities.setCapability("platformVersion", "10.13");13 capabilities.setCapability("deviceName", "Mac");14 capabilities.setCapability("automationName", "XCUITest");15 capabilities.setCapability("app", "/Users/username/Desktop/Calculator.app");16 driver = new Mac2Driver<WebElement>(capabilities);17 WebDriverWait wait = new WebDriverWait(driver, 10);18 WebElement button = driver.findElementByName("Calculator");19 button.click();20 WebElement button2 = driver.findElementByName("Calculator");21 button2.click();22 WebElement button3 = driver.findElementByName("Calculator");23 button3.click();24 WebElement button4 = driver.findElementByName("Calculator");25 button4.click();26 WebElement button5 = driver.findElementByName("Calculator");27 button5.click();28 WebElement button6 = driver.findElementByName("Calculator");29 button6.click();30 WebElement button7 = driver.findElementByName("Calculator");31 button7.click();32 WebElement button8 = driver.findElementByName("Calculator");33 button8.click();34 WebElement button9 = driver.findElementByName("Calculator");35 button9.click();

Full Screen

Full Screen

Mac2Driver

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.mac.Mac2Driver;6public class MacDriver {7public static void main(String[] args) throws MalformedURLException {8DesiredCapabilities cap = new DesiredCapabilities();9cap.setCapability("platformName", "Mac");10cap.setCapability("app", "/Applications/Calculator.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