Commits

Micha Kops  committed 570534e

initial import

  • Participants

Comments (0)

Files changed (3)

+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.hascode.tutorial</groupId>
+	<artifactId>selenium-webdriver</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<selenium.version>2.20.0</selenium.version>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.seleniumhq.selenium</groupId>
+			<artifactId>selenium-java</artifactId>
+			<version>${selenium.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.10</version>
+		</dependency>
+		<dependency>
+			<groupId>org.seleniumhq.selenium</groupId>
+			<artifactId>selenium-server</artifactId>
+			<version>${selenium.version}</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.3.2</version>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

File src/test/java/com/hascode/tutorial/RemoteDriverTest.java

+package com.hascode.tutorial;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openqa.selenium.OutputType;
+import org.openqa.selenium.TakesScreenshot;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.remote.Augmenter;
+import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.remote.RemoteWebDriver;
+import org.openqa.selenium.server.RemoteControlConfiguration;
+import org.openqa.selenium.server.SeleniumServer;
+
+import com.google.common.io.Files;
+
+public class RemoteDriverTest {
+	private static SeleniumServer server;
+
+	@BeforeClass
+	public static void setUpTest() throws Exception {
+		RemoteControlConfiguration conf = new RemoteControlConfiguration();
+		conf.setPort(4444);
+		conf.setDebugURL("/wd/hub");
+		server = new SeleniumServer(conf);
+		server.start();
+	}
+
+	@AfterClass
+	public static void tearDownTest() {
+		server.stop();
+	}
+
+	@Test
+	public void testTakeScreenshot() throws IOException {
+		WebDriver driver = new RemoteWebDriver(new URL(
+				"http://localhost:4444/wd/hub"), DesiredCapabilities.firefox());
+
+		driver.get("http://www.dzone.com/");
+
+		WebDriver augmentedDriver = new Augmenter().augment(driver);
+		File screenshot = ((TakesScreenshot) augmentedDriver)
+				.getScreenshotAs(OutputType.FILE);
+		assertNotNull(screenshot);
+		assertTrue(screenshot.exists());
+		assertTrue(Files.toByteArray(screenshot).length > 0);
+	}
+}

File src/test/java/com/hascode/tutorial/WebpageTest.java

+package com.hascode.tutorial;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.firefox.FirefoxDriver;
+
+public class WebpageTest {
+	private WebDriver driver;
+
+	@Before
+	public void setUp() {
+		driver = new FirefoxDriver();
+	}
+
+	@After
+	public void tearDown() {
+		driver.close();
+	}
+
+	@Test
+	public void testGetTitle() {
+		driver.get("http://www.hascode.com/");
+		assertEquals("hasCode.com", driver.getTitle());
+		WebElement searchBox = driver.findElement(By.id("s"));
+		searchBox.sendKeys("ejb");
+		searchBox.submit();
+		assertEquals("hasCode.com » Search Results » ejb", driver.getTitle());
+	}
+}