How to use shutDownExecutor method of org.fluentlenium.utils.ExecutorServiceUtil class

Best FluentLenium code snippet using org.fluentlenium.utils.ExecutorServiceUtil.shutDownExecutor

Source:SharedWebdriverSingletonImpl.java Github

copy

Full Screen

...18import java.util.concurrent.ExecutorService;19import java.util.concurrent.Future;20import java.util.function.Supplier;21import static org.fluentlenium.utils.ExecutorServiceUtil.getExecutor;22import static org.fluentlenium.utils.ExecutorServiceUtil.shutDownExecutor;23/**24 * Shared web driver container singleton implementation.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,173 Configuration configuration)174 throws ExecutionException, InterruptedException {175 SharedWebDriver sharedWebDriver = null;176 ExecutorService executorService = getExecutor(webDriverExecutor);177 Integer browserTimeoutRetries = configuration.getBrowserTimeoutRetries();178 for (int retryCount = 0; retryCount < browserTimeoutRetries; retryCount++) {179 Future<SharedWebDriver> futureWebDriver = createDriver(parameters, executorService, webDriver);180 shutDownExecutor(executorService, configuration.getBrowserTimeout());181 try {182 sharedWebDriver = futureWebDriver.get();183 } catch (InterruptedException | ExecutionException e) {184 executorService.shutdownNow();185 throw e;186 }187 if (sharedWebDriver != null) {188 break;189 }190 }191 return sharedWebDriver;192 }193 private Future<SharedWebDriver> createDriver(SharedMutator.EffectiveParameters<?> parameters,194 ExecutorService executorService,...

Full Screen

Full Screen

Source:ExecutorServiceUtil.java Github

copy

Full Screen

...4import java.util.concurrent.TimeUnit;5public final class ExecutorServiceUtil {6 private ExecutorServiceUtil() {7 }8 public static void shutDownExecutor(ExecutorService executorService, Long browserTimeout) throws InterruptedException {9 executorService.shutdown();10 if (didNotExitGracefully(executorService, browserTimeout)) {11 executorService.shutdownNow();12 }13 }14 public static ExecutorService getExecutor(ExecutorService webDriverExecutor) {15 if (webDriverExecutor == null) {16 return Executors.newSingleThreadExecutor();17 }18 return webDriverExecutor;19 }20 private static boolean didNotExitGracefully(ExecutorService executorService, Long browserTimeout)21 throws InterruptedException {22 return !executorService.awaitTermination(browserTimeout, TimeUnit.MILLISECONDS);...

Full Screen

Full Screen

shutDownExecutor

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.core.FluentPage;2import org.fluentlenium.core.annotation.Page;3import org.junit.Test;4import org.junit.runner.RunWith;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.htmlunit.HtmlUnitDriver;7import org.openqa.selenium.support.ui.WebDriverWait;8import org.springframework.test.context.ContextConfiguration;9import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;10import javax.annotation.Resource;11@RunWith(SpringJUnit4ClassRunner.class)12@ContextConfiguration("classpath:applicationContext.xml")13public class 4 {14 private WebDriver webDriver;15 private WebDriverWait webDriverWait;16 private GooglePage googlePage;17 public void test() {18 googlePage.go();19 googlePage.isAt();20 googlePage.fillSearch("FluentLenium").submit();21 googlePage.isAt();22 }23 public static class GooglePage extends FluentPage {24 public String getUrl() {25 }26 public void isAt() {27 assert title().equals("Google");28 }29 public GooglePage fillSearch(String text) {30 fill("#lst-ib").with(text);31 return this;32 }33 public GooglePage submit() {34 findFirst("button[name=btnG]").click();35 return this;36 }37 }38 public static class WebDriverConfig {39 private ExecutorServiceUtil executorServiceUtil;40 @Bean(destroyMethod = "quit")41 public WebDriver webDriver() {42 return new HtmlUnitDriver(true);43 }44 public WebDriverWait webDriverWait() {45 return new WebDriverWait(webDriver(), 10);46 }47 public void shutDownExecutor() {48 executorServiceUtil.shutdown();49 }50 }51}

Full Screen

Full Screen

shutDownExecutor

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.core.FluentPage;2import org.fluentlenium.core.annotation.Page;3import org.fluentlenium.core.annotation.PageUrl;4import org.openqa.selenium.WebDriver;5import org.testng.annotations.AfterMethod;6import org.testng.annotations.BeforeMethod;7import org.testng.annotations.Test;8import java.util.concurrent.ExecutorService;9import java.util.concurrent.Executors;10import java.util.concurrent.TimeUnit;11public class 4 extends FluentPage {12 private 4 page;13 private ExecutorService executorService;14 public void beforeMethod() {15 executorService = Executors.newSingleThreadExecutor();16 }17 public void test() {18 executorService.submit(() -> page.go());19 }20 public void afterMethod() {21 ExecutorServiceUtil.shutDownExecutor(executorService, 10, TimeUnit.SECONDS);22 }23 public WebDriver getDefaultDriver() {24 return null;25 }26}27import org.fluentlenium.core.FluentPage;28import org.fluentlenium.core.annotation.Page;29import org.fluentlenium.core.annotation.PageUrl;30import org.openqa.selenium.WebDriver;31import org.testng.annotations.AfterMethod;32import org.testng.annotations.BeforeMethod;33import org.testng.annotations.Test;34import java.util.concurrent.ExecutorService;35import java.util.concurrent.Executors;36import java.util.concurrent.TimeUnit;37public class 5 extends FluentPage {38 private 5 page;39 private ExecutorService executorService;40 public void beforeMethod() {41 executorService = Executors.newSingleThreadExecutor();42 }43 public void test() {44 executorService.submit(() -> page.go());45 }46 public void afterMethod() {47 ExecutorServiceUtil.shutDownExecutor(executorService, 10, TimeUnit.SECONDS);48 }49 public WebDriver getDefaultDriver() {50 return null;51 }52}53import org.fluentlenium.core.FluentPage;54import org.fluentlenium.core.annotation.Page;55import org.fluentlenium.core

Full Screen

Full Screen

shutDownExecutor

Using AI Code Generation

copy

Full Screen

1package com.seleniumtests;2import java.util.concurrent.TimeUnit;3import org.fluentlenium.core.FluentPage;4import org.fluentlenium.core.annotation.Page;5import org.fluentlenium.core.hook.wait.Wait;6import org.fluentlenium.core.hook.wait.WaitHook;7import org.fluentlenium.core.hook.wait.WaitHookImpl;8import org.fluentlenium.utils.ExecutorServiceUtil;9import org.openqa.selenium.WebDriver;10public class FluentTest extends FluentPage {11 private PageObject pageObject;12 public void isAt() {13 }14 public void await() {15 }16 public void awaitAt() {17 }18 public void awaitUntil(WaitHook waitHook) {19 }20 public void awaitUntil(WaitHookImpl waitHook) {21 }22 public void awaitUntil(WaitHookImpl waitHook, long time, TimeUnit timeUnit) {23 }24 public void awaitUntil(WaitHook waitHook, long time, TimeUnit timeUnit) {25 }26 public void awaitAtMost(long time, TimeUnit timeUnit) {27 }28 public void awaitAtMost(long time, TimeUnit timeUnit, WaitHook waitHook) {29 }30 public void awaitAtMost(long time, TimeUnit timeUnit, WaitHookImpl waitHook) {31 }32 public void awaitAtMost(long time, TimeUnit timeUnit, WaitHookImpl waitHook, long time2, TimeUnit timeUnit2) {33 }34 public void awaitAtMost(long time, TimeUnit timeUnit, WaitHook waitHook, long time2, TimeUnit timeUnit2) {35 }36 public void awaitAtMost(long time, TimeUnit timeUnit, WaitHook waitHook, long time2,

Full Screen

Full Screen

shutDownExecutor

Using AI Code Generation

copy

Full Screen

1package com.automation.test;2import org.fluentlenium.core.FluentPage;3import org.fluentlenium.core.annotation.Page;4import org.fluentlenium.core.domain.FluentWebElement;5import org.fluentlenium.core.hook.wait.Wait;6import org.openqa.selenium.support.FindBy;7public class FluentLeniumTest extends FluentPage {8 private FluentLeniumTest fluentLeniumTest;9 @FindBy(css = "div#div1")10 private FluentWebElement div1;11 @FindBy(css = "div#div2")12 private FluentWebElement div2;13 @FindBy(css = "div#div3")14 private FluentWebElement div3;15 @FindBy(css = "div#div4")16 private FluentWebElement div4;17 @FindBy(css = "div#div5")18 private FluentWebElement div5;19 @FindBy(css = "div#div6")20 private FluentWebElement div6;21 @FindBy(css = "div#div7")22 private FluentWebElement div7;23 @FindBy(css = "div#div8")24 private FluentWebElement div8;25 @FindBy(css = "div#div9")26 private FluentWebElement div9;27 @FindBy(css = "div#div10")28 private FluentWebElement div10;29 @FindBy(css = "div#div11")30 private FluentWebElement div11;31 @FindBy(css = "div#div12")32 private FluentWebElement div12;33 @FindBy(css = "div#div13")34 private FluentWebElement div13;35 @FindBy(css = "div#div14")36 private FluentWebElement div14;37 @FindBy(css = "div#div15")38 private FluentWebElement div15;39 @FindBy(css = "div#div16")40 private FluentWebElement div16;41 @FindBy(css = "div#div17")42 private FluentWebElement div17;43 @FindBy(css = "div#div18")44 private FluentWebElement div18;45 @FindBy(css = "div#div19")46 private FluentWebElement div19;47 @FindBy(css = "div#div20")48 private FluentWebElement div20;49 @FindBy(css = "div#div21")50 private FluentWebElement div21;51 @FindBy(css = "div#div22")52 private FluentWebElement div22;53 @FindBy(css = "div#div23")

Full Screen

Full Screen

shutDownExecutor

Using AI Code Generation

copy

Full Screen

1package com.seleniumeasy;2import org.fluentlenium.core.FluentPage;3import org.fluentlenium.core.annotation.Page;4import org.fluentlenium.core.domain.FluentWebElement;5import org.junit.AfterClass;6import org.junit.BeforeClass;7import org.junit.Test;8import org.openqa.selenium.By;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.chrome.ChromeDriver;11import org.openqa.selenium.chrome.ChromeOptions;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.support.FindBy;14import org.openqa.selenium.support.ui.ExpectedConditions;15import org.openqa.selenium.support.ui.WebDriverWait;16import java.io.File;17import java.util.concurrent.TimeUnit;18public class FluentTest extends FluentPage {19 private static WebDriver driver;20 private static WebDriverWait wait;21 private static FluentTest fluentTest;22 @FindBy(id = "btn_basic_example")23 private FluentWebElement basicExamples;24 @FindBy(id = "btn_input_forms")25 private FluentWebElement inputForms;26 @FindBy(id = "btn_ajax_form")27 private FluentWebElement ajaxForm;28 @FindBy(id = "title")29 private FluentWebElement title;30 @FindBy(id = "description")31 private FluentWebElement description;32 @FindBy(id = "btn-submit")33 private FluentWebElement submit;34 @FindBy(css = "div#submit-control")35 private FluentWebElement submitControl;36 @FindBy(css = "div#submit-control")37 private FluentWebElement submitControl2;38 @FindBy(id = "btn")39 private FluentWebElement btn;40 @FindBy(id = "title")41 private FluentWebElement title2;42 @FindBy(id = "description")43 private FluentWebElement description2;44 @FindBy(id = "btn-submit")45 private FluentWebElement submit2;46 public static void setUp() {47 File file = new File("C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");48 System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());49 ChromeOptions options = new ChromeOptions();50 options.addArguments("disable-infobars");51 DesiredCapabilities capabilities = DesiredCapabilities.chrome();52 capabilities.setCapability(ChromeOptions.CAPABILITY, options);53 driver = new ChromeDriver(capabilities);54 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);55 wait = new WebDriverWait(driver, 10);56 driver.manage().window().maximize();57 }58 public void test() {

Full Screen

Full Screen

shutDownExecutor

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 ExecutorService executor = Executors.newFixedThreadPool(2);4 executor.execute(() -> {5 System.out.println("Thread 1");6 });7 executor.execute(() -> {8 System.out.println("Thread 2");9 });10 ExecutorServiceUtil.shutdownExecutor(executor);11 }12}

Full Screen

Full Screen

shutDownExecutor

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.utils.ExecutorServiceUtil;2public class ShutDownExecutor{3public static void main(String[] args){4ExecutorServiceUtil.shutDownExecutor();5}6}

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