How to use DriverFactory class of com.qaprosoft.carina.core.foundation.webdriver.core.factory package

Best Carina code snippet using com.qaprosoft.carina.core.foundation.webdriver.core.factory.DriverFactory

Source:DriverFactory.java Github

copy

Full Screen

...30import com.qaprosoft.carina.core.foundation.webdriver.device.DevicePool;31import io.appium.java_client.android.AndroidDriver;32import io.appium.java_client.ios.IOSDriver;33/**34 * DriverFactory produces driver instance with desired capabilities according to35 * configuration.36 *37 * @author Alexey Khursevich (hursevich@gmail.com)38 */39public class DriverFactory {40 public static final String HTML_UNIT = "htmlunit";41 protected static final Logger LOGGER = Logger.getLogger(DriverFactory.class);42 private static final Device nullDevice = new Device();43 @SuppressWarnings("rawtypes")44 public static WebDriver create(String testName, DesiredCapabilities capabilities, String selenium_host) {45 RemoteWebDriver driver = null;46 try {47 if (capabilities.getCapability("automationName") == null)48 driver = new RemoteWebDriver(new URL(selenium_host), capabilities);49 else {50 String platform;51 if (capabilities.getCapability("platform") != null) {52 platform = capabilities.getCapability("platform").toString();53 } else if (capabilities.getCapability("platformName") != null) {54 platform = capabilities.getCapability("platformName").toString();55 } else {56 throw new RuntimeException("Unable to identify platform type using platform and platformName capabilities for test: " + testName);57 }58 if (platform.toLowerCase().equals("android")) {59 driver = new AndroidDriver(new URL(selenium_host), capabilities);60 } else if (platform.toLowerCase().equals("ios")) {61 driver = new IOSDriver(new URL(selenium_host), capabilities);62 } else {63 throw new RuntimeException("Undefined platform type for mobile driver test: " + testName);64 }65 }66 } catch (Exception e) {67 LOGGER.error("Unable to initialize extra driver!\r\n" + e.getMessage());68 }69 70 if (driver == null) {71 LOGGER.error("Page isn't created. There is no any initialized driver for thread: " + Thread.currentThread().getId());72 DevicePool.removeDevice();73 throw new RuntimeException("Page isn't created. Driver isn't initialized.");74 }75 return driver;76 }77 /**78 * Creates driver instance for specified test.79 *80 * @param testName in which driver will be used81 * @return RemoteWebDriver instance82 */83 public static WebDriver create(String testName) {84 return create(testName, nullDevice);85 }86 public static WebDriver create(String testName, Device device) {87 LOGGER.debug("DriverFactory start...");88 AbstractFactory factory;89 String driverType = Configuration.get(Parameter.DRIVER_TYPE);90 if (driverType.equalsIgnoreCase(SpecialKeywords.DESKTOP)) {91 factory = new DesktopFactory();92 } else if (driverType.equalsIgnoreCase(SpecialKeywords.MOBILE)93 || driverType.equalsIgnoreCase(SpecialKeywords.MOBILE_POOL)94 || driverType.equalsIgnoreCase(SpecialKeywords.MOBILE_GRID)) {95 factory = new MobileFactory();96 } else {97 throw new RuntimeException("Unsupported driver_type: " + driverType + "!");98 }99 WebDriver drv = factory.create(testName, device);100 LOGGER.debug("DriverFactory finish...");101 return drv;102 }103 public static String getBrowserName(WebDriver driver) {104 Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();105 return cap.getBrowserName().toString();106 }107 public static String getBrowserVersion(WebDriver driver) {108 Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();109 return cap.getVersion().toString();110 }111}...

Full Screen

Full Screen

DriverFactory

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.core.foundation.webdriver.core.factory;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.remote.RemoteWebDriver;5import org.openqa.selenium.support.events.EventFiringWebDriver;6import org.openqa.selenium.support.events.WebDriverEventListener;7import org.slf4j.Logger;8import org.slf4j.LoggerFactory;9import com.qaprosoft.carina.core.foundation.commons.SpecialKeywords;10import com.qaprosoft.carina.core.foundation.exception.DriverPoolException;11import com.qaprosoft.carina.core.foundation.utils.Configuration;12import com.qaprosoft.carina.core.foundation.webdriver.DriverPool;13import com.qaprosoft.carina.core.foundation.webdriver.IDriverPool;14import com.qaprosoft.carina.core.foundation.webdriver.Screenshot;15import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedEventFiringWebDriver;16import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedRemoteWebDriver;17import com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener;18import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringWebDriverListener;19public class DriverFactory {20 private static final Logger LOGGER = LoggerFactory.getLogger(DriverFactory.class);21 private static final String CAPABILITIES = "capabilities";22 private static final String DRIVER = "driver";23 private static final String DRIVER_TYPE = "driver_type";24 private static final String REMOTE_URL = "remote_url";25 private static final String REMOTE_URL_BROWSERSTACK = "remote_url_browserstack";26 private static final String REMOTE_URL_APPIUM = "remote_url_appium";27 private static final String REMOTE_URL_SELENIUM_GRID = "remote_url_selenium_grid";28 private static final String REMOTE_URL_LOCAL = "remote_url_local";29 private static final String REMOTE_URL_LOCAL_APPIUM = "remote_url_local_appium";30 private static final String REMOTE_URL_LOCAL_SELENIUM_GRID = "remote_url_local_selenium_grid";31 private static final String REMOTE_URL_LOCAL_BROWSERSTACK = "remote_url_local_browserstack";32 private static final String REMOTE_URL_LOCAL_GRID = "remote_url_local_grid";33 private static final String REMOTE_URL_LOCAL_CHROME = "remote_url_local_chrome";34 private static final String REMOTE_URL_LOCAL_FIREFOX = "remote_url_local_firefox";35 private static final String REMOTE_URL_LOCAL_IE = "remote_url_local_ie";

Full Screen

Full Screen

DriverFactory

Using AI Code Generation

copy

Full Screen

1DriverFactory.getDriver().findElement(By.name("q")).sendKeys("Hello World");2DriverFactory.getDriver().findElement(By.name("btnK")).click();3DriverFactory.getDriver().close();4DriverFactory.getDriver().quit();5DriverFactory.getDriver().findElement(By.name("q")).sendKeys("Hello World");6DriverFactory.getDriver().findElement(By.name("btnK")).click();7DriverFactory.getDriver().close();8DriverFactory.getDriver().quit();9DriverFactory.getDriver().findElement(By.name("q")).sendKeys("Hello World");10DriverFactory.getDriver().findElement(By.name("btnK")).click();11DriverFactory.getDriver().close();12DriverFactory.getDriver().quit();13DriverFactory.getDriver().findElement(By.name("q")).sendKeys("Hello World");14DriverFactory.getDriver().findElement(By.name("btnK")).click();15DriverFactory.getDriver().close();16DriverFactory.getDriver().quit();17DriverFactory.getDriver().findElement(By.name("q")).sendKeys("Hello World");18DriverFactory.getDriver().findElement(By.name("btnK")).click();19DriverFactory.getDriver().close();20DriverFactory.getDriver().quit();21DriverFactory.getDriver().findElement(By.name("q")).sendKeys("Hello World");22DriverFactory.getDriver().findElement(By.name("btnK")).click();23DriverFactory.getDriver().close();24DriverFactory.getDriver().quit();

Full Screen

Full Screen

DriverFactory

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.core.factory.DriverFactory;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.firefox.FirefoxDriver;5import org.openqa.selenium.remote.RemoteWebDriver;6import org.openqa.selenium.safari.SafariDriver;7public class DriverFactoryTest {8public static void main(String[] args) {9WebDriver driver = DriverFactory.getDriver();10System.out.println("Driver object is: " + driver);11System.out.println("Driver object class is: " + driver.getClass());12}13}

Full Screen

Full Screen

DriverFactory

Using AI Code Generation

copy

Full Screen

1DriverFactory.getDriver().close();2DriverFactory.getDriver().close();3DriverFactory.getDriver().close();4DriverFactory.getDriver().close();5DriverFactory.getDriver().close();6DriverFactory.getDriver().close();7DriverFactory.getDriver().close();8DriverFactory.getDriver().close();

Full Screen

Full Screen

DriverFactory

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.core.factory.DriverFactory;2import org.openqa.selenium.WebDriver;3public class Test {4 public static void main(String[] args) {5 WebDriver driver = DriverFactory.getDriver();6 System.out.println("title of the page is: " + driver.getTitle());7 driver.close();8 driver.quit();9 }10}

Full Screen

Full Screen

DriverFactory

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.core.factory.DriverFactory;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeOptions;4import java.util.HashMap;5import java.util.Map;6public class DriverFactoryExample {7 public static void main(String[] args) {8 Map<String, String> mobileEmulation = new HashMap<>();9 mobileEmulation.put("deviceName", "iPhone X");10 ChromeOptions options = new ChromeOptions();11 options.setExperimentalOption("mobileEmulation", mobileEmulation);12 WebDriver driver = DriverFactory.getDriver(options);13 System.out.println(driver.getTitle());14 driver.quit();15 }16}17[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ carina-demo ---18[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ carina-demo ---19[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ carina-demo ---20[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ carina-demo ---21[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ carina-demo ---22[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @

Full Screen

Full Screen

DriverFactory

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.support.FindBy;4import org.openqa.selenium.support.PageFactory;5import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;6import com.qaprosoft.carina.core.foundation.webdriver.decorator.PageOpeningStrategy;7import com.qaprosoft.carina.core.foundation.webdriver.decorator.PageOpeningStrategy.PageOpenMode;8import com.qaprosoft.carina.core.foundation.webdriver.decorator.PageOpeningStrategy.PageOpenStrategy;9import com.qaprosoft.carina.core.foundation.webdriver.decorator.PageOpeningStrategy.PageType;10import com.qaprosoft.carina.core.foundation.webdriver.decorator.VerboseElementLocatorFactory;11import com.qaprosoft.carina.core.foundation.webdriver.core.factory.DriverFactory;12public class BasePage {13 protected WebDriver driver;14 public BasePage(WebDriver driver) {15 this.driver = driver;16 PageFactory.initElements(new VerboseElementLocatorFactory(driver, 10), this);17 }18 public BasePage() {19 this(DriverFactory.getDriver());20 }21 public void open() {22 PageOpeningStrategy strategy = new PageOpeningStrategy(PageOpenMode.BY_URL, PageOpenStrategy.GET);23 strategy.setPageType(PageType.BASE_PAGE);24 open(strategy);25 }26 public void open(PageOpeningStrategy pageOpeningStrategy) {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Carina automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in DriverFactory

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful