How to use quitMethodAndThreadDrivers method of org.fluentlenium.adapter.TestRunnerCommon class

Best FluentLenium code snippet using org.fluentlenium.adapter.TestRunnerCommon.quitMethodAndThreadDrivers

Source:FluentTestRunnerAdapter.java Github

copy

Full Screen

2import static org.fluentlenium.adapter.TestRunnerCommon.deleteCookies;3import static org.fluentlenium.adapter.TestRunnerCommon.doHtmlDump;4import static org.fluentlenium.adapter.TestRunnerCommon.doScreenshot;5import static org.fluentlenium.adapter.TestRunnerCommon.getTestDriver;6import static org.fluentlenium.adapter.TestRunnerCommon.quitMethodAndThreadDrivers;7import static org.fluentlenium.utils.AnnotationUtil.getClassAnnotationForClass;8import static org.fluentlenium.utils.AnnotationUtil.getMethodAnnotationForMethod;9import static org.fluentlenium.utils.ScreenshotUtil.isIgnoredException;10import static org.fluentlenium.utils.ThreadLocalAdapterUtil.clearThreadLocals;11import static org.fluentlenium.utils.ThreadLocalAdapterUtil.getClassFromThread;12import static org.fluentlenium.utils.ThreadLocalAdapterUtil.getMethodNameFromThread;13import static org.fluentlenium.utils.ThreadLocalAdapterUtil.setTestClassAndMethodValues;14import java.lang.annotation.Annotation;15import java.util.List;16import org.fluentlenium.adapter.SharedMutator.EffectiveParameters;17import org.fluentlenium.adapter.sharedwebdriver.SharedWebDriver;18import org.fluentlenium.adapter.sharedwebdriver.SharedWebDriverContainer;19/**20 * FluentLenium Test Runner Adapter.21 * <p>22 * Extends this class to provide FluentLenium support to your Test class.23 */24@SuppressWarnings("PMD.GodClass")25public class FluentTestRunnerAdapter extends FluentAdapter implements TestRunnerAdapter {26 private final SharedMutator sharedMutator;27 private static final ThreadLocal<EffectiveParameters<?>> PARAMETERS_THREAD_LOCAL = new ThreadLocal<>();28 private static final ThreadLocal<String> TEST_METHOD_NAME = new ThreadLocal<>();29 private static final ThreadLocal<Class<?>> TEST_CLASS = new ThreadLocal<>();30 /**31 * Creates a new test runner adapter.32 */33 public FluentTestRunnerAdapter() {34 this(new DefaultFluentControlContainer());35 }36 /**37 * Creates a test runner adapter, with a custom driver container.38 *39 * @param driverContainer driver container40 */41 public FluentTestRunnerAdapter(FluentControlContainer driverContainer) {42 this(driverContainer, new DefaultSharedMutator());43 }44 /**45 * Creates a test runner adapter, with a custom shared mutator.46 *47 * @param sharedMutator shared mutator.48 */49 public FluentTestRunnerAdapter(SharedMutator sharedMutator) {50 this(new DefaultFluentControlContainer(), sharedMutator);51 }52 /**53 * Creates a test runner adapter, with a customer driver container and a customer shared mutator.54 *55 * @param driverContainer driver container56 * @param sharedMutator shared mutator57 */58 public FluentTestRunnerAdapter(FluentControlContainer driverContainer, SharedMutator sharedMutator) {59 super(driverContainer);60 this.sharedMutator = sharedMutator;61 }62 /**63 * Creates a test runner adapter, with a customer driver container and a customer shared mutator.64 * It is possible to pass class from which the FluentConfiguration annotation will be loaded.65 *66 * @param driverContainer driver container67 * @param clazz class from which FluentConfiguration annotation will be loaded68 * @param sharedMutator shared mutator69 */70 public FluentTestRunnerAdapter(FluentControlContainer driverContainer, Class<?> clazz, SharedMutator sharedMutator) {71 super(driverContainer, clazz);72 this.sharedMutator = sharedMutator;73 }74 @Override75 public Class<?> getTestClass() {76 return getClassFromThread(TEST_CLASS);77 }78 @Override79 public String getTestMethodName() {80 return getMethodNameFromThread(TEST_METHOD_NAME);81 }82 @Override83 public <T extends Annotation> T getClassAnnotation(Class<T> annotation) {84 return getClassAnnotationForClass(annotation, getClassFromThread(TEST_CLASS));85 }86 @Override87 public <T extends Annotation> T getMethodAnnotation(Class<T> annotation) {88 return getMethodAnnotationForMethod(89 annotation,90 getClassFromThread(TEST_CLASS),91 getMethodNameFromThread(TEST_METHOD_NAME));92 }93 /**94 * Invoked when a test method is starting.95 */96 protected void starting() {97 starting(getClass());98 }99 /**100 * Invoked when a test method is starting.101 *102 * @param testName Test name103 */104 protected void starting(String testName) {105 starting(getClass(), testName);106 }107 /**108 * Invoked when a test method is starting.109 *110 * @param testClass Test class111 */112 protected void starting(Class<?> testClass) {113 starting(testClass, testClass.getName());114 }115 /**116 * Invoked when a test method is starting.117 *118 * @param testClass Test class119 * @param testName Test name120 */121 protected void starting(Class<?> testClass, String testName) {122 PARAMETERS_THREAD_LOCAL.set(sharedMutator.getEffectiveParameters(testClass, testName,123 getDriverLifecycle()));124 SharedWebDriver sharedWebDriver = getTestDriver(testClass, testName,125 this::newWebDriver, this::failed,126 getConfiguration(), PARAMETERS_THREAD_LOCAL.get());127 setTestClassAndMethodValues(PARAMETERS_THREAD_LOCAL, TEST_CLASS, TEST_METHOD_NAME);128 initFluent(sharedWebDriver.getDriver());129 }130 /**131 * Invoked when a test method has finished (whatever the success of failing status)132 */133 protected void finished() {134 finished(getClass());135 }136 /**137 * Invoked when a test method has finished (whatever the success of failing status)138 *139 * @param testName Test name140 */141 protected void finished(String testName) {142 finished(getClass(), testName);143 }144 /**145 * Invoked when a test method has finished (whatever the success of failing status)146 *147 * @param testClass Test class148 */149 protected void finished(Class<?> testClass) {150 finished(testClass, testClass.getName());151 }152 /**153 * Invoked when a test method has finished (whatever the success of failing status)154 *155 * @param testClass Test class156 * @param testName Test name157 */158 protected void finished(Class<?> testClass, String testName) {159 DriverLifecycle driverLifecycle = getDriverLifecycle();160 SharedWebDriver sharedWebDriver = SharedWebDriverContainer.INSTANCE161 .getDriver(sharedMutator.getEffectiveParameters(testClass, testName, driverLifecycle));162 quitMethodAndThreadDrivers(driverLifecycle, sharedWebDriver);163 deleteCookies(sharedWebDriver, getConfiguration());164 clearThreadLocals(PARAMETERS_THREAD_LOCAL, TEST_CLASS, TEST_METHOD_NAME);165 releaseFluent();166 }167 /**168 * Invoked when a test method has failed (before finished)169 */170 protected void failed() {171 failed(getClass());172 }173 /**174 * Invoked when a test method has failed (before finished)175 *176 * @param testName Test name...

Full Screen

Full Screen

Source:SpringTestNGAdapter.java Github

copy

Full Screen

...13import static org.fluentlenium.adapter.TestRunnerCommon.deleteCookies;14import static org.fluentlenium.adapter.TestRunnerCommon.doHtmlDump;15import static org.fluentlenium.adapter.TestRunnerCommon.doScreenshot;16import static org.fluentlenium.adapter.TestRunnerCommon.getTestDriver;17import static org.fluentlenium.adapter.TestRunnerCommon.quitMethodAndThreadDrivers;18import static org.fluentlenium.utils.AnnotationUtil.getClassAnnotationForClass;19import static org.fluentlenium.utils.AnnotationUtil.getMethodAnnotationForMethod;20import static org.fluentlenium.utils.ScreenshotUtil.isIgnoredException;21import static org.fluentlenium.utils.ThreadLocalAdapterUtil.clearThreadLocals;22import static org.fluentlenium.utils.ThreadLocalAdapterUtil.getClassFromThread;23import static org.fluentlenium.utils.ThreadLocalAdapterUtil.getMethodNameFromThread;24import static org.fluentlenium.utils.ThreadLocalAdapterUtil.setTestClassAndMethodValues;25/**26 * FluentLenium Test Runner Adapter.27 * <p>28 * Extends this class to provide FluentLenium support to your Test class.29 */30@SuppressWarnings("PMD.GodClass")31class SpringTestNGAdapter extends SpringTestNGControl implements TestRunnerAdapter, IFluentAdapter {32 private final SharedMutator sharedMutator;33 private static final ThreadLocal<EffectiveParameters<?>> PARAMETERS_THREAD_LOCAL = new ThreadLocal<>();34 private static final ThreadLocal<String> TEST_METHOD_NAME = new ThreadLocal<>();35 private static final ThreadLocal<Class<?>> TEST_CLASS = new ThreadLocal<>();36 /**37 * Creates a new test runner adapter.38 */39 SpringTestNGAdapter() {40 super(new ThreadLocalFluentControlContainer());41 this.sharedMutator = new DefaultSharedMutator();42 }43 @Override44 public Class<?> getTestClass() {45 return getClassFromThread(TEST_CLASS);46 }47 @Override48 public String getTestMethodName() {49 return getMethodNameFromThread(TEST_METHOD_NAME);50 }51 @Override52 public <T extends Annotation> T getClassAnnotation(Class<T> annotation) {53 return getClassAnnotationForClass(annotation, getClassFromThread(TEST_CLASS));54 }55 @Override56 public <T extends Annotation> T getMethodAnnotation(Class<T> annotation) {57 return getMethodAnnotationForMethod(58 annotation,59 getClassFromThread(TEST_CLASS),60 getMethodNameFromThread(TEST_METHOD_NAME));61 }62 /**63 * Invoked when a test method is starting.64 *65 * @param testClass Test class66 * @param testName Test name67 */68 protected void starting(Class<?> testClass, String testName) {69 PARAMETERS_THREAD_LOCAL.set(sharedMutator.getEffectiveParameters(testClass, testName,70 getDriverLifecycle()));71 SharedWebDriver sharedWebDriver = getTestDriver(testClass, testName,72 this::newWebDriver, this::failed,73 getConfiguration(), PARAMETERS_THREAD_LOCAL.get());74 setTestClassAndMethodValues(PARAMETERS_THREAD_LOCAL, TEST_CLASS, TEST_METHOD_NAME);75 initFluent(sharedWebDriver.getDriver());76 }77 /**78 * Invoked when a test method has finished (whatever the success of failing status)79 *80 * @param testClass Test class81 * @param testName Test name82 */83 protected void finished(Class<?> testClass, String testName) {84 DriverLifecycle driverLifecycle = getDriverLifecycle();85 SharedWebDriver sharedWebDriver = SharedWebDriverContainer.INSTANCE86 .getDriver(sharedMutator.getEffectiveParameters(testClass, testName, driverLifecycle));87 quitMethodAndThreadDrivers(driverLifecycle, sharedWebDriver);88 deleteCookies(sharedWebDriver, getConfiguration());89 clearThreadLocals(PARAMETERS_THREAD_LOCAL, TEST_CLASS, TEST_METHOD_NAME);90 releaseFluent();91 }92 /**93 * Invoked when a test method has failed (before finished)94 *95 * @param e Throwable thrown by the failing test.96 * @param testClass Test class97 * @param testName Test name98 */99 protected void failed(Throwable e, Class<?> testClass, String testName) {100 if (isFluentControlAvailable() && !isIgnoredException(e)) {101 doScreenshot(testClass, testName, this, getConfiguration());...

Full Screen

Full Screen

Source:TestRunnerCommon.java Github

copy

Full Screen

...17import static org.fluentlenium.utils.ExceptionUtil.getCauseMessage;18public final class TestRunnerCommon {19 private TestRunnerCommon() {20 }21 public static void quitMethodAndThreadDrivers(22 DriverLifecycle driverLifecycle, SharedWebDriver sharedWebDriver) {23 if (driverLifecycle == METHOD || driverLifecycle == THREAD) {24 Optional.ofNullable(sharedWebDriver).ifPresent(SharedWebDriverContainer.INSTANCE::quit);25 }26 }27 public static void deleteCookies(SharedWebDriver sharedWebDriver, Configuration configuration) {28 if (configuration.getDeleteCookies()) {29 Optional.ofNullable(sharedWebDriver).ifPresent(shared -> shared.getDriver().manage().deleteAllCookies());30 }31 }32 public static SharedWebDriver getTestDriver(Class<?> testClass, String testName, Supplier<WebDriver> webDriver,33 TriConsumer<Throwable, Class<?>, String> failed,34 Configuration configuration, EffectiveParameters<?> parameters) {35 SharedWebDriver sharedWebDriver;...

Full Screen

Full Screen

quitMethodAndThreadDrivers

Using AI Code Generation

copy

Full Screen

1package com.mkyong.testng.examples;2import org.fluentlenium.adapter.FluentTestNg;3import org.fluentlenium.core.annotation.Page;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.htmlunit.HtmlUnitDriver;6import org.testng.annotations.AfterMethod;7import org.testng.annotations.BeforeMethod;8import org.testng.annotations.Test;9public class TestRunner extends FluentTestNg {10 private GooglePage googlePage;11 public void beforeMethod() {12 System.out.println("beforeMethod");13 }14 public void test1() {15 System.out.println("test1");16 googlePage.go();17 googlePage.isAt();18 }19 public void test2() {20 System.out.println("test2");21 googlePage.go();22 googlePage.isAt();23 }24 public void afterMethod() {25 System.out.println("afterMethod");26 }27 public WebDriver getDefaultDriver() {28 return new HtmlUnitDriver();29 }30 public String getBaseUrl() {31 }32}33package com.mkyong.testng.examples;34import org.fluentlenium.adapter.FluentTestNg;35import org.fluentlenium.core.annotation.Page;36import org.openqa.selenium.WebDriver;37import org.openqa.selenium.htmlunit.HtmlUnitDriver;38import org.testng.annotations.AfterMethod;39import org.testng.annotations.BeforeMethod;40import org.testng.annotations.Test;41public class TestRunner extends FluentTestNg {42 private GooglePage googlePage;43 public void beforeMethod() {44 System.out.println("beforeMethod");45 }46 public void test1() {47 System.out.println("test1");48 googlePage.go();49 googlePage.isAt();50 }51 public void test2() {52 System.out.println("test2");53 googlePage.go();54 googlePage.isAt();55 }56 public void afterMethod() {57 System.out.println("afterMethod");58 }59 public WebDriver getDefaultDriver() {60 return new HtmlUnitDriver();61 }62 public String getBaseUrl() {

Full Screen

Full Screen

quitMethodAndThreadDrivers

Using AI Code Generation

copy

Full Screen

1package com.automation;2import org.junit.Test;3import org.junit.runner.RunWith;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.firefox.FirefoxDriver;6import org.openqa.selenium.firefox.FirefoxProfile;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.openqa.selenium.support.ui.WebDriverWait;9import org.springframework.beans.factory.annotation.Autowired;10import org.springframework.test.context.ContextConfiguration;11import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;12import com.automation.configuration.SeleniumConfig;13import com.automation.configuration.SpringConfig;14import com.automation.pages.HomePage;15import com.automation.pages.LoginPage;16import com.automation.pages.MyProfilePage;17import com.automation.pages.RegisterPage;18@RunWith(SpringJUnit4ClassRunner.class)19@ContextConfiguration(classes = { SpringConfig.class, SeleniumConfig.class })20public class TestRunnerCommon extends TestRunner {21 HomePage homePage;22 LoginPage loginPage;23 MyProfilePage myProfilePage;24 RegisterPage registerPage;25 public void test() {26 System.out.println("In test method");27 homePage.open();28 homePage.clickLoginLink();29 loginPage.enterUserName("test");30 loginPage.enterPassword("test");31 loginPage.clickLoginButton();32 }33 public void quitMethodAndThreadDrivers() {34 if (getDriver() != null) {35 getDriver().quit();36 }37 }38 public WebDriver newWebDriver() {39 FirefoxProfile profile = new FirefoxProfile();40 DesiredCapabilities capabilities = DesiredCapabilities.firefox();41 capabilities.setCapability(FirefoxDriver.PROFILE, profile);42 WebDriver driver = new FirefoxDriver(capabilities);43 driver.manage().window().maximize();44 return driver;45 }46 public WebDriverWait newWebDriverWait(WebDriver webDriver, long timeOutInSeconds, long sleepInMillis) {47 return new WebDriverWait(webDriver, timeOutInSeconds, sleepInMillis);48 }49}50package com.automation.configuration;51import org.fluentlenium.adapter.FluentTest;52import org.openqa.selenium.WebDriver;53public class TestRunner extends FluentTest {54 public WebDriver newWebDriver() {55 return null;56 }57 public void quitMethodAndThreadDrivers() {58 }

Full Screen

Full Screen

quitMethodAndThreadDrivers

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.adapter.TestRunnerCommon;2import org.junit.Test;3public class TestRunnerCommonTest extends TestRunnerCommon {4 public void testQuitMethodAndThreadDrivers() {5 quitMethodAndThreadDrivers();6 }7}8import org.fluentlenium.adapter.TestRunnerCommon;9import org.junit.Test;10public class TestRunnerCommonTest extends TestRunnerCommon {11 public void testQuitMethodAndThreadDrivers() {12 quitMethodAndThreadDrivers();13 }14}15import org.fluentlenium.adapter.TestRunnerCommon;16import org.junit.Test;17public class TestRunnerCommonTest extends TestRunnerCommon {18 public void testQuitMethodAndThreadDrivers() {19 quitMethodAndThreadDrivers();20 }21}22import org.fluentlenium.adapter.TestRunnerCommon;23import org.junit.Test;24public class TestRunnerCommonTest extends TestRunnerCommon {25 public void testQuitMethodAndThreadDrivers() {26 quitMethodAndThreadDrivers();27 }28}29import org.fluentlenium.adapter.TestRunnerCommon;30import org.junit.Test;31public class TestRunnerCommonTest extends TestRunnerCommon {32 public void testQuitMethodAndThreadDrivers() {33 quitMethodAndThreadDrivers();34 }35}36import org.fluentlenium.adapter.TestRunnerCommon;37import org.junit.Test;38public class TestRunnerCommonTest extends TestRunnerCommon {39 public void testQuitMethodAndThreadDrivers() {40 quitMethodAndThreadDrivers();41 }42}43import org.fluentlenium.adapter.TestRunnerCommon;44import

Full Screen

Full Screen

quitMethodAndThreadDrivers

Using AI Code Generation

copy

Full Screen

1public class 4 extends TestRunnerCommon {2 public void test() {3 quitMethodAndThreadDrivers();4 }5}6public class 5 extends TestRunnerCommon {7 public void test() {8 quitMethodAndThreadDrivers();9 }10}11public class 6 extends TestRunnerCommon {12 public void test() {13 quitMethodAndThreadDrivers();14 }15}16public class 7 extends TestRunnerCommon {17 public void test() {18 quitMethodAndThreadDrivers();19 }20}21public class 8 extends TestRunnerCommon {22 public void test() {23 quitMethodAndThreadDrivers();24 }25}26public class 9 extends TestRunnerCommon {27 public void test() {28 quitMethodAndThreadDrivers();29 }30}31public class 10 extends TestRunnerCommon {32 public void test() {33 quitMethodAndThreadDrivers();34 }35}

Full Screen

Full Screen

quitMethodAndThreadDrivers

Using AI Code Generation

copy

Full Screen

1public class 4 extends TestRunnerCommon {2 public static void main(String[] args) {3 FluentDriverManager.get().quitMethodAndThreadDrivers();4 }5}6public class 5 extends TestRunnerCommon {7 public static void main(String[] args) {8 FluentDriverManager.get().quitMethodAndThreadDrivers();9 }10}11public class 6 extends TestRunnerCommon {12 public static void main(String[] args) {13 FluentDriverManager.get().quitMethodAndThreadDrivers();14 }15}16public class 7 extends TestRunnerCommon {17 public static void main(String[] args) {18 FluentDriverManager.get().quitMethodAndThreadDrivers();19 }20}21public class 8 extends TestRunnerCommon {22 public static void main(String[] args) {23 FluentDriverManager.get().quitMethodAndThreadDrivers();24 }25}26public class 9 extends TestRunnerCommon {27 public static void main(String[] args) {28 FluentDriverManager.get().quitMethodAndThreadDrivers();29 }30}31public class 10 extends TestRunnerCommon {32 public static void main(String[] args) {33 FluentDriverManager.get().quitMethodAndThreadDrivers();34 }35}

Full Screen

Full Screen

quitMethodAndThreadDrivers

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.adapter.FluentTest;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.firefox.FirefoxDriver;4import org.testng.annotations.AfterMethod;5import org.testng.annotations.BeforeMethod;6import org.testng.annotations.Test;7public class 4 extends FluentTest {8 public void beforeMethod() {9 System.out.println("Before Method");10 }11 public void afterMethod() {12 System.out.println("After Method");13 quitMethodAndThreadDrivers();14 }15 public void test() {16 System.out.println("Test");17 }18 public WebDriver newWebDriver() {19 return new FirefoxDriver();20 }21}22import org.fluentlenium.adapter.FluentTest;23import org.openqa.selenium.WebDriver;24import org.openqa.selenium.firefox.FirefoxDriver;25import org.testng.annotations.AfterMethod;26import org.testng.annotations.BeforeMethod;27import org.testng.annotations.Test;28public class 5 extends FluentTest {29 public void beforeMethod() {30 System.out.println("Before Method");31 }32 public void afterMethod() {33 System.out.println("After Method");34 quitMethodAndThreadDrivers();35 }36 public void test() {37 System.out.println("Test");38 }39 public WebDriver newWebDriver() {40 return new FirefoxDriver();41 }42}43import org.fluentlenium.adapter.FluentTest;44import

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