Best io.appium code snippet using io.appium.java_client.safari.SafariDriver
TestInstrument.java
Source:TestInstrument.java
...16import org.openqa.selenium.opera.OperaOptions;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 }100 /**101 * Finishing...
BrowserCompatibilityTest.java
Source:BrowserCompatibilityTest.java
...20import org.openqa.selenium.chrome.ChromeDriverService;21import org.openqa.selenium.firefox.FirefoxDriver;22import org.openqa.selenium.ie.InternetExplorerDriver;23import org.openqa.selenium.ie.InternetExplorerDriverService;24import org.openqa.selenium.safari.SafariDriver;25import org.openqa.selenium.support.FindBy;26import org.openqa.selenium.support.FindBys;27import org.openqa.selenium.support.PageFactory;28import org.openqa.selenium.remote.RemoteWebElement;29public class BrowserCompatibilityTest {30 private static enum AvailableDrivers {31 FIREFOX(FirefoxDriver.class, new ArrayList<Platform>() {32 private static final long serialVersionUID = 1L;33 {34 add(Platform.WINDOWS);35 add(Platform.MAC);36 }37 }, new HashMap<Platform, File>(), null), CHROME(ChromeDriver.class,38 new ArrayList<Platform>() {39 private static final long serialVersionUID = 1L;40 {41 add(Platform.WINDOWS);42 add(Platform.MAC);43 }44 }, new HashMap<Platform, File>() {45 private static final long serialVersionUID = 1L;46 {47 put(Platform.WINDOWS,48 new File(49 "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver.exe"));50 put(Platform.MAC,51 new File(52 "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver"));53 }54 }, ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY), 55 INTERNET_EXPLORER(56 InternetExplorerDriver.class, new ArrayList<Platform>() {57 private static final long serialVersionUID = 1L;58 {59 add(Platform.WINDOWS);60 }61 }, new HashMap<Platform, File>() {62 private static final long serialVersionUID = 1L;63 {64 put(Platform.WINDOWS,65 new File(66 "src/test/java/io/appium/java_client/pagefactory_tests/IEDriverServer.exe"));67 }68 }, InternetExplorerDriverService.IE_DRIVER_EXE_PROPERTY), SAFARI(69 SafariDriver.class, new ArrayList<Platform>() {70 private static final long serialVersionUID = 1L;71 {72 add(Platform.MAC);73 }74 }, new HashMap<Platform, File>(), null);75 // TODO Linux can be added if is necessary76 private final Class<? extends WebDriver> driverClazz;77 private final List<Platform> platformCompatible;78 private final Map<Platform, File> serviceBinaries;79 private final String propertyName;80 private AvailableDrivers(Class<? extends WebDriver> driverClazz,81 List<Platform> platformCompatible,82 Map<Platform, File> serviceBinaries, String property) {83 this.driverClazz = driverClazz;84 this.platformCompatible = platformCompatible;85 this.serviceBinaries = serviceBinaries;86 this.propertyName = property;87 }88 private static AvailableDrivers getAvailableDriver(89 Class<? extends WebDriver> driverClass, Platform p) {90 AvailableDrivers[] availableDrivers = AvailableDrivers.values();91 for (AvailableDrivers availableDriver : availableDrivers) {92 if (!availableDriver.driverClazz.equals(driverClass)){93 continue;94 }95 96 for (Platform compatible: availableDriver.platformCompatible){97 if (p.is(compatible)){98 return availableDriver;99 }100 }101 }102 return null;103 }104 private void setSystemProperty(Platform p) {105 Platform platform = null;106 for (Platform compatible: platformCompatible){107 if (p.is(compatible)){108 platform = compatible;109 break;110 }111 }112 113 if ((platform != null) && (propertyName != null)114 && (serviceBinaries.get(platform) != null)) {115 System.setProperty(propertyName, serviceBinaries.get(platform)116 .getAbsolutePath());117 }118 }119 }120 121 public void setUp(Class<? extends WebDriver> driverClass) { 122 AvailableDrivers availableDriver = AvailableDrivers.getAvailableDriver(driverClass, current);123 if (availableDriver != null){124 availableDriver.setSystemProperty(current);125 }126 }127 128 private final Platform current = Platform.getCurrent();129 private final long IMPLICITLY_WAIT = 15;130 131 @FindBy(name = "q")132 @AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/someId\")")133 @iOSFindBy(uiAutomator = ".elements()[0]")134 private WebElement searchTextField;135 136 @AndroidFindBys({137 @AndroidFindBy(className = "someClass"),138 @AndroidFindBy(xpath = "//someTag")}) 139 @iOSFindBys({140 @iOSFindBy(xpath = "//selector[1]"),141 @iOSFindBy(xpath = "//someTag")})142 @FindBy(id="gbqfb")143 private RemoteWebElement searchButton;144 145 @AndroidFindBy(className = "someClass") 146 @iOSFindBys({147 @iOSFindBy(xpath = "//selector[1]"),148 @iOSFindBy(xpath = "//someTag")})149 @FindBys({@FindBy(className = "r"), @FindBy(tagName = "a")})150 private List<WebElement> foundLinks;151 152 private List<WebElement> ires; //this list is located by id="ires"153 private WebElement gbqfb; //this element is found by id="gbqfb"154 private WebDriver trap1;155 private List<AndroidDriver> trap2;156 157 private void test(WebDriver driver){158 try {159 PageFactory.initElements(new AppiumFieldDecorator(driver, IMPLICITLY_WAIT, TimeUnit.SECONDS), this);160 driver.get("https://www.google.com");161 searchTextField.sendKeys("Hello");162 searchButton.click();163 Assert.assertNotEquals(0, foundLinks.size());164 searchTextField.clear();165 searchTextField.sendKeys("Hello, Appium!");166 searchButton.click();167 Assert.assertNotEquals(0, foundLinks.size());168 Assert.assertNotEquals(0, ires.size());169 Assert.assertEquals(null, trap1);170 Assert.assertEquals(null, trap2);171 gbqfb.click();172 } finally {173 driver.quit();174 }175 }176 @Test177 public void fireFoxTest() {178 if (AvailableDrivers.getAvailableDriver(FirefoxDriver.class, current)!=null){179 setUp(FirefoxDriver.class);180 test(new FirefoxDriver());181 } 182 }183 184 @Test185 public void chromeTest() {186 System.getProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);187 if (AvailableDrivers.getAvailableDriver(ChromeDriver.class, current)!=null){188 setUp(ChromeDriver.class);189 test(new ChromeDriver());190 } 191 } 192 193 @Test194 public void ieTest() {195 if (AvailableDrivers.getAvailableDriver(InternetExplorerDriver.class, current)!=null){196 setUp(InternetExplorerDriver.class);197 test(new InternetExplorerDriver());198 } 199 } 200 201 @Test202 public void safariTest() {203 if (AvailableDrivers.getAvailableDriver(SafariDriver.class, current)!=null){204 setUp(SafariDriver.class);205 test(new SafariDriver());206 } 207 } 208}...
WebDriverType.java
Source:WebDriverType.java
...17import org.openqa.selenium.phantomjs.PhantomJSDriver;18import org.openqa.selenium.remote.CapabilityType;19import org.openqa.selenium.remote.DesiredCapabilities;20import org.openqa.selenium.remote.RemoteWebDriver;21import org.openqa.selenium.safari.SafariDriver;22import com.anik.selenium.model.enums.interfaces.DriverSetup;23import io.appium.java_client.android.AndroidDriver;24import io.appium.java_client.remote.AutomationName;25import io.appium.java_client.remote.MobileCapabilityType;26import io.appium.java_client.service.local.AppiumDriverLocalService;27import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;28import io.appium.java_client.service.local.AppiumServiceBuilder;29import io.github.bonigarcia.wdm.ChromeDriverManager;30import io.github.bonigarcia.wdm.FirefoxDriverManager;31import io.github.bonigarcia.wdm.InternetExplorerDriverManager;32import io.github.bonigarcia.wdm.OperaDriverManager;33import io.github.bonigarcia.wdm.PhantomJsDriverManager;34public enum WebDriverType implements DriverSetup {35 // FIREFOX {36 // @Override37 // public FirefoxDriver create() {38 // FirefoxDriverManager.getInstance().setup();39 /*40 * proxyServer.start();41 * proxyServer.setHarCaptureTypes(CaptureType.getAllContentCaptureTypes());42 * proxyServer.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT,43 * CaptureType.RESPONSE_CONTENT);44 * proxyServer.newHar(LocalDateTime.now().toString());45 * 46 * Proxy proxy = ClientUtil.createSeleniumProxy(proxyServer); FirefoxProfile47 * profile = new FirefoxProfile(); String host =48 * proxy.getHttpProxy().split(":")[0]; int port =49 * Integer.parseInt(proxy.getHttpProxy().split(":")[1]);50 * profile.setPreference("network.proxy.type", 1);51 * profile.setPreference("network.proxy.http", host);52 * profile.setPreference("network.proxy.http_port", port);53 * profile.setPreference("network.proxy.ssl", host);54 * profile.setPreference("network.proxy.ssl_port", port);55 * profile.setPreference("acceptInsecureCerts", true);56 */57 // DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();58 // desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS,59 // this.createBrowserLog());60 // desiredCapabilities.setAcceptInsecureCerts(true);61 // desiredCapabilities.setCapability(FirefoxDriver.PROFILE, profile);62 // FirefoxBinary firefoxBinary = new FirefoxBinary();63 // firefoxBinary.addCommandLineOptions("--headless");64 // return new FirefoxDriver(firefoxBinary);// desiredCapabilities);65 // }66 // },67 /*68 * CHROME {69 * 70 * @Override public ChromeDriver create() {71 * ChromeDriverManager.getInstance().setup(); ChromeOptions chromeOptions = new72 * ChromeOptions(); chromeOptions.addArguments("--start-maximized");73 * chromeOptions.addArguments("headless"); DesiredCapabilities74 * desiredCapabilities = DesiredCapabilities.chrome();75 * desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS,76 * this.createBrowserLog());77 * desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);78 * return new ChromeDriver(desiredCapabilities); } }, IE {79 * 80 * @Override public InternetExplorerDriver create() {81 * InternetExplorerDriverManager.getInstance().arch32().setup();82 * DesiredCapabilities desiredCapabilities =83 * DesiredCapabilities.internetExplorer();84 * desiredCapabilities.setCapability(InternetExplorerDriver.85 * INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); //86 * desiredCapabilities.setCapability("initialBrowserUrl", url);87 * desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS,88 * this.createBrowserLog()); return new89 * InternetExplorerDriver(desiredCapabilities); } }, OPERA {90 * 91 * @Override public OperaDriver create() {92 * OperaDriverManager.getInstance().setup(); OperaOptions operaOptions = new93 * OperaOptions(); operaOptions.setBinary(new94 * File(System.getProperty("opera"))); DesiredCapabilities capabilities =95 * DesiredCapabilities.operaBlink(); capabilities.setCapability("opera.no_quit",96 * false); capabilities.setCapability(OperaOptions.CAPABILITY, operaOptions);97 * return new OperaDriver(capabilities); } }, SAFARI {98 * 99 * @Override public SafariDriver create() { return new SafariDriver(); } },100 */101 ANDROID {102 @Override103 public AndroidDriver create() {104 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();105 desiredCapabilities.setCapability("deviceName", "Android Emulator");106 desiredCapabilities.setCapability("platformVersion", "6.0.1");107 desiredCapabilities.setCapability("platformName", "Android");108 desiredCapabilities.setCapability("appPackage", "com.habbitzz.app");109 desiredCapabilities.setCapability("appActivity", "com.habbitzz.app.nav.NavigationActivity");110 desiredCapabilities.setCapability("unicodeKeyboard", true);111 desiredCapabilities.setCapability("resetKeyboard", true);112 try {113 return new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);...
WebDriverConfig.java
Source:WebDriverConfig.java
...9import org.openqa.selenium.firefox.FirefoxDriver;10import org.openqa.selenium.remote.CommandExecutor;11import org.openqa.selenium.remote.DesiredCapabilities;12import org.openqa.selenium.remote.RemoteWebDriver;13import org.openqa.selenium.safari.SafariDriver;14import org.springframework.beans.factory.annotation.Value;15import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;16import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;17import org.springframework.context.annotation.Bean;18import org.springframework.context.annotation.Profile;19import io.appium.java_client.AppiumDriver;20import io.appium.java_client.MobileElement;21import io.appium.java_client.android.AndroidDriver;22import io.appium.java_client.ios.IOSDriver;23import io.appium.java_client.service.local.AppiumDriverLocalService;24import io.appium.java_client.service.local.AppiumServiceBuilder;25import io.github.bonigarcia.wdm.WebDriverManager;26import main.java.com.viacomcbs.PropertyConfig;27import main.java.com.viacomcbs.annotation.LazyAutowired;28import main.java.com.viacomcbs.annotation.LazyConfiguration;29import main.java.com.viacomcbs.annotation.ThreadBean;30import org.openqa.selenium.WebDriver;31/** NOTES -> Configuration of all drivers*/32@LazyConfiguration33public class WebDriverConfig {34 35 @LazyAutowired36 private WebDriver driver;37 private AppiumDriverLocalService AppiumService;38 @LazyAutowired39 Desired_Capabilities dc; 40 41 @LazyAutowired42 PropertyConfig config ;43 @ThreadBean44 public WebDriver setDriverPlatform(){45 switch(config.getConfig().getProperty("platform").toUpperCase())46 {47 case ("CHROME"):48 driver = chromeDriver();49 break; 50 case ("FIREFOX"): 51 driver = firefoxDriver();52 break;53 case ("SAFARI"): 54 driver = safariDriver();55 break;56 case ("EDGE"): 57 driver = edgeDriver();58 break;59 case ("ANDROID"): 60 driver = androidDriver();61 break;62 case ("IOS"): 63 driver = iosDriver();64 break;65 case ("CBT"):66 driver = crossBrowserTesting();67 break;68 default:69 // driver = chromeDriver();70 driver = crossBrowserTesting();71 break;72 }73 return driver ;74 } 75 /** NOTES -> Firefox driver*/76 public WebDriver firefoxDriver(){77 78 if(config.getConfig().getProperty("remote").toUpperCase().equals("ON")) {79 try {80 return new RemoteWebDriver(new URL(config.getConfig()81 .getProperty("selenium.grid.url")), DesiredCapabilities.firefox());82 } catch (MalformedURLException e) {83 e.printStackTrace();}84 }85 WebDriverManager.firefoxdriver().setup();86 return new FirefoxDriver(dc.FirefoxDesiredCap());}87 /** NOTES -> Chrome driver*/88 public WebDriver chromeDriver(){89 if(config.getConfig().getProperty("remote").toUpperCase().equals("ON")) {90 try {91 return new RemoteWebDriver(new URL(config.getConfig()92 .getProperty("selenium.grid.url")), DesiredCapabilities.chrome());93 } catch (MalformedURLException e) {94 e.printStackTrace();} }95 WebDriverManager.chromedriver().setup();96 return new ChromeDriver( dc.ChromeDesiredCap());}97 /** NOTES -> Safari driver*/98 public WebDriver safariDriver(){99 if(config.getConfig().getProperty("remote").toUpperCase().equals("ON")) {100 try {101 return new RemoteWebDriver(new URL(config.getConfig()102 .getProperty("selenium.grid.url")), DesiredCapabilities.safari());103 } catch (MalformedURLException e) {104 e.printStackTrace();} 105 } return new SafariDriver(dc.SafariDesiredCap());}106 107 /** NOTES -> Edge driver*/108 public WebDriver edgeDriver(){109 WebDriverManager.edgedriver();110 if(config.getConfig().getProperty("remote").toUpperCase().equals("ON")) {111 try {112 return new RemoteWebDriver(new URL(config.getConfig()113 .getProperty("selenium.grid.url")), DesiredCapabilities.edge());114 } catch (MalformedURLException e) {115 e.printStackTrace();} 116 } return new EdgeDriver(dc.EdgeDesiredCap());117 }118 /** NOTES -> Android driver*/119 public WebDriver androidDriver() {...
DriverManager.java
Source:DriverManager.java
...11import org.openqa.selenium.ie.InternetExplorerDriver;12import org.openqa.selenium.opera.OperaDriver;13import org.openqa.selenium.remote.DesiredCapabilities;14import org.openqa.selenium.remote.RemoteWebDriver;15import org.openqa.selenium.safari.SafariDriver;16import java.net.MalformedURLException;17import java.net.URL;18import java.util.logging.Level;19/*20 * This class is for initializing the RemoteWebDriver.21 * For specific mobile actions (e.g. TouchAction) , cast driver to AppiumDriver under CommonMethods class.22 */23public class DriverManager {24 protected static RemoteWebDriver driver;25 protected DesiredCapabilities dc;26 /**27 * This method calling driver initialize methods using given platform.28 */29 public void initDriver() {30 switch (Constants.PLATFORM.toLowerCase()) {31 case "web":32 Log.info("Initializing Web Driver");33 try {34 setWebDriver();35 driver.manage().window().maximize();36 } catch (RuntimeException e) {37 e.printStackTrace();38 Log.error("Web Driver Failure", e);39 }40 break;41 case "desktop":42 Log.info("Initializing Windows Driver");43 try {44 setWindowsDriver();45 } catch (MalformedURLException e) {46 e.printStackTrace();47 Log.error("Windows Driver Failure", e);48 }49 break;50 case "mobile":51 Log.info("Initializing Appium Driver");52 try {53 setAppiumDriver();54 } catch (MalformedURLException e) {55 e.printStackTrace();56 Log.error("Android Driver Failure", e);57 }58 break;59 }60 }61 /**62 * This method initialize web driver using given browser type.63 */64 private void setWebDriver() {65 switch (Constants.BROWSER_TYPE.toLowerCase()) {66 case "chrome":67 Log.info("Found chrome as Browser");68 WebDriverManager.chromedriver().setup();69 driver = new ChromeDriver();70 break;71 case "edge":72 WebDriverManager.edgedriver().setup();73 driver = new EdgeDriver();74 break;75 case "firefox":76 Log.info("Found firefox as Browser");77 WebDriverManager.firefoxdriver().setup();78 driver = new FirefoxDriver();79 break;80 case "ie":81 Log.info("Found IE as Browser");82 WebDriverManager.iedriver().setup();83 driver = new InternetExplorerDriver();84 break;85 case "safari":86 Log.info("Found safari as Browser");87 WebDriverManager.safaridriver().setup();88 driver = new SafariDriver();89 break;90 case "opera":91 Log.info("Found opera as Browser");92 WebDriverManager.operadriver().setup();93 driver = new OperaDriver();94 break;95 default:96 throw new RuntimeException("Unsupported Browser Type");97 }98 }99 /**100 * This method initialize the driver as WindowsDriver.101 *102 * @throws MalformedURLException Thrown to indicate that a malformed URL has occurred....
Drivers.java
Source:Drivers.java
...11import org.openqa.selenium.chrome.ChromeDriver;12import org.openqa.selenium.firefox.FirefoxDriver;13import org.openqa.selenium.ie.InternetExplorerDriver;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.safari.SafariDriver;16import org.slf4j.Logger;17import org.slf4j.LoggerFactory;18import test.DriverFactory;19import ui.app.android.AndroidUtility;20import utils.JavaWrappers;21import utils.OSValidator;22public class Drivers {23 private static Logger log = LoggerFactory.getLogger(Drivers.class);24 public String os = System.getProperty("os.name").toLowerCase();25 AndroidDriver androidDriver = null;26 IOSDriver iosDriver = null;27 AppiumDriver appiumDriver = null;28 WebDriver webDriver = null;29 ChromeDriver chromeDriver = null;30 FirefoxDriver firefoxDriver = null;31 SafariDriver safariDriver = null;32 InternetExplorerDriver internetExplorerDriver = null;33 public DesiredCapabilities desiredCapabilities = null;34 private static InheritableThreadLocal<WebDriver> driver = new InheritableThreadLocal<WebDriver>() {35 @Override36 protected WebDriver initialValue() {37 return null;38 }39 };40 private static InheritableThreadLocal<HashMap<Integer,AppiumDriverLocalService>> appiumServerService = new InheritableThreadLocal<HashMap<Integer,AppiumDriverLocalService>>() {41 @Override42 protected HashMap<Integer,AppiumDriverLocalService> initialValue() {43 return new HashMap<>();44 }45 };...
SafariDriver.java
Source:SafariDriver.java
...31 * for more details on how to configure and use it.32 *33 * @since Appium 1.20.034 */35public class SafariDriver extends AppiumDriver {36 private static final String PLATFORM_NAME = Platform.IOS.toString();37 private static final String AUTOMATION_NAME = AutomationName.SAFARI;38 public SafariDriver(HttpCommandExecutor executor, Capabilities capabilities) {39 super(executor, ensurePlatformAndAutomationNames(capabilities, PLATFORM_NAME, AUTOMATION_NAME));40 }41 public SafariDriver(URL remoteAddress, Capabilities capabilities) {42 super(remoteAddress, ensurePlatformAndAutomationNames(43 capabilities, PLATFORM_NAME, AUTOMATION_NAME));44 }45 public SafariDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities capabilities) {46 super(remoteAddress, httpClientFactory, ensurePlatformAndAutomationNames(47 capabilities, PLATFORM_NAME, AUTOMATION_NAME));48 }49 public SafariDriver(AppiumDriverLocalService service, Capabilities capabilities) {50 super(service, ensurePlatformAndAutomationNames(51 capabilities, PLATFORM_NAME, AUTOMATION_NAME));52 }53 public SafariDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,54 Capabilities capabilities) {55 super(service, httpClientFactory, ensurePlatformAndAutomationNames(56 capabilities, PLATFORM_NAME, AUTOMATION_NAME));57 }58 public SafariDriver(AppiumServiceBuilder builder, Capabilities capabilities) {59 super(builder, ensurePlatformAndAutomationNames(60 capabilities, PLATFORM_NAME, AUTOMATION_NAME));61 }62 public SafariDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,63 Capabilities capabilities) {64 super(builder, httpClientFactory, ensurePlatformAndAutomationNames(65 capabilities, PLATFORM_NAME, AUTOMATION_NAME));66 }67 public SafariDriver(HttpClient.Factory httpClientFactory, Capabilities capabilities) {68 super(httpClientFactory, ensurePlatformAndAutomationNames(69 capabilities, PLATFORM_NAME, AUTOMATION_NAME));70 }71 public SafariDriver(Capabilities capabilities) {72 super(ensurePlatformAndAutomationNames(capabilities, PLATFORM_NAME, AUTOMATION_NAME));73 }74}...
BaseTestPage.java
Source:BaseTestPage.java
...11import org.openqa.selenium.ie.InternetExplorerDriver;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.remote.RemoteWebDriver;14import org.openqa.selenium.remote.UnreachableBrowserException;15import org.openqa.selenium.safari.SafariDriver;16import com.ppsf.elementfactory.ElementFactory;1718import io.appium.java_client.ios.IOSDriver;19import io.appium.java_client.service.local.AppiumDriverLocalService;2021public class BaseTestPage {22 23 public static WebDriver driver;24 25 public BaseTestPage (){26 27 //PageFactory.initElements(driver, this);28 ElementFactory.initElements(driver, this);29 }3031 public static void InstantiateWebDriver () throws IOException32 {33 34 String sBrowserName = DesiredCapabilities.firefox().getBrowserName();35 DesiredCapabilities oCapability = new DesiredCapabilities();36 37 oCapability.setBrowserName(sBrowserName);38 39 DesiredCapabilities capabilities = new DesiredCapabilities();40 capabilities.setCapability("deviceName", "iPhone 6 Plus");41 capabilities.setCapability("platformName", "iOS");42 capabilities.setCapability("platformVersion", "9.2");43 capabilities.setCapability("browserName", "safari");44 AppiumDriverLocalService service=null;45 46 try{ 47 driver = new RemoteWebDriver(new URL(ConfigurationManager.getProperty ("sHubURL")), oCapability);48 System.out.println("Running via Selenium GRID");49 }50 catch (UnreachableBrowserException e){51 switch (ConfigurationManager.getProperty ("driver.name")) {52 53 case "chromeDriver":54 System.setProperty("webdriver.chrome.driver", new File(ConfigurationManager.getProperty ("webdriver.chrome.driver")).getCanonicalPath());55 driver = new ChromeDriver ();56 break;57 58 case "firefoxDriver":59 driver = new FirefoxDriver();60 break;61 62 case "ieDriver":63 System.setProperty("webdriver.ie.driver", new File(ConfigurationManager.getProperty ("webdriver.ie.driver")).getCanonicalPath());64 driver = new InternetExplorerDriver ();6566 break;67 68 case "safariDriver":69 driver = new SafariDriver ();7071 break;72 73 case "appiumDriver":74 //driver = new RemoteWebDriver(new URL(ConfigurationManager.getProperty ("AppiumServerURL")), oCapability);75 service = AppiumDriverLocalService.buildDefaultService();76 service.start();77 driver = new IOSDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);7879 break;8081 default:82 throw new TAFException.GENERAL_SCRIPT_ERROR("driver.name: "+ConfigurationManager.getProperty ("driver.name")+"is not supported. "83 + "Supported values: chromeDriver, appiumDriver, safariDriver, ieDriver & firefoxDriver");
...
SafariDriver
Using AI Code Generation
1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.concurrent.TimeUnit;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.testng.annotations.AfterTest;7import org.testng.annotations.BeforeTest;8import org.testng.annotations.Test;9import io.appium.java_client.ios.IOSDriver;10import io.appium.java_client.ios.IOSElement;11import io.appium.java_client.remote.MobileCapabilityType;12public class AppiumTest {13 IOSDriver<IOSElement> driver;14 public void setup() throws MalformedURLException {15 DesiredCapabilities caps = new DesiredCapabilities();16 caps.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6");17 caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");18 caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.3");19 caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
SafariDriver
Using AI Code Generation
1import io.appium.java_client.safari.SafariDriver;2import io.appium.java_client.ios.IOSDriver;3import java.net.URL;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.remote.DesiredCapabilities;7public class Safari {8 public static void main(String[] args) throws Exception {9 DesiredCapabilities capabilities = new DesiredCapabilities();10 capabilities.setCapability("platformName", "iOS");11 capabilities.setCapability("platformVersion", "8.4");12 capabilities.setCapability("deviceName", "iPhone Simulator");13 capabilities.setCapability("browserName", "Safari");14 capabilities.setCapability("autoAcceptAlerts", true);15 capabilities.setCapability("autoDismissAlerts", true);16 capabilities.setCapability("safariAllowPopups", true);17 capabilities.setCapability("safariIgnoreFraudWarning", true);18 capabilities.setCapability("safariOpenLinksInBackground", true);19 capabilities.setCapability("nativeWebTap", true);20 capabilities.setCapability("safariAllowPopups", true);21 capabilities.setCapability("safariIgnoreFraudWarning", true);22 capabilities.setCapability("safariOpenLinksInBackground", true);23 capabilities.setCapability("nativeWebTap", true);24 capabilities.setCapability("safariAllowPopups", true);25 capabilities.setCapability("safariIgnoreFraudWarning", true);26 capabilities.setCapability("safariOpenLinksInBackground", true);27 capabilities.setCapability("nativeWebTap", true);28 capabilities.setCapability("safariAllowPopups", true);29 capabilities.setCapability("safariIgnoreFraudWarning", true);30 capabilities.setCapability("safariOpenLinksInBackground", true);31 capabilities.setCapability("nativeWebTap", true);
SafariDriver
Using AI Code Generation
1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.openqa.selenium.safari.SafariDriver;6public class safari {7public static void main(String[] args) throws MalformedURLException {8DesiredCapabilities capabilities = new DesiredCapabilities();9capabilities.setCapability("deviceName", "iPhone 6");10capabilities.setCapability("platformName", "iOS");11capabilities.setCapability("platformVersion", "8.1");12capabilities.setCapability("browserName", "Safari");
SafariDriver
Using AI Code Generation
1SafariDriver driver = new SafariDriver();2SafariOptions safariOptions = new SafariOptions();3safariOptions.setUseCleanSession(true);4safariOptions.setUseTechnologyPreview(true);5safariOptions.setTechnologyPreview(true);6safariOptions.setUseTechnologyPreview(true);
SafariDriver
Using AI Code Generation
1package appium.java;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.safari.SafariDriver;5import org.openqa.selenium.safari.SafariOptions;6public class SafariTest {7 public static void main(String[] args) {8 WebDriver driver;9 DesiredCapabilities capabilities = DesiredCapabilities.safari();10 SafariOptions options = new SafariOptions();11 options.setUseCleanSession(true);12 capabilities.setCapability(SafariOptions.CAPABILITY, options);13 driver = new SafariDriver(capabilities);14 System.out.println("Title of the page is : " + driver.getTitle());15 driver.quit();16 }
SafariDriver
Using AI Code Generation
1package appium;2import io.appium.java_client.safari.SafariDriver;3import java.net.URL;4import java.net.MalformedURLException;5import org.openqa.selenium.remote.DesiredCapabilities;6public class SafariDriverTest {7public static void main(String[] args) throws MalformedURLException {8DesiredCapabilities capabilities = new DesiredCapabilities();9capabilities.setCapability("deviceName", "iPhone 6");10capabilities.setCapability("browserName", "Safari");11capabilities.setCapability("platformVersion", "9.3");12capabilities.setCapability("platformName", "iOS");13capabilities.setCapability("appPackage", "com.apple.mobilesafari");14capabilities.setCapability("appActivity", "com.apple.mobilesafari");
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!!