Permalink
Browse files

Initial commit of a basic maven template for Selenium.

  • Loading branch information...
1 parent f1438dd commit 5a8732c6e24c29d91f7781aeddce74bf951b6c18 Mark Collin committed Apr 19, 2012
Showing with 195 additions and 4 deletions.
  1. +50 −3 .gitignore
  2. +10 −1 README.md
  3. +84 −0 pom.xml
  4. +51 −0 src/test/java/com/lazerycode/selenium/Selenium2ExampleTest.java
View
@@ -1,6 +1,53 @@
+# Compiled source #
+###################
+*.com
*.class
+*.dll
+*.exe
+*.o
+*.so
-# Package Files #
+# Packages #
+############
+# it's better to unpack these files and commit the raw source
+# git has its own built in compression methods
+*.7z
+*.dmg
+*.gz
+*.iso
*.jar
-*.war
-*.ear
+*.rar
+*.tar
+*.zip
+
+# Logs and databases #
+######################
+*.log
+*.sql
+*.sqlite
+
+# OS generated files #
+######################
+.DS_Store*
+ehthumbs.db
+Icon?
+Thumbs.db
+
+# IntelliJ #
+############
+*.iml
+*.ipr
+*.iws
+.idea
+
+# Maven #
+#########
+*/target/*
+
+# Other IDE's#
+##############
+\.classpath
+\.project
+\.settings
+\.dorsync
+/nbactions.xml
View
@@ -1,4 +1,13 @@
Selenium-Maven-Template
=======================
-A maven template for Selenium that will let you check out and go.
+A maven template for Selenium that has the latest dependencies so that you can just check out and start writing tests.
+
+Check out this project.
+
+In the terminal
+
+cd *project_directory*
+mvn clean install -U
+
+All dependencies should now be downloaded and the example test will be run (Assuming you have Firefox installed in the default location)
View
84 pom.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright (c) 2010-2012 Lazery Attack - http://www.lazeryattack.com ~ http://www.lazerycode.com
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<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">
+
+ <groupId>com.lazerycode.selenium</groupId>
+ <artifactId>maven-template</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <modelVersion>4.0.0</modelVersion>
+
+ <name>Selenium Maven Template</name>
+ <description>A Maven Template For Selenium</description>
+ <url>http://www.lazerycode.com</url>
+
+ <licenses>
+ <license>
+ <name>Apache 2</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ <comments>A business-friendly OSS license</comments>
+ </license>
+ </licenses>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>selenium-server</artifactId>
+ <version>2.21.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.opera</groupId>
+ <artifactId>operadriver</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.opera</groupId>
+ <artifactId>operadriver</artifactId>
+ <version>0.11</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>selenium-remote-driver</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </build>
+
+</project>
@@ -0,0 +1,51 @@
+package com.lazerycode.selenium;
+
+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;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+public class Selenium2ExampleTest {
+
+ @Test
+ public void exampleTest() throws Exception{
+ // Create a new instance of the Firefox driver
+ // Notice that the remainder of the code relies on the interface,
+ // not the implementation.
+ WebDriver driver = new FirefoxDriver();
+
+ // And now use this to visit Google
+ driver.get("http://www.google.com");
+ // Alternatively the same thing can be done like this
+ // driver.navigate().to("http://www.google.com");
+
+ // Find the text input element by its name
+ WebElement element = driver.findElement(By.name("q"));
+
+ // Enter something to search for
+ element.sendKeys("Cheese!");
+
+ // Now submit the form. WebDriver will find the form for us from the element
+ element.submit();
+
+ // Check the title of the page
+ System.out.println("Page title is: " + driver.getTitle());
+
+ // Google's search is rendered dynamically with JavaScript.
+ // Wait for the page to load, timeout after 10 seconds
+ (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
+ public Boolean apply(WebDriver d) {
+ return d.getTitle().toLowerCase().startsWith("cheese!");
+ }
+ });
+
+ // Should see: "cheese! - Google Search"
+ System.out.println("Page title is: " + driver.getTitle());
+
+ //Close the browser
+ driver.quit();
+ }
+}

0 comments on commit 5a8732c

Please sign in to comment.