|
| 1 | +package com.BrowserStack; |
| 2 | + |
| 3 | +import java.net.URL; |
| 4 | +import java.util.HashMap; |
| 5 | + |
| 6 | +import org.junit.*; |
| 7 | + |
| 8 | +import org.openqa.selenium.WebDriver; |
| 9 | +import org.openqa.selenium.remote.DesiredCapabilities; |
| 10 | +import org.openqa.selenium.remote.RemoteWebDriver; |
| 11 | + |
| 12 | +public class BrowserStackLocalExample { |
| 13 | + private WebDriver driver; |
| 14 | + Local l; |
| 15 | + |
| 16 | + @Before |
| 17 | + public void setUp() throws Exception { |
| 18 | + String username = System.getenv("BROWSERSTACK_USER"); |
| 19 | + String access_key = System.getenv("BROWSERSTACK_ACCESS_KEY"); |
| 20 | + |
| 21 | + DesiredCapabilities caps = new DesiredCapabilities(); |
| 22 | + caps.setCapability("browser", "Firefox"); |
| 23 | + caps.setCapability("browser_version", "40.0"); |
| 24 | + caps.setCapability("os", "Windows"); |
| 25 | + caps.setCapability("os_version", "8.1"); |
| 26 | + caps.setCapability("browserstack.local", true); |
| 27 | + |
| 28 | + l = new Local(); |
| 29 | + HashMap<String, String> options = new HashMap<String, String>(); |
| 30 | + options.put("key", access_key); |
| 31 | + //options.put("only", "localhost,80,0"); |
| 32 | + //options.put("forcelocal", ""); |
| 33 | + //options.put("proxyHost", "127.0.0.1"); |
| 34 | + //options.put("proxyPort", "8118"); |
| 35 | + //options.put("xyz", "qwerty"); |
| 36 | + l.start(options); |
| 37 | + |
| 38 | + System.out.println("Starting session"); |
| 39 | + driver = new RemoteWebDriver(new URL("http://" + username + ":" + access_key + "@hub.browserstack.com/wd/hub"), caps); |
| 40 | + System.out.println("Started session"); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testSimple() throws Exception { |
| 45 | + driver.get("http://localhost"); |
| 46 | + System.out.println("Process is running : " + l.isRunning()); |
| 47 | + System.out.println("Page title is: " + driver.getTitle()); |
| 48 | + } |
| 49 | + |
| 50 | + @After |
| 51 | + public void tearDown() throws Exception { |
| 52 | + driver.quit(); |
| 53 | + l.stop(); |
| 54 | + } |
| 55 | +} |
0 commit comments