Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created August 13, 2024 14:38
Show Gist options
  • Save SarahElson/c3f8825eaa2da7197608b551b3159407 to your computer and use it in GitHub Desktop.
Save SarahElson/c3f8825eaa2da7197608b551b3159407 to your computer and use it in GitHub Desktop.
ExpectedConditions In Selenium: Types And Examples
public class BaseTest {
protected RemoteWebDriver driver;
@BeforeClass
public void setup() {
String USERNAME = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME");
String ACCESS_KEY = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY");
String GRID_URL = "@hub.lambdatest.com/wd/hub";
try {
this.driver = new RemoteWebDriver(new URL("http://" + USERNAME + ":" + ACCESS_KEY + GRID_URL), getChromeOptions());
} catch (final MalformedURLException e) {
System.out.println("Could not start the remote session on LambdaTest cloud grid");
}
this.driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
}
public ChromeOptions getChromeOptions() {
final var browserOptions = new ChromeOptions();
browserOptions.setPlatformName("Windows 10");
browserOptions.setBrowserVersion("126.0");
final HashMap<String, Object> ltOptions = new HashMap<String, Object>();
ltOptions.put("project", "Expected Conditions Blog");
ltOptions.put("build", "LambdaTest");
ltOptions.put("name", "Expected Conditions Demo");
ltOptions.put("visual", true);
ltOptions.put("network", true);
ltOptions.put("console", true);
ltOptions.put("w3c", true);
ltOptions.put("plugin", "java-testNG");
browserOptions.setCapability("LT:Options", ltOptions);
return browserOptions;
}
@AfterClass
public void tearDown() {
this.driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment