From 1260b6ec5fa776bb920b09af18f8bcdde9791003 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Wed, 21 Jun 2017 11:32:14 +0200 Subject: [PATCH] Add selenium and two selenium tests to the project --- docker-compose.yml | 8 +- pom.xml | 444 +++++++++--------- .../utwente/bpsd/selenium/AddOwnerTest.java | 47 ++ .../utwente/bpsd/selenium/FindOwnerTest.java | 30 ++ .../bpsd/selenium/SeleniumBaseTest.java | 43 ++ 5 files changed, 353 insertions(+), 219 deletions(-) create mode 100644 src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java create mode 100644 src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java create mode 100644 src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java diff --git a/docker-compose.yml b/docker-compose.yml index b2c662c3f..73da6f62a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: - "8080:8080" links: - mysql:mysql + - selenium command: java -jar ./target/*.jar mysql: image: mysql @@ -15,4 +16,9 @@ services: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=test volumes: - - "./conf.d:/etc/mysql/conf.d:ro" \ No newline at end of file + - "./conf.d:/etc/mysql/conf.d:ro" + selenium: + image: selenium/standalone-firefox + shm_size: 2g + ports: + - "4444:4444" diff --git a/pom.xml b/pom.xml index ff677d097..757c84577 100644 --- a/pom.xml +++ b/pom.xml @@ -1,229 +1,237 @@ - 4.0.0 - org.springframework.samples - spring-petclinic - 1.5.1 + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + org.springframework.samples + spring-petclinic + 1.5.1 - - org.springframework.boot - spring-boot-starter-parent - 1.5.1.RELEASE - - petclinic - - - - - 1.8 - UTF-8 - UTF-8 - - - 3.3.6 - 1.11.4 - 2.2.4 - 1.8.0 - - 3.0.2.RELEASE - - 2.7 - - - - - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-cache - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - nz.net.ultraq.thymeleaf - thymeleaf-layout-dialect - - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - org.hsqldb - hsqldb - runtime - - - mysql - mysql-connector-java - runtime - - - - - javax.cache - cache-api - - - org.ehcache - ehcache - - - - - org.webjars - webjars-locator - - - org.webjars - jquery - ${webjars-jquery.version} - - - org.webjars - jquery-ui - ${webjars-jquery-ui.version} - - - org.webjars - bootstrap - ${webjars-bootstrap.version} - - - - - org.springframework.boot - spring-boot-devtools - runtime - - - - - - + org.springframework.boot - spring-boot-maven-plugin - - - - - build-info - - - - ${project.build.sourceEncoding} - ${project.reporting.outputEncoding} - ${maven.compiler.source} - ${maven.compiler.target} - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura.version} - - - - - - - clean - check - - - - + spring-boot-starter-parent + 1.5.1.RELEASE + + petclinic - - - pl.project13.maven - git-commit-id-plugin - - - - revision - - - - - true - yyyy-MM-dd'T'HH:mm:ssZ - true - ${project.build.outputDirectory}/git.properties - - false - - + - - ro.isdc.wro4j - wro4j-maven-plugin - ${wro4j.version} - - - generate-resources - - run - - - - - ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory - ${project.build.directory}/classes/static/resources/css - ${basedir}/src/main/wro/wro.xml - ${basedir}/src/main/wro/wro.properties - ${basedir}/src/main/less - - - + + 1.8 + UTF-8 + UTF-8 + + + 3.3.6 + 1.11.4 + 2.2.4 + 1.8.0 + + 3.0.2.RELEASE + + 2.7 + + 3.4.0 + + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-cache + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + nz.net.ultraq.thymeleaf + thymeleaf-layout-dialect + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.hsqldb + hsqldb + runtime + + + mysql + mysql-connector-java + runtime + + + + + javax.cache + cache-api + + + org.ehcache + ehcache + + + + + org.webjars + webjars-locator + + + org.webjars + jquery + ${webjars-jquery.version} + + + org.webjars + jquery-ui + ${webjars-jquery-ui.version} + + org.webjars bootstrap ${webjars-bootstrap.version} - - - - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura.version} - - - html - - - - - - + + + + + org.springframework.boot + spring-boot-devtools + runtime + + + + + org.seleniumhq.selenium + selenium-java + ${selenium-java.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + build-info + + + + ${project.build.sourceEncoding} + ${project.reporting.outputEncoding} + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura.version} + + + + + + + clean + check + + + + + + + + pl.project13.maven + git-commit-id-plugin + + + + revision + + + + + true + yyyy-MM-dd'T'HH:mm:ssZ + true + ${project.build.outputDirectory}/git.properties + + false + + + + + ro.isdc.wro4j + wro4j-maven-plugin + ${wro4j.version} + + + generate-resources + + run + + + + + ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory + ${project.build.directory}/classes/static/resources/css + ${basedir}/src/main/wro/wro.xml + ${basedir}/src/main/wro/wro.properties + ${basedir}/src/main/less + + + + org.webjars + bootstrap + ${webjars-bootstrap.version} + + + + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura.version} + + + html + + + + + + diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java new file mode 100644 index 000000000..888e501c3 --- /dev/null +++ b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java @@ -0,0 +1,47 @@ +package nl.utwente.bpsd.selenium; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.net.MalformedURLException; + +/** + * @author Martijn + * @since 21-6-2017. + */ +public class AddOwnerTest extends SeleniumBaseTest { + public AddOwnerTest() throws MalformedURLException { + super(); + } + + @Test + @Category(SeleniumBaseTest.class) + public void addOwnerTest() { + driver.get(BASE_URL+"/owners/new"); + + //Add an owner + fillTextField(By.name("firstName"), "Sophie"); + fillTextField(By.name("lastName"), "Lathouwers"); + fillTextField(By.name("address"), "Homeroad 12"); + fillTextField(By.name("city"), "Enschede"); + fillTextField(By.name("telephone"), "0534890000"); + driver.findElement(By.name("telephone")).submit(); + Assert.assertTrue(pageContainsText("Sophie Lathouwers")); + + //Add a pet + new WebDriverWait(driver, 3).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText("Add New Pet"))); + driver.findElement(By.linkText("Add New Pet")).click(); + fillTextField(By.name("name"), "Thumper"); + fillTextField(By.name("birthDate"), "1942/08/09"); + new Select(driver.findElement(By.name("type"))).selectByValue("hamster"); + driver.findElement(By.name("name")).submit(); + + Assert.assertTrue(pageContainsText("Thumper")); + } + +} diff --git a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java new file mode 100644 index 000000000..ff6700f6d --- /dev/null +++ b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java @@ -0,0 +1,30 @@ +package nl.utwente.bpsd.selenium; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.net.MalformedURLException; + +/** + * + * @author Martijn + * @since 21-6-2017. + */ +public class FindOwnerTest extends SeleniumBaseTest { + public FindOwnerTest() throws MalformedURLException { + super(); + } + + @Test + @Category(SeleniumBaseTest.class) + public void findOwnerTest() { + driver.get(BASE_URL+"/owners/find"); + fillTextField(By.name("lastName"),"Coleman"); + driver.findElement(By.name("lastName")).submit(); + Assert.assertTrue(driver.findElementsByXPath("//*[text()='Jean Coleman']").size() == 1); + } +} diff --git a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java new file mode 100644 index 000000000..8b72d1edf --- /dev/null +++ b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java @@ -0,0 +1,43 @@ +package nl.utwente.bpsd.selenium; + +import org.junit.After; +import org.openqa.selenium.By; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; + +import java.net.MalformedURLException; +import java.net.URL; + +/** + * + * @author Martijn + * @since 21-6-2017. + */ +public class SeleniumBaseTest { + protected final RemoteWebDriver driver; + public static final String BASE_URL = "http://pet-clinic:8080/"; +// public static final String BASE_URL = "http://localhost:8080/"; + + public SeleniumBaseTest() throws MalformedURLException { +// System.setProperty("webdriver.chrome.driver","C:\\Users\\marti\\Downloads\\chromedriver_win32\\chromedriver.exe"); +// this.driver = new ChromeDriver(); + this.driver = new RemoteWebDriver(new URL("http://selenium:4444/wd/hub"), DesiredCapabilities.firefox()); + driver.get(BASE_URL); + } + + public void fillTextField(By by, String text){ + driver.findElement(by).clear(); + driver.findElement(by).sendKeys(text); + } + + @After + public void afterTest() { + driver.close(); + } + + + protected boolean pageContainsText(String text) { + return driver.findElementsByXPath("//*[text()='"+text+"']").size() == 1; + } +}