Created
April 11, 2024 05:45
-
-
Save SarahElson/76aca9d5f30ceb2c0619c514b742288c to your computer and use it in GitHub Desktop.
How To Retry Failed Tests Using IRetryAnalyzer In TestNG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DriverManager { | |
private static final ThreadLocal<WebDriver > DRIVER = new ThreadLocal<> (); | |
private static final String GRID_URL = "@hub.lambdatest.com/wd/hub"; | |
private static final Logger LOG = LogManager.getLogger ("DriverManager.class"); | |
private static final String LT_ACCESS_KEY = System.getProperty ("LT_ACCESS_KEY"); | |
private static final String LT_USERNAME = System.getProperty ("LT_USERNAME"); | |
public static void createDriver (final Browsers browser) { | |
setupChromeInLambdaTest (); | |
setupBrowserTimeouts (); | |
} | |
public static WebDriver getDriver () { | |
return DriverManager.DRIVER.get (); | |
} | |
public static void quitDriver () { | |
if (null != DRIVER.get ()) { | |
LOG.info ("Closing the driver..."); | |
getDriver ().quit (); | |
DRIVER.remove (); | |
} | |
} | |
private static void setDriver (final WebDriver driver) { | |
DriverManager.DRIVER.set (driver); | |
} | |
private static void setupBrowserTimeouts () { | |
LOG.info ("Setting Browser Timeouts...."); | |
getDriver ().manage () | |
.timeouts () | |
.implicitlyWait (Duration.ofSeconds (30)); | |
getDriver ().manage () | |
.timeouts () | |
.pageLoadTimeout (Duration.ofSeconds (30)); | |
getDriver ().manage () | |
.timeouts () | |
.scriptTimeout (Duration.ofSeconds (30)); | |
} | |
private static void setupChromeInLambdaTest () { | |
final ChromeOptions browserOptions = new ChromeOptions (); | |
browserOptions.setPlatformName ("Windows 10"); | |
browserOptions.setBrowserVersion ("latest"); | |
final HashMap<String, Object> ltOptions = new HashMap<> (); | |
ltOptions.put ("resolution", "2560x1440"); | |
ltOptions.put ("selenium_version", "4.0.0"); | |
ltOptions.put ("build", "LambdaTest ECommerce Playground Build"); | |
ltOptions.put ("name", "End to End LambdaTest ECommerce Playground Tests"); | |
ltOptions.put ("w3c", true); | |
ltOptions.put ("plugin", "java-testNG"); | |
browserOptions.setCapability ("LT:Options", ltOptions); | |
try { | |
setDriver ( | |
new RemoteWebDriver (new URL (format ("https://{0}:{1}{2}", LT_USERNAME, LT_ACCESS_KEY, GRID_URL)), | |
browserOptions)); | |
} catch (final MalformedURLException e) { | |
LOG.error ("Error setting up Chrome browser in LambdaTest", e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment