mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:15:50 +00:00
Add selenium and two selenium tests to the project
This commit is contained in:
parent
d129f24d9f
commit
1260b6ec5f
5 changed files with 353 additions and 219 deletions
|
@ -6,6 +6,7 @@ services:
|
|||
- "8080:8080"
|
||||
links:
|
||||
- mysql:mysql
|
||||
- selenium
|
||||
command: java -jar ./target/*.jar
|
||||
mysql:
|
||||
image: mysql
|
||||
|
@ -16,3 +17,8 @@ services:
|
|||
- MYSQL_DATABASE=test
|
||||
volumes:
|
||||
- "./conf.d:/etc/mysql/conf.d:ro"
|
||||
selenium:
|
||||
image: selenium/standalone-firefox
|
||||
shm_size: 2g
|
||||
ports:
|
||||
- "4444:4444"
|
||||
|
|
12
pom.xml
12
pom.xml
|
@ -31,6 +31,7 @@
|
|||
|
||||
<cobertura.version>2.7</cobertura.version>
|
||||
|
||||
<selenium-java.version>3.4.0</selenium-java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -116,6 +117,13 @@
|
|||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!--Selenium-->
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>${selenium-java.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -146,7 +154,7 @@
|
|||
<artifactId>cobertura-maven-plugin</artifactId>
|
||||
<version>${cobertura.version}</version>
|
||||
<configuration>
|
||||
<check />
|
||||
<check/>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
|
@ -220,7 +228,7 @@
|
|||
<formats>
|
||||
<format>html</format>
|
||||
</formats>
|
||||
<check />
|
||||
<check/>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
|
47
src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java
Normal file
47
src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java
Normal file
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
30
src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java
Normal file
30
src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
43
src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java
Normal file
43
src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue