Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created March 15, 2021 13:42
Show Gist options
  • Save muditlambda/e85a50df9a351b40b066e972d0075796 to your computer and use it in GitHub Desktop.
Save muditlambda/e85a50df9a351b40b066e972d0075796 to your computer and use it in GitHub Desktop.
package org.testnggroup;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariOptions;
public class Helper {
protected static ThreadLocal<RemoteWebDriver> driver = new ThreadLocal<>();
public static String remote_url = "http://localhost:4444/wd/hub";
public void setupThread(String browserName) throws MalformedURLException
{
if(browserName.equalsIgnoreCase("chrome"))
{
ChromeOptions options = new ChromeOptions();
driver.set(new RemoteWebDriver(new URL(remote_url), options));
}
else if (browserName.equalsIgnoreCase("firefox"))
{
FirefoxOptions options = new FirefoxOptions();
driver.set(new RemoteWebDriver(new URL(remote_url), options));
}
}
public WebDriver getDriver()
{
return driver.get();
}
public void tearDownDriver()
{
getDriver().quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment