Skip to content

Commit 8254c6d

Browse files
committed
Added Basic Tests.
0 parents  commit 8254c6d

4 files changed

Lines changed: 110 additions & 0 deletions

File tree

BrowserStack.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package bs;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.net.MalformedURLException;
6+
import java.net.URL;
7+
import org.apache.commons.io.FileUtils;
8+
import org.openqa.selenium.By;
9+
import org.openqa.selenium.OutputType;
10+
import org.openqa.selenium.Platform;
11+
import org.openqa.selenium.TakesScreenshot;
12+
import org.openqa.selenium.WebDriver;
13+
import org.openqa.selenium.WebElement;
14+
import org.openqa.selenium.remote.Augmenter;
15+
import org.openqa.selenium.remote.DesiredCapabilities;
16+
import org.openqa.selenium.remote.RemoteWebDriver;
17+
18+
public class BrowserStack {
19+
20+
public static void main(String args[]) throws MalformedURLException, InterruptedException {
21+
DesiredCapabilities capability = DesiredCapabilities.firefox();
22+
WebDriver driver = new RemoteWebDriver(
23+
new URL("http://USERNAME:ACCESS_KEY@hub.browserstack.com/wd/hub"),
24+
capability
25+
);
26+
driver.get("http://www.google.com");
27+
System.out.println("Page title is: " + driver.getTitle());
28+
WebElement element = driver.findElement(By.name("q"));
29+
element.sendKeys("BrowserStack");
30+
element.submit();
31+
System.out.println("And the Title is: " + driver.getTitle());
32+
driver.quit();
33+
}
34+
}

LocalSample.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import org.openqa.selenium.By;
2+
import org.openqa.selenium.WebDriver;
3+
import org.openqa.selenium.WebElement;
4+
import org.openqa.selenium.firefox.*;
5+
6+
public class LocalSample {
7+
8+
public static void main(String[] args) throws Exception {
9+
10+
WebDriver driver = new FirefoxDriver();
11+
driver.get("http://www.google.com/");
12+
System.out.println("Page title is: " + driver.getTitle());
13+
WebElement element = driver.findElement(By.name("q"));
14+
element.sendKeys("BrowserStack");
15+
element.submit();
16+
System.out.println("And the Title is: " + driver.getTitle());
17+
driver.quit();
18+
19+
}
20+
}

README

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Automate Java Samples
2+
---------------------
3+
4+
This repository contains code samples from http://browserstack.dev/automate/java. Please feel free to clone the repo and use the example code.
5+
6+
7+
Do remember to switch the USERNAME and ACCESS_KEY with your own browserstack credentials.

junit/JUnitTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import static org.junit.Assert.*;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.net.URL;
6+
7+
import org.apache.commons.io.FileUtils;
8+
import org.junit.AfterClass;
9+
import org.junit.BeforeClass;
10+
import org.junit.Test;
11+
import org.openqa.selenium.By;
12+
import org.openqa.selenium.OutputType;
13+
import org.openqa.selenium.Platform;
14+
import org.openqa.selenium.TakesScreenshot;
15+
import org.openqa.selenium.WebDriver;
16+
import org.openqa.selenium.WebElement;
17+
import org.openqa.selenium.remote.Augmenter;
18+
import org.openqa.selenium.remote.DesiredCapabilities;
19+
import org.openqa.selenium.remote.RemoteWebDriver;
20+
21+
public class JUnitTest {
22+
private static WebDriver driver;
23+
24+
@Before
25+
public static void setUp() throws Exception {
26+
DesiredCapabilities capability = DesiredCapabilities.chrome();
27+
capability.setPlatform(Platform.MAC);
28+
capability.setVersion("20.0");
29+
driver = new RemoteWebDriver(
30+
new URL("http://USERNAME:ACCESS_KEY@hub.browserstack.com/wd/hub"),
31+
capability
32+
);
33+
}
34+
35+
@Test
36+
public void testSimple() throws Exception {
37+
driver.get("http://www.google.com");
38+
System.out.println("Page title is: " + driver.getTitle());
39+
assertEquals("Google", driver.getTitle());
40+
WebElement element = driver.findElement(By.name("q"));
41+
element.sendKeys("Browser Stack");
42+
element.submit();
43+
}
44+
45+
@After
46+
public static void tearDown() throws Exception {
47+
driver.quit();
48+
}
49+
}

0 commit comments

Comments
 (0)