From e33814ff839fb457b3cb7eedc87c385563c86ca5 Mon Sep 17 00:00:00 2001 From: arnlaugsson Date: Tue, 25 Oct 2016 22:49:22 +0000 Subject: [PATCH 1/3] Add selenium sourceSet and dependencies --- build.gradle | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 4fad630..01fd8fe 100644 --- a/build.gradle +++ b/build.gradle @@ -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 +} From 3a3c2b4fd513a24ce6db8accdb654157d474fde8 Mon Sep 17 00:00:00 2001 From: arnlaugsson Date: Tue, 25 Oct 2016 22:50:32 +0000 Subject: [PATCH 2/3] Add SeleniumTestWrapper helper class --- .../chuck_joke/SeleniumTestWrapper.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/selenium/java/is/ru/arnlaugsson/chuck_joke/SeleniumTestWrapper.java diff --git a/src/selenium/java/is/ru/arnlaugsson/chuck_joke/SeleniumTestWrapper.java b/src/selenium/java/is/ru/arnlaugsson/chuck_joke/SeleniumTestWrapper.java new file mode 100644 index 0000000..bb63219 --- /dev/null +++ b/src/selenium/java/is/ru/arnlaugsson/chuck_joke/SeleniumTestWrapper.java @@ -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(); + } +} From 9e79d69a81b292e33003bbc674d1c4a79c9a02e8 Mon Sep 17 00:00:00 2001 From: arnlaugsson Date: Tue, 25 Oct 2016 22:51:14 +0000 Subject: [PATCH 3/3] Add simple titleMatches test and a skeleton for another test --- .../arnlaugsson/chuck_joke/TestChuckWeb.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/selenium/java/is/ru/arnlaugsson/chuck_joke/TestChuckWeb.java diff --git a/src/selenium/java/is/ru/arnlaugsson/chuck_joke/TestChuckWeb.java b/src/selenium/java/is/ru/arnlaugsson/chuck_joke/TestChuckWeb.java new file mode 100644 index 0000000..a59d3cb --- /dev/null +++ b/src/selenium/java/is/ru/arnlaugsson/chuck_joke/TestChuckWeb.java @@ -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. + */ + } +}