Best io.appium code snippet using io.appium.java_client.safari.options.SafariOptions
TestBase.java
Source:TestBase.java
...12import org.openqa.selenium.firefox.FirefoxOptions;13import org.openqa.selenium.ie.InternetExplorerDriver;14import org.openqa.selenium.ie.InternetExplorerOptions;15import org.openqa.selenium.remote.DesiredCapabilities;16import org.openqa.selenium.safari.SafariOptions;17import org.testng.ITestResult;18import org.testng.annotations.AfterMethod;19import org.testng.annotations.BeforeMethod;20import org.testng.annotations.DataProvider;21import common.ExcelMethods;22import common.ReadProperties;23import java.io.File;24import java.io.IOException;25import java.lang.reflect.Method;26import java.net.URL;27public class TestBase {28 //****************************************//29 //*** ***//30 //*** Created by Angela Tong APR 2018 ***//31 //*** ***//32 //****************************************//33 34 //Run mvn dependency:copy-dependencies -DoutputDirectory=lib to extract all the maven dependencies/jars into the lib folder35 //If using for windows, please change paths to windows paths.36 37 @SuppressWarnings("rawtypes")38 public static AppiumDriver driver;39 public static WebDriver webdriver;40 41 //For Mac -comment out if using for windows42 public static String folderpath = "/Users/angee/EclipseProjects/XOME/screencaptures";43 //For Windows -comment out if using for mac44 //public static String folderpath = "C:\\EclipseProjects\\XOME\\screencaptures";45 46 public static String runonrealdevice = "";47 public String methodname = "";48 @SuppressWarnings({ "rawtypes"})49 @BeforeMethod (alwaysRun=true)50 //Use before method instead of before class or before test so each method/test will open in new browser; 51 //This was tested and found before method was the only one that works.52 public void Setup() throws IOException{53 54 ReadProperties.retrieveGlobalProperties();55 56 DesiredCapabilities capabilities = new DesiredCapabilities();57 58 String os = System.getProperty("os.name");59 60 if (ReadProperties.globalProp.getProperty("webautomation").contains("yes") && ReadProperties.globalProp.getProperty("mobileautomation").contains("no"))61 {62 if(ReadProperties.globalProp.getProperty("webbrowser").contains("firefox"))63 {64 //capabilities.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, 1);65 if(os.contains("MAC") || os.contains("mac") || os.contains("Mac"))66 {67 System.setProperty("webdriver.gecko.driver", ReadProperties.globalProp.getProperty("macgeckodriver"));68 FirefoxOptions firefoxOptions = new FirefoxOptions();69 firefoxOptions.setCapability("platform", "MAC");70 firefoxOptions.setCapability("browser", "firefox");71 firefoxOptions.setCapability("newCommandTimeout", 5000);72 }73 else74 {75 System.setProperty("webdriver.gecko.driver", ReadProperties.globalProp.getProperty("pcgeckodriver"));76 FirefoxOptions firefoxOptions = new FirefoxOptions();77 firefoxOptions.setCapability("platform", "WINDOWS");78 firefoxOptions.setCapability("browser", "firefox");79 firefoxOptions.setCapability("newCommandTimeout", 5000);80 }81 webdriver = new FirefoxDriver();82 }83 else if (ReadProperties.globalProp.getProperty("webbrowser").contains("chrome"))84 {85 if(os.contains("MAC") || os.contains("mac") || os.contains("Mac"))86 {87 System.setProperty("webdriver.chrome.driver", ReadProperties.globalProp.getProperty("macchromedriver"));88 ChromeOptions chromeOptions = new ChromeOptions();89 chromeOptions.setCapability("platform", "MAC");90 chromeOptions.setCapability("browser", "chrome");91 chromeOptions.setCapability("newCommandTimeout", 5000);92 }93 else94 {95 System.setProperty("webdriver.chrome.driver", ReadProperties.globalProp.getProperty("pcchromedriver"));96 ChromeOptions chromeOptions = new ChromeOptions();97 chromeOptions.setCapability("platform", "WINDOWS");98 chromeOptions.setCapability("browser", "chrome");99 chromeOptions.setCapability("newCommandTimeout", 5000);100 }101 webdriver = new ChromeDriver();102 }103 else if (ReadProperties.globalProp.getProperty("webbrowser").contains("safari"))104 {105 SafariOptions safariOptions = new SafariOptions();106 safariOptions.setCapability("platform", "MAC");107 safariOptions.setCapability("browser", "safari");108 safariOptions.setCapability("newCommandTimeout", 5000);109 }110 else if(ReadProperties.globalProp.getProperty("webbrowser").contains("MicrosoftEdge"))111 {112 System.setProperty("webdriver.edge.driver", ReadProperties.globalProp.getProperty("edgedriver"));113 EdgeOptions edgeOptions = new EdgeOptions();114 edgeOptions.setCapability("platform", "WINDOWS");115 edgeOptions.setCapability("browser", "edge");116 edgeOptions.setCapability("ensureCleanSession", true);117 edgeOptions.setCapability("ignoreZoomSetting", true);118 edgeOptions.setCapability("ignoreProtectedModeSettings", true);119 edgeOptions.setCapability("ignore-certificate-error", true);...
OptionsBuildingTest.java
Source:OptionsBuildingTest.java
...28import io.appium.java_client.ios.options.simulator.Permissions;29import io.appium.java_client.mac.options.AppleScriptData;30import io.appium.java_client.mac.options.Mac2Options;31import io.appium.java_client.remote.AutomationName;32import io.appium.java_client.safari.options.SafariOptions;33import io.appium.java_client.safari.options.WebrtcData;34import io.appium.java_client.windows.options.PowerShellData;35import io.appium.java_client.windows.options.WindowsOptions;36import org.junit.Test;37import org.openqa.selenium.Platform;38import java.net.MalformedURLException;39import java.net.URL;40import java.time.Duration;41import static org.junit.Assert.assertEquals;42import static org.junit.Assert.assertFalse;43import static org.junit.Assert.assertNotNull;44import static org.junit.Assert.assertTrue;45@SuppressWarnings("ConstantConditions")46public class OptionsBuildingTest {47 @Test48 public void canBuildXcuiTestOptions() throws MalformedURLException {49 XCUITestOptions options = new XCUITestOptions();50 assertEquals(Platform.IOS, options.getPlatformName());51 assertEquals(AutomationName.IOS_XCUI_TEST, options.getAutomationName().orElse(null));52 options.setNewCommandTimeout(Duration.ofSeconds(10))53 .noReset()54 .setWdaBaseUrl("http://localhost:8000")55 .setPermissions(new Permissions()56 .withAppPermissions("com.apple.MobileSafari",57 ImmutableMap.of("calendar", "YES")))58 .setSafariSocketChunkSize(10)59 .setCommandTimeouts(new CommandTimeouts()60 .withCommandTimeout("yolo", Duration.ofSeconds(1)));61 assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));62 assertEquals(new URL("http://localhost:8000"), options.getWdaBaseUrl().orElse(null));63 assertNotNull(options.getPermissions()64 .map((v) -> v.getAppPermissions("com.apple.MobileSafari"))65 .orElse(null));66 assertEquals(10L, (long) options.getSafariSocketChunkSize().orElse(0));67 assertEquals(1L, options.getCommandTimeouts().orElse(null).left()68 .getCommandTimeout("yolo").orElse(null).getSeconds());69 }70 @Test71 public void canBuildUiAutomator2Options() throws MalformedURLException {72 UiAutomator2Options options = new UiAutomator2Options();73 assertEquals(Platform.ANDROID, options.getPlatformName());74 assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, options.getAutomationName().orElse(null));75 options.setNewCommandTimeout(Duration.ofSeconds(10))76 .noReset()77 .setAdbExecTimeout(Duration.ofSeconds(3))78 .suppressKillServer()79 .setMjpegScreenshotUrl(new URL("http://yolo.com"))80 .setKeystoreConfig(new KeystoreConfig("path", "password", "keyAlias", "keyPassword"));81 assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));82 assertEquals(Duration.ofSeconds(3), options.getAdbExecTimeout().orElse(null));83 assertEquals(new URL("http://yolo.com"), options.getMjpegScreenshotUrl().orElse(null));84 assertEquals("path", options.getKeystoreConfig().orElse(null).getPath());85 assertEquals("keyAlias", options.getKeystoreConfig().orElse(null).getKeyAlias());86 assertTrue(options.doesSuppressKillServer().orElse(false));87 }88 @Test89 public void canBuildEspressoOptions() {90 EspressoOptions options = new EspressoOptions();91 assertEquals(Platform.ANDROID, options.getPlatformName());92 assertEquals(AutomationName.ESPRESSO, options.getAutomationName().orElse(null));93 options.setNewCommandTimeout(Duration.ofSeconds(10))94 .forceEspressoRebuild()95 .setAppLocale(new AppLocale()96 .withCountry("CN")97 .withLanguage("zh")98 .withVariant("hans"))99 .setEspressoBuildConfig(new EspressoBuildConfig()100 .withAdditionalAppDependencies(ImmutableList.of(101 "com.dep1:1.2.3",102 "com.dep2:1.2.3"103 ))104 );105 assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));106 assertEquals("CN", options.getAppLocale().orElse(null).getCountry().orElse(null));107 assertEquals(2, options.getEspressoBuildConfig().orElse(null)108 .left().getAdditionalAppDependencies().orElse(null).size());109 assertTrue(options.doesForceEspressoRebuild().orElse(false));110 }111 @Test112 public void canBuildWindowsOptions() {113 WindowsOptions options = new WindowsOptions();114 assertEquals(Platform.WINDOWS, options.getPlatformName());115 assertEquals(AutomationName.WINDOWS, options.getAutomationName().orElse(null));116 options.setNewCommandTimeout(Duration.ofSeconds(10))117 .setPrerun(new PowerShellData().withScript("yolo prescript"))118 .setPostrun(new PowerShellData().withCommand("yolo command"));119 assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));120 assertEquals("yolo prescript", options.getPrerun().orElse(null).getScript().orElse(null));121 assertEquals("yolo command", options.getPostrun().orElse(null).getCommand().orElse(null));122 }123 @Test124 public void canBuildMac2Options() {125 Mac2Options options = new Mac2Options();126 assertEquals(Platform.MAC, options.getPlatformName());127 assertEquals(AutomationName.MAC2, options.getAutomationName().orElse(null));128 options.setNewCommandTimeout(Duration.ofSeconds(10))129 .skipAppKill()130 .setPrerun(new AppleScriptData().withScript("yolo prescript"))131 .setPostrun(new AppleScriptData().withCommand("yolo command"));132 assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));133 assertEquals("yolo prescript", options.getPrerun().orElse(null).getScript().orElse(null));134 assertEquals("yolo command", options.getPostrun().orElse(null).getCommand().orElse(null));135 assertTrue(options.doesSkipAppKill().orElse(false));136 assertFalse(options.doesEventTimings().isPresent());137 }138 @Test139 public void canBuildGeckoOptions() {140 GeckoOptions options = new GeckoOptions();141 options.setPlatformName(Platform.MAC.toString());142 assertEquals(Platform.MAC, options.getPlatformName());143 assertEquals(AutomationName.GECKO, options.getAutomationName().orElse(null));144 options.setNewCommandTimeout(Duration.ofSeconds(10))145 .setVerbosity(Verbosity.TRACE)146 .setMozFirefoxOptions(ImmutableMap.of(147 "profile", "yolo"148 ));149 assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));150 assertEquals(Verbosity.TRACE, options.getVerbosity().orElse(null));151 assertEquals("yolo", options.getMozFirefoxOptions().orElse(null)152 .get("profile"));153 }154 @Test155 public void canBuildSafariOptions() {156 SafariOptions options = new SafariOptions();157 assertEquals(Platform.IOS, options.getPlatformName());158 assertEquals(AutomationName.SAFARI, options.getAutomationName().orElse(null));159 options.setNewCommandTimeout(Duration.ofSeconds(10))160 .safariUseSimulator()161 .setWebkitWebrtc(new WebrtcData()162 .withDisableIceCandidateFiltering(true)163 .withDisableInsecureMediaCapture(true)164 );165 assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null));166 assertTrue(options.doesSafariUseSimulator().orElse(false));167 assertTrue(options.getWebkitWebrtc().orElse(null)168 .doesDisableIceCandidateFiltering().orElse(false));169 assertTrue(options.getWebkitWebrtc().orElse(null)170 .doesDisableInsecureMediaCapture().orElse(false));...
TestInstrument.java
Source:TestInstrument.java
...17import org.openqa.selenium.remote.BrowserType;18import org.openqa.selenium.remote.CapabilityType;19import org.openqa.selenium.remote.DesiredCapabilities;20import org.openqa.selenium.safari.SafariDriver;21import org.openqa.selenium.safari.SafariOptions;22import org.testng.annotations.*;23import java.io.File;24import java.util.concurrent.TimeUnit;25/**26 * Created by Aldo Christian on 21/05/18.27 */28public class TestInstrument {29 private static AppiumDriverLocalService service;30 protected static AndroidDriver driver;31 protected static WebDriver webDriver;32 protected static Bukalapak bukalapak;33 protected static String moduleType;34 /**35 * Initialization36 */37 @Parameters({"deviceName", "platformVersion", "port", "module", "browser", "emulation"})38 @BeforeClass39 public void beforeClass(String deviceName, String platformVersion, int port, String module, String browser, String emulation) {40 AppiumServiceBuilder builder = new AppiumServiceBuilder();41 builder.usingAnyFreePort();42 service = AppiumDriverLocalService.buildService(builder);43 service.stop();44 if (service == null || !service.isRunning()) {45 System.out.println("\"Starting appium server!\"");46 service.start();47 }48 File appDir = new File("/Users/bukalapak/Downloads/apk/");49 File app = new File(appDir, "app-release.apk");50 DesiredCapabilities capabilities = new DesiredCapabilities();51 if (module.equals("APP")) {52 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);53 capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 20);54 capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());55 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);56 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);57 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);58 capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);59 driver = new AndroidDriver<>(service.getUrl(), capabilities);60 bukalapak = new Bukalapak(driver);61 } else {62 switch (browser) {63 case "CHROME":64 capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);65 ChromeOptions chromeOptions = new ChromeOptions();66 chromeOptions.addArguments("--disable-notifications");67 chromeOptions.merge(capabilities);68 webDriver = new ChromeDriver(chromeOptions);69 break;70 case "FIREFOX":71 capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);72 FirefoxOptions firefoxOptions = new FirefoxOptions();73 firefoxOptions.addPreference("dom.webnotifications.enabled", false);74 firefoxOptions.merge(capabilities);75 webDriver = new FirefoxDriver(firefoxOptions);76 break;77 case "OPERA":78 // TODO: Not stable yet for web version, screen blocked by notification prompt79 capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.OPERA_BLINK);80 OperaOptions operaOptions = new OperaOptions();81 webDriver = new OperaDriver(operaOptions);82 break;83 case "SAFARI":84 capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.SAFARI);85 SafariOptions safariOptions = new SafariOptions();86 safariOptions.merge(capabilities);87 webDriver = new SafariDriver(safariOptions);88 break;89 default:90 System.out.println("Sorry, can't found browser settings!");91 break;92 }93 if (module.equals("WEB"))94 webDriver.manage().window().maximize();95 else96 webDriver.manage().window().setSize(EmulateDevice.emulateDevice(emulation));97 bukalapak = new Bukalapak(webDriver);98 }99 }...
DriverFactory.java
Source:DriverFactory.java
...16import org.openqa.selenium.firefox.FirefoxOptions;17import org.openqa.selenium.remote.DesiredCapabilities;18import org.openqa.selenium.remote.RemoteWebDriver;19import org.openqa.selenium.safari.SafariDriver;20import org.openqa.selenium.safari.SafariOptions;21import org.openqa.selenium.support.events.EventFiringWebDriver;22import org.openqa.selenium.support.ui.WebDriverWait;23import java.net.URL;24import java.util.ArrayList;25import java.util.Map;26@Log4j227@SuppressWarnings("unused")28public class DriverFactory {29 private static final ThreadLocal<WebDriver> DRIVER_INSTANCE = new ThreadLocal<>();30 private static String getPlatformNameFromCapabilities(Map<String, Object> capabilities) {31 return capabilities.getOrDefault("platformName", "").toString();32 }33 @SneakyThrows34 private static URL getURLFromCapabilities(Map<String, Object> capabilities) {35 return new URL(capabilities.getOrDefault("hub", "").toString());36 }37 private static EventFiringWebDriver registerEventFiringDriver(WebDriver driver) {38 log.debug("registering firing event driver");39 var eventFiringWebDriver = new EventFiringWebDriver(driver);40 var driverEventListener = new DriverEventListener();41 eventFiringWebDriver.register(driverEventListener);42 log.debug("event firing driver registered");43 return eventFiringWebDriver;44 }45 private static AppiumDriver<?> initAppiumDriver(Map<String, Object> capabilities) {46 log.debug("initializing appium driver");47 var url = getURLFromCapabilities(capabilities);48 var platformName = getPlatformNameFromCapabilities(capabilities);49 var desiredCapabilities = new DesiredCapabilities(capabilities);50 if (platformName.equalsIgnoreCase(Platform.ANDROID.name())) {51 var androidDriver = new AndroidDriver<>(url, desiredCapabilities);52 log.debug("appium android driver initialized with capabilities: {}\n{}", url, desiredCapabilities);53 return androidDriver;54 } else if (platformName.equalsIgnoreCase(Platform.IOS.name())) {55 var iosDriver = new IOSDriver<>(url, desiredCapabilities);56 log.debug("appium ios driver initialized with capabilities: {}\n{}", url, desiredCapabilities);57 return iosDriver;58 } else {59 throw new ExceptionInInitializerError("missing <platformName> capability");60 }61 }62 private static WebDriver initRemoteWebDriver(Map<String, Object> capabilities) {63 if (!getURLFromCapabilities(capabilities).toString().isEmpty()) {64 var url = getURLFromCapabilities(capabilities);65 var remoteWebDriver = new RemoteWebDriver(url, new DesiredCapabilities(capabilities));66 log.debug("remote web driver initialized with capabilities: {}\n{}", url, capabilities);67 return registerEventFiringDriver(remoteWebDriver);68 } else {69 throw new ExceptionInInitializerError("missing <hub> capability");70 }71 }72 @SuppressWarnings({"unchecked", "rawtypes"})73 private static WebDriver initWebDriver(String driverName, Map<String, Object> capabilities) {74 WebDriver driver;75 if (driverName.equalsIgnoreCase("chrome")) {76 WebDriverManager.chromedriver().setup();77 var chromeOptions = new ChromeOptions();78 capabilities.forEach(chromeOptions::setCapability);79 chromeOptions.addArguments((ArrayList) capabilities.getOrDefault("arguments", new ArrayList<>()));80 driver = new ChromeDriver(chromeOptions);81 log.debug("chrome driver initialized with options:\n{}", chromeOptions);82 return registerEventFiringDriver(driver);83 } else if (driverName.equalsIgnoreCase("firefox")) {84 WebDriverManager.firefoxdriver().setup();85 var firefoxOptions = new FirefoxOptions();86 capabilities.forEach(firefoxOptions::setCapability);87 firefoxOptions.addArguments((ArrayList) capabilities.getOrDefault("arguments", new ArrayList<>()));88 driver = new FirefoxDriver(firefoxOptions);89 log.debug("firefox driver initialized with options:\n{}", firefoxOptions);90 return registerEventFiringDriver(driver);91 } else if (driverName.equalsIgnoreCase("safari")) {92 var safariOptions = new SafariOptions();93 capabilities.forEach(safariOptions::setCapability);94 driver = new SafariDriver(safariOptions);95 log.debug("safari driver initialized with options:\n{}", safariOptions);96 return registerEventFiringDriver(driver);97 } else if (driverName.equalsIgnoreCase("edge")) {98 WebDriverManager.edgedriver().setup();99 var edgeOptions = new EdgeOptions();100 capabilities.forEach(edgeOptions::setCapability);101 driver = new EdgeDriver(edgeOptions);102 log.debug("edge driver initialized with options:\n{}", edgeOptions);103 return registerEventFiringDriver(driver);104 } else {105 throw new ExceptionInInitializerError("missing <driver> capability");106 }...
DriveManager.java
Source:DriveManager.java
...9import org.openqa.selenium.edge.EdgeOptions;10import org.openqa.selenium.firefox.FirefoxOptions;11import org.openqa.selenium.remote.CapabilityType;12import org.openqa.selenium.remote.RemoteWebDriver;13import org.openqa.selenium.safari.SafariOptions;14import io.appium.java_client.AppiumDriver;15import io.appium.java_client.android.AndroidDriver;16import io.appium.java_client.ios.IOSDriver;17import io.appium.java_client.remote.MobileCapabilityType;18public class DriveManager {19 // Saucelabs port20 private static final String PORT = System.getProperty("test.remote.access.port");21 // Web driver capabilities22 private MutableCapabilities capabilities;23 // Browser types24 private enum BrowsersTypes {25 CHROME, FIREFOX, MICROSOFTEDGE, SAFARI,26 }27 private URL buildUrl() throws MalformedURLException {28 StringBuilder urlBuilder = new StringBuilder();29 urlBuilder.append("http://");30 urlBuilder.append("127.0.0.1:");31 urlBuilder.append(PORT);32 urlBuilder.append("/wd/hub");33 URL url = new URL(urlBuilder.toString());34 System.out.println("Remote web driver URL:" + url);35 return url;36 }37 public RemoteWebDriver getDriver(String platformName, String browser, String browserVersion,38 String device, String deviceOrientation, Map<String, Object> sauceOptions) throws MalformedURLException {39 if(device != null) {40 return getMobileDriver(platformName, browser, device, browserVersion, deviceOrientation, sauceOptions);41 } else {42 return getDesktopDriver(browser, platformName, browserVersion, sauceOptions);43 }44 }45 public RemoteWebDriver getDesktopDriver(String browserName, String platformName, String browserVersion,46 Map<String, Object> sauceOptions) throws MalformedURLException {47 BrowsersTypes browser = BrowsersTypes.valueOf(browserName.toUpperCase());48 switch (browser) {49 case CHROME:50 ChromeOptions chromeOptions = new ChromeOptions();51 capabilities = (MutableCapabilities) chromeOptions;52 break;53 case FIREFOX:54 FirefoxOptions firefoxOptions = new FirefoxOptions();55 capabilities = (MutableCapabilities) firefoxOptions;56 break;57 case MICROSOFTEDGE:58 EdgeOptions edgeOptions = new EdgeOptions();59 capabilities = (MutableCapabilities) edgeOptions;60 break;61 case SAFARI:62 SafariOptions safariOptions = new SafariOptions();63 capabilities = (MutableCapabilities) safariOptions;64 break;65 default:66 capabilities = new MutableCapabilities();67 capabilities.setCapability(CapabilityType.BROWSER_NAME, browserName);68 }69 capabilities.setCapability(CapabilityType.PLATFORM_NAME, platformName);70 capabilities.setCapability(CapabilityType.BROWSER_VERSION, browserVersion);71 capabilities.setCapability("sauce:options", sauceOptions);72 System.out.println("Web driver configurations: browser[" + browserName +73 "], browser version[" + browserVersion +74 "], platform name[" + platformName +75 "], sauce options[" + sauceOptions.toString() + "]"76 );...
DriverType.java
Source:DriverType.java
...13import org.openqa.selenium.remote.CapabilityType;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.remote.RemoteWebDriver;16import org.openqa.selenium.safari.SafariDriver;17import org.openqa.selenium.safari.SafariOptions;18import java.util.HashMap;19/**20 * DriverType is an enum for defining the type of Selenium or Appium driver.21 * It is called by DriverFactory, where you can set driver capabilities specific22 * to the mobile device or browser under test. For example, when setting DriverType.ANDROID23 * you can specify the platformVersion and deviceName as DesiredCapabilities. Also, any24 * capabilities that are always needed for a specific DriverType can be stored within the25 * enum getDriverObject() method.26 */27public enum DriverType implements DriverSetup {28 CHROME {29 @Override30 public RemoteWebDriver getDriverObject(DesiredCapabilities capabilities) {31 HashMap<String, Object> chromePreferences = new HashMap<>();32 ChromeOptions options = new ChromeOptions();33 options.merge(capabilities);34 options.addArguments("--start-maximized");35 options.setExperimentalOption("prefs", chromePreferences);36 System.setProperty("webdriver.chrome.driver", getDriverBinaryPath("chrome"));37 return new ChromeDriver(options);38 }39 },40 FIREFOX {41 @Override42 public RemoteWebDriver getDriverObject(DesiredCapabilities capabilities) {43 FirefoxOptions options = new FirefoxOptions();44 options.merge(capabilities);45 System.setProperty("webdriver.gecko.driver", getDriverBinaryPath("firefox"));46 return new FirefoxDriver(options);47 }48 },49 IE {50 @Override51 public RemoteWebDriver getDriverObject(DesiredCapabilities capabilities) {52 InternetExplorerOptions options = new InternetExplorerOptions();53 options.merge(capabilities);54 options.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);55 options.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, true);56 options.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);57 return new InternetExplorerDriver(options);58 }59 },60 EDGE {61 @Override62 public RemoteWebDriver getDriverObject(DesiredCapabilities capabilities) {63 EdgeOptions options = new EdgeOptions();64 options.merge(capabilities);65 return new EdgeDriver(options);66 }67 },68 SAFARI {69 @Override70 public RemoteWebDriver getDriverObject(DesiredCapabilities capabilities) {71 SafariOptions options = new SafariOptions();72 options.merge(capabilities);73 return new SafariDriver(options);74 }75 },76 ANDROID {77 @Override78 public RemoteWebDriver getDriverObject(DesiredCapabilities capabilities) {79 capabilities.setCapability("unicodeKeyboard", true);80 capabilities.setCapability("resetKeyboard", true);81 return new AndroidDriver<MobileElement>(capabilities);82 }83 },84 IOS {85 @Override...
SafariOptions.java
Source:SafariOptions.java
...28import java.util.Map;29/**30 * https://github.com/appium/appium-safari-driver#usage31 */32public class SafariOptions extends BaseOptions<SafariOptions> implements33 SupportsBrowserNameOption<SafariOptions>,34 SupportsBrowserVersionOption<SafariOptions>,35 SupportsSafariPlatformVersionOption<SafariOptions>,36 SupportsSafariPlatformBuildVersionOption<SafariOptions>,37 SupportsSafariUseSimulatorOption<SafariOptions>,38 SupportsSafariDeviceTypeOption<SafariOptions>,39 SupportsSafariDeviceNameOption<SafariOptions>,40 SupportsSafariDeviceUdidOption<SafariOptions>,41 SupportsSafariAutomaticInspectionOption<SafariOptions>,42 SupportsSafariAutomaticProfilingOption<SafariOptions>,43 SupportsWebkitWebrtcOption<SafariOptions>,44 SupportsAcceptInsecureCertsOption<SafariOptions>,45 SupportsPageLoadStrategyOption<SafariOptions>,46 SupportsSetWindowRectOption<SafariOptions>,47 SupportsProxyOption<SafariOptions>,48 SupportsUnhandledPromptBehaviorOption<SafariOptions> {49 public SafariOptions() {50 setCommonOptions();51 }52 public SafariOptions(Capabilities source) {53 super(source);54 setCommonOptions();55 }56 public SafariOptions(Map<String, ?> source) {57 super(source);58 setCommonOptions();59 }60 private void setCommonOptions() {61 setPlatformName(Platform.IOS.toString());62 setAutomationName(AutomationName.SAFARI);63 }64}...
CustomWebDriverInterceptor.java
Source:CustomWebDriverInterceptor.java
...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}...
SafariOptions
Using AI Code Generation
1SafariOptions options = new SafariOptions();2options.setUseTechnologyPreview(true);3DesiredCapabilities capabilities = new DesiredCapabilities();4capabilities.setCapability(SafariOptions.CAPABILITY, options);5capabilities.setCapability("platformName", "iOS");6capabilities.setCapability("platformVersion", "8.1");7capabilities.setCapability("deviceName", "iPhone Simulator");8capabilities.setCapability("browserName", "Safari");9capabilities.setCapability("appiumVersion", "1.3.4");10capabilities.setCapability("deviceOrientation", "portrait");11capabilities.setCapability("deviceType", "phone");12capabilities.setCapability("name", "SafariOptions");13capabilities.setCapability("build", "1.0");14driver = new IOSDriver(new URL(URL), capabilities);15SafariOptions options = new SafariOptions();16options.setUseTechnologyPreview(true);17DesiredCapabilities capabilities = new DesiredCapabilities();18capabilities.setCapability(SafariOptions.CAPABILITY, options);19capabilities.setCapability("platformName", "iOS");20capabilities.setCapability("platformVersion", "8.1");21capabilities.setCapability("deviceName", "iPhone Simulator");22capabilities.setCapability("browserName", "Safari");23capabilities.setCapability("appiumVersion", "1.3.4");24capabilities.setCapability("deviceOrientation", "portrait");25capabilities.setCapability("deviceType", "phone");26capabilities.setCapability("name", "SafariOptions");27capabilities.setCapability("build", "1.0");28driver = new IOSDriver(new URL(URL), capabilities);29var SafariOptions = require('appium').SafariOptions;30var options = new SafariOptions();31options.setUseTechnologyPreview(true);32var desiredCaps = {33};34desiredCaps[SafariOptions.CAPABILITY] = options;35driver = wd.promiseChainRemote('ondemand.saucelabs.com', 80, username, accessKey);36driver.init(desiredCaps);
SafariOptions
Using AI Code Generation
1SafariOptions options = new SafariOptions();2options.setUseTechnologyPreview(true);3DesiredCapabilities capabilities = new DesiredCapabilities();4capabilities.setCapability(SafariOptions.CAPABILITY, options);5WebDriver driver = new SafariDriver(capabilities);6SafariOptions options = new SafariOptions();7options.setUseTechnologyPreview(true);8DesiredCapabilities capabilities = new DesiredCapabilities();9capabilities.setCapability(SafariOptions.CAPABILITY, options);10WebDriver driver = new SafariDriver(capabilities);11SafariOptions options = new SafariOptions();12options.setUseTechnologyPreview(true);13DesiredCapabilities capabilities = new DesiredCapabilities();14capabilities.setCapability(SafariOptions.CAPABILITY, options);15WebDriver driver = new SafariDriver(capabilities);16SafariOptions options = new SafariOptions();17options.setUseTechnologyPreview(true);18DesiredCapabilities capabilities = new DesiredCapabilities();19capabilities.setCapability(SafariOptions.CAPABILITY, options);20WebDriver driver = new SafariDriver(capabilities);21SafariOptions options = new SafariOptions();22options.setUseTechnologyPreview(true);23DesiredCapabilities capabilities = new DesiredCapabilities();24capabilities.setCapability(SafariOptions.CAPABILITY, options);25WebDriver driver = new SafariDriver(capabilities);26SafariOptions options = new SafariOptions();27options.setUseTechnologyPreview(true);28DesiredCapabilities capabilities = new DesiredCapabilities();29capabilities.setCapability(SafariOptions.CAPABILITY, options);30WebDriver driver = new SafariDriver(capabilities);31SafariOptions options = new SafariOptions();32options.setUseTechnologyPreview(true);33DesiredCapabilities capabilities = new DesiredCapabilities();34capabilities.setCapability(SafariOptions.CAPABILITY, options);35WebDriver driver = new SafariDriver(capabilities);36SafariOptions options = new SafariOptions();37options.setUseTechnologyPreview(true
SafariOptions
Using AI Code Generation
1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setCapability("browserName", "Safari");3capabilities.setCapability("platformName", "iOS");4capabilities.setCapability("platformVersion", "11.2");5capabilities.setCapability("deviceName", "iPhone Simulator");6SafariOptions options = new SafariOptions();7options.setUseCleanSession(true);8options.setUseTechnologyPreview(true);9capabilities.setCapability(SafariOptions.CAPABILITY, options);10DesiredCapabilities capabilities = new DesiredCapabilities();11capabilities.setCapability("browserName", "Safari");12capabilities.setCapability("platformName", "iOS");13capabilities.setCapability("platformVersion", "11.2");14capabilities.setCapability("deviceName", "iPhone Simulator");15SafariOptions options = new SafariOptions();16options.setUseCleanSession(true);17options.setUseTechnologyPreview(true);18capabilities.setCapability(SafariOptions.CAPABILITY, options);19const opts = {20 safariOptions: {21 }22};23const opts = {24 safariOptions: {25 }26};27opts = { caps: {28 safariOptions: {29 }30}}31opts = { caps: {32 safariOptions: {
SafariOptions
Using AI Code Generation
1SafariOptions options = new SafariOptions();2options.setUseCleanSession(true);3options.setUseTechnologyPreview(true);4SafariDriver driver = new SafariDriver(options);5var options = new SafariOptions();6options.setUseCleanSession(true);7options.setUseTechnologyPreview(true);8var driver = new SafariDriver(options);9options = SafariOptions()10driver = SafariDriver(options)11driver = Appium::Safari::Driver.new(options)12$options = new SafariOptions();13$options->setUseCleanSession(true);14$options->setUseTechnologyPreview(true);15$driver = new SafariDriver($options);16SafariOptions options = new SafariOptions();17options.UseCleanSession = true;18options.UseTechnologyPreview = true;19SafariDriver driver = new SafariDriver(options);20options := new SafariOptions()21options.SetUseCleanSession(true)22options.SetUseTechnologyPreview(true)23driver := new SafariDriver(options)
SafariOptions
Using AI Code Generation
1SafariOptions safariOptions = new SafariOptions();2safariOptions.setUseCleanSession(true);3safariOptions.setTechnologyPreview(true);4safariOptions.setUseTechnologyPreview(true);5safariOptions.setAutomaticInspection(true);6safariOptions.setAutomaticProfiling(true);7safariOptions.setUseFirstMatch(true);
SafariOptions
Using AI Code Generation
1SafariOptions options = new SafariOptions();2options.setUseCleanSession(true);3options.setUseTechnologyPreview(true);4driver = new SafariDriver(options);5SafariOptions options = new SafariOptions();6options.setUseCleanSession(true);7options.setUseTechnologyPreview(true);8driver = new SafariDriver(options);9SafariOptions options = new SafariOptions();10options.setUseCleanSession(true);11options.setUseTechnologyPreview(true);12driver = new SafariDriver(options);13SafariOptions options = new SafariOptions();14options.setUseCleanSession(true);15options.setUseTechnologyPreview(true);16driver = new SafariDriver(options);17SafariOptions options = new SafariOptions();18options.setUseCleanSession(true);19options.setUseTechnologyPreview(true);20driver = new SafariDriver(options);21SafariOptions options = new SafariOptions();22options.setUseCleanSession(true);23options.setUseTechnologyPreview(true);24driver = new SafariDriver(options);25SafariOptions options = new SafariOptions();26options.setUseCleanSession(true);27options.setUseTechnologyPreview(true);28driver = new SafariDriver(options);29SafariOptions options = new SafariOptions();30options.setUseCleanSession(true);31options.setUseTechnologyPreview(true);32driver = new SafariDriver(options);33SafariOptions options = new SafariOptions();34options.setUseCleanSession(true);35options.setUseTechnologyPreview(true);36driver = new SafariDriver(options);
SafariOptions
Using AI Code Generation
1SafariOptions options = new SafariOptions();2options.setUseCleanSession(true);3options.setPort(1234);4DesiredCapabilities capabilities = new DesiredCapabilities();5capabilities.setCapability("safari.options", options);6capabilities.setCapability(CapabilityType.BROWSER_NAME, "safari");7capabilities.setCapability(CapabilityType.PLATFORM, "MAC");8capabilities.setCapability(CapabilityType.VERSION, "10.10");9driver = new SafariDriver(capabilities);10SafariOptions options = new SafariOptions();11options.setUseCleanSession(true);12options.setPort(1234);13DesiredCapabilities capabilities = new DesiredCapabilities();14capabilities.setCapability("safari.options", options);15capabilities.setCapability(CapabilityType.BROWSER_NAME, "safari");16capabilities.setCapability(CapabilityType.PLATFORM, "MAC");17capabilities.setCapability(CapabilityType.VERSION, "10.10");18driver = new SafariDriver(capabilities);19SafariOptions options = new SafariOptions();20options.setUseCleanSession(true);21options.setPort(1234);22DesiredCapabilities capabilities = new DesiredCapabilities();23capabilities.setCapability("safari.options", options);24capabilities.setCapability(CapabilityType.BROWSER_NAME, "safari");25capabilities.setCapability(CapabilityType.PLATFORM, "MAC");26capabilities.setCapability(CapabilityType.VERSION, "10.10");27driver = new SafariDriver(capabilities);28SafariOptions options = new SafariOptions();29options.setUseCleanSession(true);30options.setPort(1234);31DesiredCapabilities capabilities = new DesiredCapabilities();32capabilities.setCapability("safari.options", options);33capabilities.setCapability(CapabilityType.BROWSER_NAME, "safari");34capabilities.setCapability(CapabilityType.PLATFORM, "MAC");35capabilities.setCapability(CapabilityType.VERSION, "10.10");36driver = new SafariDriver(capabilities);37SafariOptions options = new SafariOptions();38options.setUseCleanSession(true);39options.setPort(1234);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!