Skip to content

Instantly share code, notes, and snippets.

@alexpreynolds
Created October 5, 2018 00:07
Show Gist options
  • Save alexpreynolds/2906b8bf7a2619422a79cca38d8cc44a to your computer and use it in GitHub Desktop.
Save alexpreynolds/2906b8bf7a2619422a79cca38d8cc44a to your computer and use it in GitHub Desktop.
Selenium Java binding test
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class LocalSeleniumTest {
public static void main(String[] args) throws IOException, InterruptedException {
System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--no-sandbox");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://www.google.com");
Thread.sleep(1000);
if (driver.getPageSource().contains("I'm Feeling Lucky")) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment