Skip to content

Commit

Permalink
Merge pull request #11 from arnlaugsson/selenium
Browse files Browse the repository at this point in the history
Add Selenium support
  • Loading branch information
arnlaugsson authored Oct 25, 2016
2 parents 891a367 + 9e79d69 commit fc3033d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
19 changes: 17 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,30 @@ repositories {
jcenter()
}

sourceSets {
selenium
}

dependencies {
// Application dependencies
compile 'org.slf4j:slf4j-api:1.7.5'
compile 'net.joningi:icndb-java-api:1.0'
compile 'com.sparkjava:spark-core:2.5'

// Unit test dependencies
testCompile 'junit:junit:4.11'

compile 'net.joningi:icndb-java-api:1.0'
compile 'com.sparkjava:spark-core:2.5'
// Selenium dependencies
seleniumCompile 'junit:junit:4.11'
seleniumCompile 'org.seleniumhq.selenium:selenium-firefox-driver:3.0.1'
seleniumCompile 'org.seleniumhq.selenium:selenium-chrome-driver:3.0.1'
}

task stage {
dependsOn installDist
}

task selenium(type: Test, dependsOn: installDist) {
testClassesDir = sourceSets.selenium.output.classesDir
classpath = sourceSets.selenium.runtimeClasspath
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package is.ru.arnlaugsson.chuck_joke;

import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.openqa.selenium.chrome.ChromeDriver;


public abstract class SeleniumTestWrapper {
static ChromeDriver driver;
static String baseUrl;
static String port;

@BeforeClass
public static void openBrowser(){
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

port = System.getenv("PORT");
if (port == null) {
port = "4567";
}
baseUrl = "http://localhost:" + port;
}

@AfterClass
public static void closeBrowser(){
driver.quit();
}
}
25 changes: 25 additions & 0 deletions src/selenium/java/is/ru/arnlaugsson/chuck_joke/TestChuckWeb.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package is.ru.arnlaugsson.chuck_joke;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class TestChuckWeb extends SeleniumTestWrapper {
@Test
public void titleMatches() {
driver.get(baseUrl);
assertEquals("Chuck Norris Jokes", driver.getTitle());
}

@Test
public void assertUpdatingNameChangesSpecificJoke() {
driver.get(baseUrl + "/config.html");
/*
1. Fill in some name (first name, last name)
2. Submit form.
3. Assert that form notifies of success ("Name set as: ...")
4. Navigate to page to get specific Joke
5. Enter a specific joke number
6. Assert the name is used in the joke.
*/
}
}

0 comments on commit fc3033d

Please sign in to comment.