Skip to content

Instantly share code, notes, and snippets.

@ndmanvar
Created July 22, 2015 18:32
Show Gist options
  • Save ndmanvar/ed7170bff671c1cdd6ea to your computer and use it in GitHub Desktop.
Save ndmanvar/ed7170bff671c1cdd6ea to your computer and use it in GitHub Desktop.
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.CapabilityType;
import java.net.URL;
public class SampleSeleniumTest {
public static final String USERNAME = System.getenv("SAUCE_USERNAME");
public static final String ACCESS_KEY = System.getenv("SAUCE_ACCESS_KEY");
public static final String URL = "http://<ADDRESS_OF_SELENIUM_HUB>:4444/wd/hub";
// if localhost, then:
// public static final String URL = "http://localhost:4444/wd/hub";
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(CapabilityType.BROWSER_NAME, "firefox");
caps.setCapability(CapabilityType.VERSION, "37");
caps.setCapability(CapabilityType.PLATFORM, "Windows 7");
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
driver.get("http://www.amazon.com");
WebElement element = driver.findElement(By.name("field-keywords"));
element.sendKeys("Sauce Labs");
element.submit();
System.out.println(driver.getTitle());
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment