How to use ThreadDriver method of org.fluentlenium.adapter.sharedwebdriver.SharedWebdriverSingletonImpl class

Best FluentLenium code snippet using org.fluentlenium.adapter.sharedwebdriver.SharedWebdriverSingletonImpl.ThreadDriver

Source:SharedWebdriverSingletonImpl.java Github

copy

Full Screen

...25 */26class SharedWebdriverSingletonImpl {27 private final ClassDriver classDriverImpl = new ClassDriver();28 private final JvmDriver jvmDriverImpl = new JvmDriver();29 private final ThreadDriver threadDriverImpl = new ThreadDriver();30 private final MethodDriver methodDriverImpl = new MethodDriver();31 private final Map<DriverLifecycle, FluentLeniumDriver> drivers;32 SharedWebdriverSingletonImpl() {33 this.drivers = initDrivers();34 }35 private Map<DriverLifecycle, FluentLeniumDriver> initDrivers() {36 Map<DriverLifecycle, FluentLeniumDriver> lifecycleDrivers = new HashMap<>();37 lifecycleDrivers.put(DriverLifecycle.JVM, jvmDriverImpl);38 lifecycleDrivers.put(DriverLifecycle.THREAD, threadDriverImpl);39 lifecycleDrivers.put(DriverLifecycle.CLASS, classDriverImpl);40 lifecycleDrivers.put(DriverLifecycle.METHOD, methodDriverImpl);41 lifecycleDrivers.put(DriverLifecycle.DEFAULT, methodDriverImpl);42 return lifecycleDrivers;43 }44 /**45 * Get an existing or create a new shared driver for the given test, with the given shared driver46 * lifecycle strategy.47 *48 * @param webDriverFactory Supplier supplying new WebDriver instances49 * @param parameters test parameters50 * @return shared web driver51 */52 SharedWebDriver getOrCreateDriver(Supplier<WebDriver> webDriverFactory, EffectiveParameters<?> parameters) {53 synchronized (this) {54 return Optional.ofNullable(getDriver(parameters))55 .orElseGet(() -> createAndRegisterNewDriver(webDriverFactory, parameters));56 }57 }58 private SharedWebDriver createAndRegisterNewDriver(Supplier<WebDriver> webDriverFactory, EffectiveParameters<?> parameters) {59 SharedWebDriver driver = createDriver(webDriverFactory, parameters);60 registerDriver(driver);61 return driver;62 }63 private SharedWebDriver createDriver(Supplier<WebDriver> webDriverFactory, EffectiveParameters<?> parameters) {64 WebDriver webDriver = webDriverFactory.get();65 return new SharedWebDriver(webDriver,66 parameters.getTestClass(), parameters.getTestName(), parameters.getDriverLifecycle());67 }68 private void registerDriver(SharedWebDriver driver) {69 synchronized (this) {70 drivers.get(driver.getDriverLifecycle()).addDriver(driver);71 }72 }73 /**74 * Get the current driver for given test class.75 *76 * @param parameters test parameters77 * @return shared WebDriver78 */79 public SharedWebDriver getDriver(EffectiveParameters<?> parameters) {80 synchronized (this) {81 switch (parameters.getDriverLifecycle()) {82 case JVM:83 return jvmDriverImpl.getDriver();84 case CLASS:85 return classDriverImpl.getDriver(parameters.getTestClass());86 case THREAD:87 return threadDriverImpl.getDriver(parameters.getTestClass(), parameters.getTestName(),88 Thread.currentThread().getId());89 default:90 return methodDriverImpl.getDriver(parameters.getTestClass(), parameters.getTestName());91 }92 }93 }94 /**95 * Quit an existing shared driver.96 *97 * @param driver Shared WebDriver98 */99 public void quit(SharedWebDriver driver) {100 synchronized (this) {101 drivers.get(driver.getDriverLifecycle()).quitDriver(driver);102 }103 }104 /**105 * Get all WebDriver of this container.106 *107 * @return List of {@link SharedWebDriver}108 */109 List<SharedWebDriver> getAllDrivers() {110 List<SharedWebDriver> allDrivers = new ArrayList<>();111 synchronized (this) {112 Optional.ofNullable(jvmDriverImpl.getDriver()).ifPresent(allDrivers::add);113 allDrivers.addAll(classDriverImpl.getClassDrivers().values());114 allDrivers.addAll(threadDriverImpl.getThreadDrivers().values());115 allDrivers.addAll(methodDriverImpl.getMethodDrivers().values());116 }117 return Collections.unmodifiableList(allDrivers);118 }119 /**120 * Get all shared WebDriver of this container for a given test class.121 *122 * @param testClass test class123 * @return list of shared WebDriver124 */125 List<SharedWebDriver> getTestClassDrivers(Class<?> testClass) {126 List<SharedWebDriver> testClassDrivers = new ArrayList<>();127 synchronized (this) {128 Optional.ofNullable(classDriverImpl.getClassDrivers().get(testClass)).ifPresent(testClassDrivers::add);129 testClassDrivers.addAll(getDrivers(testClass, methodDriverImpl.getMethodDrivers()));130 testClassDrivers.addAll(getDrivers(testClass, threadDriverImpl.getThreadDrivers()));131 return Collections.unmodifiableList(testClassDrivers);132 }133 }134 private List<SharedWebDriver> getDrivers(Class<?> testClass, Map<?, SharedWebDriver> webDrivers) {135 List<SharedWebDriver> sharedDrivers = new ArrayList<>();136 for (SharedWebDriver testDriver : webDrivers.values()) {137 if (testDriver.getTestClass() == testClass) {138 sharedDrivers.add(testDriver);139 }140 }141 return sharedDrivers;142 }143 /**144 * Quit all shared web driver.145 */146 void quitAll() {147 synchronized (this) {148 Optional.ofNullable(jvmDriverImpl.getDriver()).ifPresent(jvmDriverImpl::quitDriver);149 quitAllDrivers(classDriverImpl.getClassDrivers());150 quitAllDrivers(methodDriverImpl.getMethodDrivers());151 quitAllDrivers(threadDriverImpl.getThreadDrivers());152 }153 }154 private void quitAllDrivers(Map<?, SharedWebDriver> driverType) {155 Iterator<SharedWebDriver> testThreadDriversIterator = driverType.values().iterator();156 while (testThreadDriversIterator.hasNext()) {157 testThreadDriversIterator.next().getDriver().quit();158 testThreadDriversIterator.remove();159 }160 }161 /**162 * Returns SharedDriver instance163 *164 * @param parameters driver parameters165 * @param webDriverExecutor executor service166 * @return SharedDriver167 * @throws ExecutionException execution exception168 * @throws InterruptedException interrupted exception169 */170 public SharedWebDriver getSharedWebDriver(SharedMutator.EffectiveParameters<?> parameters,171 ExecutorService webDriverExecutor,172 Supplier<WebDriver> webDriver,...

Full Screen

Full Screen

Source:ThreadDriver.java Github

copy

Full Screen

...9 *10 * @see org.fluentlenium.configuration.ConfigurationProperties.DriverLifecycle#THREAD11 * @see SharedWebdriverSingletonImpl12 */13public class ThreadDriver implements FluentLeniumDriver {14 private final Map<ClassAndTestNameWithThreadId, SharedWebDriver> threadDrivers = new HashMap<>();15 Map<ClassAndTestNameWithThreadId, SharedWebDriver> getThreadDrivers() {16 return threadDrivers;17 }18 @Override19 public void quitDriver(SharedWebDriver driver) {20 List<Map.Entry<ClassAndTestNameWithThreadId, SharedWebDriver>> threadDriversToClose21 = getThreadDriversToClose(driver);22 threadDriversToClose.forEach(item -> closeThreadDriver(driver, item));23 }24 @Override25 public void addDriver(SharedWebDriver driver) {26 threadDrivers.put(new ClassAndTestNameWithThreadId(driver.getTestClass(), driver.getTestName(),27 Thread.currentThread().getId()), driver);28 }29 public <T> SharedWebDriver getDriver(Class<T> testClass, String testName, long id) {30 return threadDrivers.get(new ClassAndTestNameWithThreadId(testClass, testName, id));31 }32 private void closeThreadDriver(SharedWebDriver sharedWebDriver,33 Map.Entry<ClassAndTestNameWithThreadId, SharedWebDriver> item) {34 SharedWebDriver testThreadDriver = threadDrivers.remove(item.getKey());35 quitDriver(sharedWebDriver, testThreadDriver);36 }37 private List<Map.Entry<ClassAndTestNameWithThreadId, SharedWebDriver>> getThreadDriversToClose(SharedWebDriver driver) {38 return threadDrivers.entrySet()39 .stream()40 .filter(entry -> entry.getKey().testClass.equals(driver.getTestClass())41 && entry.getKey().testName.equals(driver.getTestName())42 && entry.getValue().getDriver().equals(driver.getDriver()))43 .collect(Collectors.toList());44 }45 private class ClassAndTestNameWithThreadId {46 protected final Class<?> testClass;47 protected final String testName;48 private final Long threadId;49 ClassAndTestNameWithThreadId(Class<?> testClass, String testName, Long threadId) {50 this.testClass = testClass;51 this.testName = testName;...

Full Screen

Full Screen

ThreadDriver

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.adapter.sharedwebdriver.SharedWebDriver;2import org.fluentlenium.adapter.sharedwebdriver.SharedWebDriverSingleton;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.chrome.ChromeOptions;6import org.openqa.selenium.firefox.FirefoxDriver;7import org.openqa.selenium.firefox.FirefoxProfile;8import org.openqa.selenium.htmlunit.HtmlUnitDriver;9import org.openqa.selenium.ie.InternetExplorerDriver;10import org.openqa.selenium.remote.DesiredCapabilities;11import org.openqa.selenium.remote.RemoteWebDriver;12import org.openqa.selenium.safari.SafariDriver;13import org.openqa.selenium.support.events.EventFiringWebDriver;14import org.openqa.selenium.support.events.WebDriverEventListener;15import org.openqa.selenium.support.ui.WebDriverWait;16import org.slf4j.Logger;17import org.slf4j.LoggerFactory;18import org.springframework.beans.factory.annotation.Value;19import org.springframework.context.annotation.Bean;20import org.springframework.context.annotation.Configuration;21import org.springframework.context.annotation.Scope;22import org.springframework.context.annotation.ScopedProxyMode;23import java.util.concurrent.TimeUnit;24public class WebDriverConfig {25 private static final Logger logger = LoggerFactory.getLogger(WebDriverConfig.class);26 @Value("${webdriver.driver}")27 private String driver;28 @Value("${webdriver.remote.url}")29 private String remoteUrl;30 @Value("${webdriver.remote.username}")31 private String remoteUsername;32 @Value("${webdriver.remote.accessKey}")33 private String remoteAccessKey;34 @Value("${webdriver.remote.platform}")35 private String remotePlatform;36 @Value("${webdriver.remote.browser}")37 private String remoteBrowser;38 @Value("${webdriver.remote.browser.version}")39 private String remoteBrowserVersion;40 @Value("${webdriver.remote.maxDuration}")41 private String remoteMaxDuration;42 @Value("${webdriver.remote.maxDuration.unit}")43 private String remoteMaxDurationUnit;44 @Value("${webdriver.remote.idleTimeout}")45 private String remoteIdleTimeout;46 @Value("${webdriver.remote.idleTimeout.unit}")47 private String remoteIdleTimeoutUnit;48 @Value("${webdriver.remote.build}")49 private String remoteBuild;50 @Value("${webdriver.remote.name}")51 private String remoteName;52 @Value("${webdriver.remote.tags}")53 private String remoteTags;54 @Value("${webdriver.remote.public}")55 private String remotePublic;56 @Value("${webdriver.remote.tunnelIdentifier}")57 private String remoteTunnelIdentifier;58 @Value("${webdriver.remote.screenResolution}")

Full Screen

Full Screen

ThreadDriver

Using AI Code Generation

copy

Full Screen

1package com.example;2import org.fluentlenium.adapter.FluentTest;3import org.fluentlenium.adapter.SharedDriver;4import org.junit.Test;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.htmlunit.HtmlUnitDriver;7import static org.assertj.core.api.Assertions.assertThat;8@SharedDriver(type = SharedDriver.SharedType.PER_CLASS)9public class ThreadDriver extends FluentTest {10 public WebDriver getDefaultDriver() {11 return new HtmlUnitDriver();12 }13 public void test() {14 assertThat(title()).contains("Google");15 }16}17package com.example;18import org.fluentlenium.adapter.FluentTest;19import org.fluentlenium.adapter.SharedDriver;20import org.junit.Test;21import org.openqa.selenium.WebDriver;22import org.openqa.selenium.htmlunit.HtmlUnitDriver;23import static org.assertj.core.api.Assertions.assertThat;24@SharedDriver(type = SharedDriver.SharedType.PER_CLASS)25public class ThreadDriver extends FluentTest {26 public WebDriver getDefaultDriver() {27 return new HtmlUnitDriver();28 }29 public void test() {30 assertThat(title()).contains("Google");31 }32}33package com.example;34import org.fluentlenium.adapter.FluentTest;35import org.fluentlenium.adapter.SharedDriver;36import org.junit.Test;37import org.openqa.selenium.WebDriver;38import org.openqa.selenium.htmlunit.HtmlUnitDriver;39import static org.assertj.core.api.Assertions.assertThat;40@SharedDriver(type = SharedDriver.SharedType.PER_CLASS)41public class ThreadDriver extends FluentTest {42 public WebDriver getDefaultDriver() {43 return new HtmlUnitDriver();44 }45 public void test() {46 assertThat(title()).contains("Google");47 }48}49package com.example;50import

Full Screen

Full Screen

ThreadDriver

Using AI Code Generation

copy

Full Screen

1package org.fluentlenium.adapter.sharedwebdriver;2import org.fluentlenium.adapter.FluentAdapter;3import org.openqa.selenium.WebDriver;4public class SharedWebDriverSingletonImpl extends FluentAdapter implements SharedWebDriverSingleton {5 private static ThreadLocal<WebDriver> threadDriver = new ThreadLocal<WebDriver>();6 public SharedWebDriverSingletonImpl() {7 super();8 if (threadDriver.get() == null) {9 threadDriver.set(getDriver());10 }11 initFluent(threadDriver.get());12 initTest();13 }14 public void closeSharedDriver() {15 closeWebDriver();16 }17 public void quitSharedDriver() {18 quitWebDriver();19 }20 public WebDriver getSharedDriver() {21 return threadDriver.get();22 }23}24package org.fluentlenium.adapter.sharedwebdriver;25import org.fluentlenium.adapter.FluentTest;26import org.openqa.selenium.WebDriver;27public class SharedWebDriverSingletonImplTest extends FluentTest {28 private SharedWebDriverSingleton sharedWebDriverSingleton = new SharedWebDriverSingletonImpl();29 public WebDriver getDriver() {30 return sharedWebDriverSingleton.getSharedDriver();31 }32 public void after() {33 sharedWebDriverSingleton.closeSharedDriver();34 }35 public void testSharedDriver() {36 fill("q").with("FluentLenium");37 submit("q");38 $("h3.r").first().shouldHave(text("FluentLenium"));39 }40}41import org.fluentlenium.adapter.sharedwebdriver.SharedWebDriverSingletonImplTest;42import org.junit.Test;43public class SharedWebDriverSingletonImplTestTest {44 public void testSharedDriver() {45 SharedWebDriverSingletonImplTest test = new SharedWebDriverSingletonImplTest();46 test.testSharedDriver();47 }48}49import org.fluentlenium.adapter.sharedwebdriver.SharedWebDriverSingletonImplTest;50import org.junit.Test;51public class SharedWebDriverSingletonImplTestTest {52 public void testSharedDriver() {53 SharedWebDriverSingletonImplTest test = new SharedWebDriverSingletonImplTest();54 test.testSharedDriver();

Full Screen

Full Screen

ThreadDriver

Using AI Code Generation

copy

Full Screen

1package com.test;2import org.junit.Before;3import org.junit.Test;4import org.junit.runner.RunWith;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.chrome.ChromeOptions;8import org.openqa.selenium.firefox.FirefoxDriver;9import org.openqa.selenium.firefox.FirefoxOptions;10import org.openqa.selenium.remote.DesiredCapabilities;11import org.openqa.selenium.remote.RemoteWebDriver;12import org.openqa.selenium.remote.SessionId;13import org.openqa.selenium.support.ui.WebDriverWait;14import org.openqa.selenium.support.ui.ExpectedConditions;15import org.openqa.selenium.By;16import org.openqa.selenium.WebElement;17import org.openqa.selenium.JavascriptExecutor;18import org.openqa.selenium.support.ui.Select;19import org.openqa.selenium.interactions.Actions;20import org.openqa.selenium.Keys;21import org.openqa.selenium.Platform;22import org.openqa.selenium.TakesScreenshot;23import org.openqa.selenium.OutputType;24import org.openqa.selenium.Capabilities;25import org.openqa.selenium.remote.RemoteWebElement;26import org.openqa.selenium.remote.DesiredCapabilities;27import org.openqa.selenium.remote.RemoteWebDriver;28import org.openqa.selenium.remote.SessionId;29import org.openqa.selenium.support.ui.WebDriverWait;30import org.openqa.selenium.support.ui.ExpectedConditions;31import org.openqa.selenium.By;32import org.openqa.selenium.WebElement;33import org.openqa.selenium.JavascriptExecutor;34import org.openqa.selenium.support.ui.Select;35import org.openqa.selenium.interactions.Actions;36import org.openqa.selenium.Keys;37import org.openqa.selenium.Platform;38import org.openqa.selenium.TakesScreenshot;39import org.openqa.selenium.OutputType;40import org.openqa.selenium.Capabilities;41import org.openqa.selenium.remote.RemoteWebElement;42import org.openqa.selenium.remote.DesiredCapabilities;43import org.openqa.selenium.remote.RemoteWebDriver;44import org.openqa.selenium.remote.SessionId;45import org.openqa.selenium.support.ui.WebDriverWait;46import org.openqa.selenium.support.ui.ExpectedConditions;47import org.openqa.selenium.By;48import org.openqa.selenium.WebElement;49import org.openqa.selenium.JavascriptExecutor;50import org.openqa.selenium.support.ui.Select;51import org.openqa.selenium.interactions.Actions;52import org.openqa.selenium.Keys;53import org.openqa.selenium.Platform;54import org.openqa.selenium.TakesScreenshot;55import org.openqa.selenium.OutputType;56import org.openqa.selenium.Capabilities;57import org.openqa.selenium.remote.RemoteWebElement;58import org.openqa.selenium.remote.DesiredCapabilities;59import org.openqa.selenium.remote.RemoteWebDriver;60import org.openqa.selenium.remote.SessionId;61import org.openqa.selenium.support.ui.WebDriverWait;62import org.openqa.selenium.support.ui.ExpectedConditions;63import org.openqa.selenium.By;64import org.openqa.selenium.WebElement;65import org.openqa

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 FluentLenium automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful