Best io.appium code snippet using io.appium.java_client.gecko.GeckoDriver
BrowserController.java
Source:BrowserController.java
...60 /**61 * Solution62 * Upgrade JDK to recent levels JDK 8u191.63 * Upgrade Selenium to current levels Version 3.14.0.64 * Upgrade GeckoDriver to GeckoDriver v0.23.0 level.65 * GeckoDriver is present in the specified location.66 * GeckoDriver is having executable permission for non-root users.67 * Upgrade Firefox version to Firefox v63.0.1 levels.68 * Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.69 * If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.70 * Take a System Reboot.71 * Execute your Test as a non-root user.72 * Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.73 */74 FirefoxOptions firefoxOptions = new FirefoxOptions();75 firefoxOptions.setCapability("marionette", true);76 firefoxOptions.setBinary(properties.getProperty(TestProperties.WEBDRIVER_GECKO_BINARY));77 System.setProperty(TestProperties.GECKO_DRIVER, properties.getProperty(TestProperties.GECKO_DRIVER_PATH));78 driver = new EventFiringWebDriver(new FirefoxDriver(firefoxOptions));79 threadLocalDriver.set(driver);80 driver.manage().window().maximize();...
WebDrivers.java
Source:WebDrivers.java
1package baseFrame.commonUtils;2import baseFrame.webUtils.WebConf;3import io.appium.java_client.AppiumDriver;4import io.appium.java_client.android.AndroidDriver;5import io.appium.java_client.android.AndroidElement;6import org.apache.log4j.Logger;7import org.openqa.selenium.Platform;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.chrome.ChromeDriver;10import org.openqa.selenium.firefox.FirefoxBinary;11import org.openqa.selenium.firefox.FirefoxDriver;12import org.openqa.selenium.firefox.FirefoxProfile;13import org.openqa.selenium.ie.InternetExplorerDriver;14import org.openqa.selenium.remote.BrowserType;15import org.openqa.selenium.remote.DesiredCapabilities;16import java.net.MalformedURLException;17import java.net.URL;18import java.util.concurrent.TimeUnit;19/**20 * WebDriverå·¥åç±»,æ ¹æ®webConf.propertiesä¸é
ç½®çbrowseræ¥çæç¸åºçWebDriver21 */22public class WebDrivers {23 private static final Logger logger = Logger.getLogger(WebDrivers.class);24 public void WebDrivers(){}25 private static WebDriver driver;26 private static AppiumDriver<AndroidElement> appdriver;27 public static WebDriver getWebDriver() {28 setDriver();29 return driver;30 }31 public static AppiumDriver getAppDriver() {32 setDriver();33 return appdriver;34 }35 /**36 * æ ¹æ®Configuratoré
ç½®çbrowserNameæ¥è·åç¸åºçWebDriver37 */38 public static void setDriver() {39 if (driver != null || appdriver != null) {40 return ;41 }42 setDriver(new DesiredCapabilities(WebConf.getProperty("browser"),"", Platform.getCurrent()));43 }44 private static void setDriver(DesiredCapabilities desiredCapabilities) {45 String appium_url = WebConf.getProperty("appium.url");46 if (appium_url != null && !appium_url.equals("")) {47 setAppDriver(appium_url);48 return;49 }50 String browser = desiredCapabilities.getBrowserName();51 String osname = System.getProperty("os.name");52 String arch = "";53 if (browser.toLowerCase().equals(BrowserType.CHROME)) {54 setChromeDriver(desiredCapabilities, osname, arch);55 } else if (browser.toLowerCase().equals(BrowserType.FIREFOX)) {56 setFireFoxDriver(desiredCapabilities, osname, arch);57 } else if (browser.toLowerCase().equals(BrowserType.IE)) {58 setIEDriver(desiredCapabilities, osname, arch);59 } else {60 logger.warn(browser + " is NOT SUPPORTED!!! Use IE as default!");61 setIEDriver(desiredCapabilities, osname, arch);62 }63 }64 private static void setAppDriver(String appium_url) {65 String appium_version = WebConf.getProperty("capability.appium-version");66 String platformName = WebConf.getProperty("capability.platformName");67 String platformVersion = WebConf.getProperty("capability.platformVersion");68 String deviceName = WebConf.getProperty("capability.deviceName");69 String app = WebConf.getProperty("capability.app");70 String appPackage = WebConf.getProperty("capability.appPackage");71 String appActivity = WebConf.getProperty("capability.appActivity");72 String unicodeKeyboard= WebConf.getProperty("capability.unicodeKeyboard") ;73 String resetKeyboard= WebConf.getProperty("capability.resetKeyboard") ;74 if (platformName.toLowerCase().trim().equals("android")) {75 DesiredCapabilities cap = new DesiredCapabilities();76 cap.setCapability("appium_version", appium_version);77 cap.setCapability("platformName", platformName);78 cap.setCapability("platformVersion", platformVersion);79 cap.setCapability("deviceName", deviceName);80 cap.setCapability("app", app);81 cap.setCapability("appPackage", appPackage);82 cap.setCapability("appActivity", appActivity);83 // cap.setCapability("unicodeKeyboard", unicodeKeyboard);84 // cap.setCapability("resetKeyboard", resetKeyboard);85 AppiumDriver wd = null;86 try {87 wd = new AndroidDriver(new URL(appium_url), cap);88 } catch (MalformedURLException e) {89 e.printStackTrace();90 }91 wd.manage().timeouts().implicitlyWait(180, TimeUnit.SECONDS);92 appdriver = wd;93// return wd;94 } else {95 //leave for dealing with ios96// return null;97 }98 }99 private static void setChromeDriver(DesiredCapabilities desiredCapabilities, String osname, String arch) {100 String driverpath = "src/main/resources/drivers/chrome/";101 if (osname.equals("Mac OS X")) {102 driverpath += "chromedriver_mac";103 } else if (osname.equals("linux")) {104 if (arch.equals("x86_64")) {105 driverpath += "chromedriver_linux64";106 } else {107 driverpath += "chromedriver_linux32";108 }109 } else {110 //as windows111 driverpath += "chromedriver.exe";112 }113 logger.info("set Chrome driver: ostype " + osname + ", arch " + arch);114 System.setProperty("webdriver.chrome.driver", driverpath);115 driver = new ChromeDriver(desiredCapabilities);116// return driver;117 }118 private static void setFireFoxDriver(DesiredCapabilities desiredCapabilities, String osname, String arch) {119 String driverpath = "src/main/resources/drivers/firefox/";120 if (osname.equals("Mac OS X")) {121 driverpath += "geckodriver_mac";122 } else if (osname.equals("linux")) {123 driverpath += "geckodriver_linux64";124 } else {125 //as windows126 driverpath += "geckodriver.exe";127 }128 logger.info("set FIREFOX driver: ostype " + osname + ", arch " + arch);129 System.setProperty("webdriver.gecko.driver", driverpath);130 FirefoxProfile profile = new FirefoxProfile();131 profile.setAcceptUntrustedCertificates(true);132 profile.setAssumeUntrustedCertificateIssuer(false);133 driver = new FirefoxDriver(new FirefoxBinary(), profile, desiredCapabilities);134// driver = new FirefoxDriver(desiredCapabilities);135// return driver;136 }137 /**138 * 设置IE driver,åæ¶ä¿æ¤æ¨¡å¼139 * @param desiredCapabilities140 * @return141 */142 private static void setIEDriver(DesiredCapabilities desiredCapabilities, String osname, String arch) {143 String driverpath = "src/main/resources/drivers/ie/";144 if (arch.equals("64")) {145 driverpath += "IEDriverServer_x64.exe";146 } else {147 //as 32bit arch148 driverpath += "IEDriverServer_32.exe";149 }150 logger.info("set IE driver: ostype " + osname + ", arch " + arch);151 System.setProperty("webdriver.ie.driver", driverpath);152 desiredCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);153 driver = new InternetExplorerDriver(desiredCapabilities);154// return driver;155 }156}...
Base.java
Source:Base.java
1package com.Base;2import com.github.mkolisnyk.cucumber.runner.BeforeSuite;3import com.github.mkolisnyk.cucumber.runner.ExtendedCucumber;4import com.github.mkolisnyk.cucumber.runner.AfterSuite;5import com.github.mkolisnyk.cucumber.runner.*;6import com.google.common.base.Objects;7import org.openqa.selenium.firefox.FirefoxDriver;8import com.utils.AppiumServerAppiumDriverLocalService;9import com.utils.CreateFolder;10import com.utils.JsonParsers;11import com.utils.SeleniumMethodes;12import cucumber.api.CucumberOptions;13import io.appium.java_client.AppiumDriver;14import io.appium.java_client.MobileElement;15import io.appium.java_client.android.AndroidDriver;16import io.appium.java_client.ios.IOSDriver;17import io.appium.java_client.service.local.AppiumDriverLocalService;18import org.junit.runner.RunWith;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.chrome.ChromeDriver;21import org.openqa.selenium.firefox.FirefoxDriver;22import org.openqa.selenium.remote.DesiredCapabilities;23import org.openqa.selenium.support.ui.WebDriverWait;24import org.testng.annotations.Test;25import java.net.URL;26import java.util.HashMap;27import java.util.HashSet;28import java.util.Map;29import java.util.Set;30import java.util.concurrent.TimeUnit;31//import com.github.mkolisnyk.cucumber.runner.ExtendedCucumberOptions;32@RunWith(ExtendedCucumber.class)33@ExtendedCucumberOptions(34 //reportPrefix = "NGMS-iOS-Automation",35// reportPrefix = "${NGMSAppBuildNumber}",36 jsonReport = "target/cucumber.json",37 retryCount = 0,38 screenShotSize = "100px",39 screenShotLocation = "Screenshots/",40 detailedReport = true,41 detailedAggregatedReport = true,42 //breakdownReport = true,43 //featureMapReport = true,44 //knownErrorsReport = true,45 //consolidatedReport = true,46 systemInfoReport = true,47 overviewReport = true,48 coverageReport = true,49 jsonUsageReport = "target/cucumber-usage.json",50 usageReport = true,51 toPDF = true,52 overviewChartsReport = true,53 pdfPageSize = "A4 Landscape",54 outputFolder = "./${ReportsFolder}/"55)56@CucumberOptions(57 strict = true,58 monochrome = true,59 dryRun = false,60 features = "src/main/resources/FeaturesFile",61 glue = "com.StepDefination",62 tags = "@cleartrip",63 plugin = {"html:target/cucumber-html-report",64 "json:target/cucumber.json", "pretty:target/cucumber-pretty.txt",65 "usage:target/cucumber-usage.json", "junit:target/cucumber-results.xml"66 }67)68public class Base {69 public static DesiredCapabilities dc;70 public static AppiumDriver<MobileElement> driver = null;71 public static WebDriver chromedriver;72 public static WebDriverWait wait;73 public static HashMap<String, String> map_OR = null;74 public static String ReportsFolder = null;75 public static String strFolderName = null;76 public static AppiumServerAppiumDriverLocalService appiumserver;77 public static AppiumDriverLocalService service;78 public static Map<String, String> mapDesiredCapabilities = null;79 static int port = 4743;80 public static SeleniumMethodes seleniumMethods = new SeleniumMethodes();81 @BeforeSuite82 public static void test() throws Exception{83 System.out.println("Base class execution");84 String strFolderName = CreateFolder.getDateTime();85 System.setProperty("ReportsFolder", CreateFolder.createFolder("Reports", strFolderName));86 mapDesiredCapabilities = JsonParsers.generateMapDesiredCapabilities("DesiredCapabilities");87 mapDesiredCapabilities.put("app", System.getProperty("user.dir") + "/src/main/resources/Amazon.apk");88// System.setProperty("driver",System.getProperty("user.dir")+"Downloads/geckodriver 2");89 System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+ "/src/main/resources/DriversFile/geckodriver");90// appiumserver = new AppiumServerAppiumDriverLocalService(port);91// if (!appiumserver.checkIfServerIsRunnning(port)) {92// service = appiumserver.startServer();93// System.out.println("Appium server is now start");94// } else {95// System.out.println("appium server is already running");96// }97// System.setProperty("platformName", mapDesiredCapabilities.get("platformName"));98// if (Objects.equal(mapDesiredCapabilities.get("platformName"), "iOS")) {99// driver = new IOSDriver<MobileElement>(service.getUrl(), JsonParsers.setCapabalities(mapDesiredCapabilities));100// } else if (Objects.equal(mapDesiredCapabilities.get("platformName"), "Android")) {101// driver = new AndroidDriver<MobileElement>(service.getUrl(), JsonParsers.setCapabalities(mapDesiredCapabilities));102// } else {103// System.out.println("Unknown Device Platform in Desired Capabilites sheet, please update it and reexecute");104// System.exit(1);105// }106 map_OR = JsonParsers.jsontoMap("ObjectRepository");107 // driver=new ChromeDriver();108 dc = new DesiredCapabilities();109 dc.setCapability("marionette", true);110 dc.setCapability("acceptInsecureCerts", true);111 dc.setCapability("browserName", "firefox");112 chromedriver=new FirefoxDriver();113 chromedriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);114// chromedriver.get("https://www.cleartrip.com/");115 }116 @AfterSuite117 public void afterSuite() {118 chromedriver.quit();119 System.out.println("after suite");120 appiumserver.stopServer(service);121 }122}...
BaseClass.java
Source:BaseClass.java
1/**2 * 3 */4package com.AppiumGrid.baseclass;5import java.net.MalformedURLException;6import java.net.URL;7import java.util.concurrent.TimeUnit;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.chrome.ChromeDriver;10import org.openqa.selenium.firefox.FirefoxDriver;11import org.openqa.selenium.remote.DesiredCapabilities;12import org.testng.annotations.AfterClass;13import org.testng.annotations.AfterTest;14import org.testng.annotations.BeforeClass;15import org.testng.annotations.BeforeTest;16import org.testng.annotations.Optional;17import org.testng.annotations.Parameters;18import com.AppiumGrid.utlity.GlobalParameters;19import io.appium.java_client.MobileElement;20import io.appium.java_client.android.AndroidDriver;21import io.appium.java_client.service.local.AppiumDriverLocalService;22import io.appium.java_client.service.local.AppiumServiceBuilder;23import io.appium.java_client.service.local.flags.GeneralServerFlag;24/**25 * @author CHIRAG26 *27 */28public class BaseClass {29 private static WebDriver driver;30 private AppiumDriverLocalService service;31 private AppiumServiceBuilder server;32 33 String platformRunAs;34 /*35 * myPlatform should be web or mobile36 * 37 */38 final String myPlatform = "web";39 40 41 @Parameters({"platform","runOn"})42 @BeforeClass43 public void setup(@Optional(myPlatform)String platform, @Optional("chrome_normal")String runOn) throws MalformedURLException44 {45 System.out.println(platform);46 GlobalParameters.runType = platform;47 String path = System.getProperty("user.dir");48 switch (platform) {49 case "web":50 51 if(runOn.equalsIgnoreCase("chrome"))52 {53 System.out.println("Chrome Browser is opening..... ");54 System.setProperty("webdriver.chrome.driver", path+"//drivers//chromedriver.exe");55 driver= new ChromeDriver();56 }else if(runOn.equalsIgnoreCase("firefox"))57 {58 System.out.println("Firefox Browser is opening..... ");59 System.setProperty("webdriver.gecko.driver", path+"//drivers//geckodriver.exe");60 driver= new FirefoxDriver();61 }62 driver.manage().window().maximize();63 driver.get("https://wordpress.com");64 driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);65 break;66 case "mobile":67 System.out.println("Application is opening... ");68 DesiredCapabilities cap = new DesiredCapabilities();69 cap.setCapability("app", path+"//App//wordpress.apk");70 cap.setCapability("platformName", "Android");71 cap.setCapability("deviceName", "HTC Desire 626 dual sim");72 cap.setCapability("appWaitActivity", "org.wordpress.android.ui.accounts.SignInActivity");73 cap.setCapability("appPackage", "org.wordpress.android");74 if(runOn.equals("192.168.56.101:5555"))75 {76 cap.setCapability("udid", "192.168.56.101:5555");77 driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4729/wd/hub"), cap);78 }else if(runOn.equals("LC62TYT08029"))79 {80 cap.setCapability("udid", "LC62TYT08029");81 driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4726/wd/hub"), cap);82 }else if(platformRunAs.equals("mobile"))83 {84 driver = new AndroidDriver<MobileElement>(service.getUrl(), cap);85 }86 System.out.println("mobile will launch");87 driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);88 break;89 default:90 System.out.println("Incorrect Platform...");91 break;92 } 93 94 }95 @AfterClass96 public void tearDown()97 {98 //driver.quit();99 /*if(mobileRunAs.equals("normal"))100 {101 //driver.quit();102 }*/103 104 }105 public WebDriver getDriver()106 {107 return this.driver;108 }109 @Parameters({"runAs"})110 @BeforeTest111 public void startAppoumserver(@Optional(myPlatform)String platform)112 {113 System.out.println(platform);114 if(platform.equalsIgnoreCase("mobile"))115 {116 platformRunAs="mobile";117 server = new AppiumServiceBuilder();118 server.usingAnyFreePort();119 server.withArgument(GeneralServerFlag.SESSION_OVERRIDE);120 server.withArgument(GeneralServerFlag.LOG_LEVEL, "error:error");121 service = AppiumDriverLocalService.buildService(server);122 service.start();123 System.out.println("Appium Server is Started...");124 }125 }126 @Parameters({"runAs"})127 @AfterTest128 public void stopAppiumServer(@Optional(myPlatform) String platform)129 {130 if(platform.equalsIgnoreCase("mobile"))131 {132 service.stop();133 System.out.println("Appium Server is Stoped...");134 }135 }136}...
GeckoDriver.java
Source:GeckoDriver.java
...22import org.openqa.selenium.remote.HttpCommandExecutor;23import org.openqa.selenium.remote.http.HttpClient;24import java.net.URL;25/**26 * GeckoDriver is an officially supported Appium driver27 * created to automate Mobile browsers and web views based on28 * the Gecko engine. The driver uses W3C29 * WebDriver protocol and is built on top of Mozilla's geckodriver30 * server. Read https://github.com/appium/appium-geckodriver31 * for more details on how to configure and use it.32 *33 * @since Appium 1.20.034 */35public class GeckoDriver extends AppiumDriver {36 private static final String AUTOMATION_NAME = AutomationName.GECKO;37 public GeckoDriver(HttpCommandExecutor executor, Capabilities capabilities) {38 super(executor, ensureAutomationName(capabilities, AUTOMATION_NAME));39 }40 public GeckoDriver(URL remoteAddress, Capabilities capabilities) {41 super(remoteAddress, ensureAutomationName(capabilities, AUTOMATION_NAME));42 }43 public GeckoDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities capabilities) {44 super(remoteAddress, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME));45 }46 public GeckoDriver(AppiumDriverLocalService service, Capabilities capabilities) {47 super(service, ensureAutomationName(capabilities, AUTOMATION_NAME));48 }49 public GeckoDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,50 Capabilities capabilities) {51 super(service, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME));52 }53 public GeckoDriver(AppiumServiceBuilder builder, Capabilities capabilities) {54 super(builder, ensureAutomationName(capabilities, AUTOMATION_NAME));55 }56 public GeckoDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,57 Capabilities capabilities) {58 super(builder, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME));59 }60 public GeckoDriver(HttpClient.Factory httpClientFactory, Capabilities capabilities) {61 super(httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME));62 }63 public GeckoDriver(Capabilities capabilities) {64 super(ensureAutomationName(capabilities, AUTOMATION_NAME));65 }66}...
DriverFactory.java
Source:DriverFactory.java
1package TestPackageDetail;23import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.firefox.FirefoxDriver;6import org.openqa.selenium.remote.BrowserType;7import org.openqa.selenium.remote.DesiredCapabilities;8import io.appium.java_client.MobileElement;9import io.appium.java_client.android.AndroidDriver;10import io.appium.java_client.remote.MobileCapabilityType;11import io.appium.java_client.service.local.AppiumDriverLocalService;12import io.appium.java_client.service.local.AppiumServiceBuilder;1314import java.io.File;15import java.net.MalformedURLException;16import java.net.URL;1718public class DriverFactory {1920 public static WebDriver driver = null;2122 public static WebDriver createInstance(String browser, String platform, String device_name, String port,23 String udid) throws MalformedURLException, InterruptedException {24 if (!platform.equals("android")) {25 if (browser.equalsIgnoreCase("chrome") & !platform.equals("android")) {26 System.setProperty("webdriver.chrome.driver",27 "C:\\Users\\ab36194\\git\\TestAutothon\\Drivers\\chromedriver.exe");28 driver = new ChromeDriver();29 return driver;30 } else if (browser.equalsIgnoreCase("firefox")) {31 System.setProperty("webdriver.gecko.driver",32 "C:\\Users\\ab36194\\git\\TestAutothon\\Drivers\\geckodriver.exe");33 driver = new FirefoxDriver();34 return driver;35 } else {36 System.setProperty("webdriver.gecko.driver",37 "C:\\Users\\ab36194\\git\\TestAutothon\\Drivers\\geckodriver.exe");38 driver = new FirefoxDriver();39 return driver;40 }41 } else {42 43 int portNo=Integer.parseInt(port);4445 AppiumDriverLocalService appiumService = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()46 .usingPort(portNo).usingDriverExecutable(new File("C://Program Files (x86)//Appium//node.exe"))47 .withAppiumJS(new File("C:\\Program Files (x86)\\Appium\\node_modules\\appium\\bin\\appium.js")));48 appiumService.start();4950 DesiredCapabilities capabilities = DesiredCapabilities.android();51 String browserType = browser.toLowerCase();52 capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, browserType);53 capabilities.setCapability("udid", udid);54 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");55 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, device_name);56 capabilities.setCapability(MobileCapabilityType.VERSION, "8.1.0");57 {58 URL url = null;59 try {60 url = new URL("http://0.0.0.0:" + port + "/wd/hub"); // 16265 472361 } catch (MalformedURLException e) {62 e.printStackTrace();63 }64 WebDriver driver = new AndroidDriver<MobileElement>(url, capabilities);65 return driver;66 }67 }68 }69}
...
GeckoOptions.java
Source:GeckoOptions.java
1/*2 * Licensed under the Apache License, Version 2.0 (the "License");3 * you may not use this file except in compliance with the License.4 * See the NOTICE file distributed with this work for additional5 * information regarding copyright ownership.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.appium.java_client.gecko.options;17import io.appium.java_client.mac.options.SupportsSystemPortOption;18import io.appium.java_client.remote.AutomationName;19import io.appium.java_client.remote.options.BaseOptions;20import io.appium.java_client.remote.options.SupportsAcceptInsecureCertsOption;21import io.appium.java_client.remote.options.SupportsBrowserNameOption;22import io.appium.java_client.remote.options.SupportsBrowserVersionOption;23import io.appium.java_client.remote.options.SupportsPageLoadStrategyOption;24import io.appium.java_client.remote.options.SupportsProxyOption;25import io.appium.java_client.remote.options.SupportsSetWindowRectOption;26import io.appium.java_client.remote.options.SupportsUnhandledPromptBehaviorOption;27import org.openqa.selenium.Capabilities;28import java.util.Map;29/**30 * https://github.com/appium/appium-geckodriver#usage31 */32public class GeckoOptions extends BaseOptions<GeckoOptions> implements33 SupportsBrowserNameOption<GeckoOptions>,34 SupportsBrowserVersionOption<GeckoOptions>,35 SupportsMarionettePortOption<GeckoOptions>,36 SupportsSystemPortOption<GeckoOptions>,37 SupportsVerbosityOption<GeckoOptions>,38 SupportsAndroidStorageOption<GeckoOptions>,39 SupportsMozFirefoxOptionsOption<GeckoOptions>,40 SupportsAcceptInsecureCertsOption<GeckoOptions>,41 SupportsPageLoadStrategyOption<GeckoOptions>,42 SupportsSetWindowRectOption<GeckoOptions>,43 SupportsProxyOption<GeckoOptions>,44 SupportsUnhandledPromptBehaviorOption<GeckoOptions> {45 public GeckoOptions() {46 setCommonOptions();47 }48 public GeckoOptions(Capabilities source) {49 super(source);50 setCommonOptions();51 }52 public GeckoOptions(Map<String, ?> source) {53 super(source);54 setCommonOptions();55 }56 private void setCommonOptions() {57 setAutomationName(AutomationName.GECKO);58 }59}...
OpenApp.java
Source:OpenApp.java
1package com.appiumTest;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.HashMap;5import java.util.Map;6import org.openqa.selenium.By;7import org.openqa.selenium.chrome.ChromeOptions;8import org.openqa.selenium.remote.DesiredCapabilities;9import org.openqa.selenium.remote.RemoteWebDriver;10import org.testng.annotations.BeforeClass;11import io.appium.java_client.android.AndroidDriver;12import io.appium.java_client.remote.MobileCapabilityType;13public class OpenApp 14{15 static 16 {17 System.setProperty("webdriver.gecko.driver", "/home/pavithra/Downloads/Pavithra/geckodriver");18 System.setProperty("webdriver.chrome.driver", "//home/pavithra/Downloads/Pavithra/chromedriver");19 }20 @SuppressWarnings("rawtypes")21 AndroidDriver driver;22 23 @SuppressWarnings("rawtypes")24 @BeforeClass25 public static void main(String[] args) throws MalformedURLException, InterruptedException 26 {27 DesiredCapabilities caps = new DesiredCapabilities();28 caps.setCapability("udid", "J8AAGF075449GVP"); //Give Device ID of your mobile phone29 caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");30 caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");31 caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");32 caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, 9.0);33 caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");34 caps.setCapability("app", "/home/pavithra/eclipse-workspace/selenenium/apk/selendroid-test-app-0.12.0.apk");35 caps.setCapability("appWaitDuration",30000);36 caps.setCapability("adbExecTimeout",300000);37 38 RemoteWebDriver driver= new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"),caps); 39 40 Thread.sleep(5000);41 driver.close();42 } 43}...
GeckoDriver
Using AI Code Generation
1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setCapability("marionette", true);3capabilities.setCapability("moz:firefoxOptions", new FirefoxOptions().setLegacy(true));4capabilities.setCapability("platformName", "Android");5capabilities.setCapability("deviceName", "Android Emulator");6capabilities.setCapability("appPackage", "org.mozilla.gecko");7capabilities.setCapability("appActivity", "org.mozilla.gecko.BrowserApp");8capabilities.setCapability("automationName", "uiautomator2");9capabilities.setCapability("noReset", true);10capabilities.setCapability("fullReset", false);11capabilities.setCapability("browserName", "Firefox");12capabilities.setCapability("newCommandTimeout", 300);13capabilities.setCapability("takesScreenshot", true);14capabilities.setCapability("autoWebview", true);15capabilities.setCapability("autoWebviewTimeout", 3000);16capabilities.setCapability("autoAcceptAlerts", true);17capabilities.setCapability("autoDismissAlerts", true);18capabilities.setCapability("ignoreUnimportantViews", true);19capabilities.setCapability("enablePerformanceLogging", true);20capabilities.setCapability("unicodeKeyboard", true);21capabilities.setCapability("resetKeyboard", true);22capabilities.setCapability("skipLogcatCapture", true);23capabilities.setCapability("skipDeviceInitialization", true);24capabilities.setCapability("skipServerInstallation", true);25capabilities.setCapability("skipUnlock", true);26capabilities.setCapability("disableWindowAnimation", true);27capabilities.setCapability("disableAndroidWatchers", true);28capabilities.setCapability("disableAndroidWatchers", true);29capabilities.setCapability("disableWindowAnimation", true);30capabilities.setCapability("disableAndroidWatchers", true);31capabilities.setCapability("disableAndroidWatchers", true);32capabilities.setCapability("disableWindowAnimation", true);33capabilities.setCapability("disableAndroidWatchers", true);34capabilities.setCapability("disableAndroidWatchers", true);35capabilities.setCapability("disableWindowAnimation", true);36capabilities.setCapability("disableAndroidWatchers", true);37capabilities.setCapability("disableAndroidWatchers", true);38capabilities.setCapability("disableWindowAnimation", true);39capabilities.setCapability("disableAndroidWatchers", true);
GeckoDriver
Using AI Code Generation
1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.openqa.selenium.remote.RemoteWebDriver;9import io.appium.java_client.android.AndroidDriver;10import io.appium.java_client.gecko.GeckoDriver;11public class GeckoDriverTest {12public static void main(String[] args) throws MalformedURLException {13DesiredCapabilities caps = new DesiredCapabilities();14caps.setCapability("deviceName", "Android Emulator");15caps.setCapability("platformName", "Android");16caps.setCapability("platformVersion", "7.1.1");17caps.setCapability("browserName", "Firefox");18caps.setCapability("noReset", "true");
GeckoDriver
Using AI Code Generation
1System.setProperty("webdriver.gecko.driver", "path to geckodriver.exe");2DesiredCapabilities capabilities = DesiredCapabilities.firefox();3capabilities.setCapability("marionette", true);4WebDriver driver = new FirefoxDriver(capabilities);5System.setProperty("webdriver.gecko.driver", "path to geckodriver.exe");6var capabilities = {browserName: "firefox", marionette: true};7var driver = new webdriver.Builder()8 .withCapabilities(capabilities)9 .build();10String title = driver.getTitle();11System.out.println("Title of the page is " + title);12driver.quit();13driver.getTitle().then(function(title) {14 console.log("Title of the page is " + title);15});16driver.quit();17javac -cp .;path to selenium-server-standalone-3.0.1.jar;path to appium-java-client-4.1.2.jar appium.java18java -cp .;path to selenium-server-standalone-3.0.1.jar;path to appium-java-client-4.1.2.jar appium
GeckoDriver
Using AI Code Generation
1package appium;2import java.io.File;3import java.io.IOException;4import java.net.MalformedURLException;5import java.net.URL;6import org.openqa.selenium.By;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.firefox.FirefoxDriver;10import org.openqa.selenium.remote.DesiredCapabilities;11import org.openqa.selenium.remote.RemoteWebDriver;12import io.appium.java_client.android.AndroidDriver;13import io.appium.java_client.android.AndroidElement;14import io.appium.java_client.gecko.GeckoDriver;15import io.appium.java_client.remote.AndroidMobileCapabilityType;16import io.appium.java_client.remote.MobileCapabilityType;17public class FirefoxAndroid {18public static void main(String[] args) throws MalformedURLException, InterruptedException, IOException {
GeckoDriver
Using AI Code Generation
1package appium;2import java.io.File;3import java.io.IOException;4import java.net.MalformedURLException;5import java.net.URL;6import java.util.concurrent.TimeUnit;7import org.openqa.selenium.By;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.firefox.FirefoxDriver;10import org.openqa.selenium.remote.DesiredCapabilities;11import org.testng.annotations.AfterTest;12import org.testng.annotations.BeforeTest;13import org.testng.annotations.Test;14import io.appium.java_client.android.AndroidDriver;15import io.appium.java_client.android.AndroidElement;16import io.appium.java_client.remote.MobileCapabilityType;17import io.appium.java_client.service.local.AppiumDriverLocalService;18import io.appium.java_client.service.local.AppiumServiceBuilder;19import io.appium.java_client.service.local.AppiumServiceBuilder;20import io.appium.java_client.service.local.flags.GeneralServe
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!!