mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-26 00:45:50 +00:00
Merge pull request #1 from cleankod/cucumber
QA assignment based on Cucumber
This commit is contained in:
commit
335352deb8
10 changed files with 292 additions and 107 deletions
32
ASSIGNMENT.md
Normal file
32
ASSIGNMENT.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
# QA Assignment
|
||||
|
||||
## How to start?
|
||||
1. Fork the project's repository.
|
||||
2. Follow the instructions in the [readme](readme.md) file.
|
||||
3. Create a pull request with your changes.
|
||||
|
||||
## Running tests
|
||||
You can run the Cucumber features from your IDE or via the command line:
|
||||
```shell
|
||||
./mvnw -P itest integration-test
|
||||
```
|
||||
Make sure the application is not started elsewhere. If it is, the `8080` port used by the application will already be occupied,
|
||||
and therefore the tests will fail.
|
||||
|
||||
## Assignment
|
||||
|
||||
### Finding owners
|
||||
The scenarios for this feature are incomplete or even naive. Please cover more cases in more reliable way.
|
||||
Open the `src/test/resources/scenarios/FindOwners.feature` and follow instructions given in the comments.
|
||||
|
||||
### Adding owners
|
||||
Open `src/test/resources/scenarios/AddOwners.feature` and follow instructions given in the comments.
|
||||
|
||||
### Report bugs
|
||||
Report any found bugs in the best possible format you can think of.
|
||||
|
||||
### Bonus tasks
|
||||
1. The browser doesn't close after all tests. Please fix it.
|
||||
2. There is something wrong with the way the HTML elements are selected.
|
||||
Prepare a suggestion of how to improve it or even implement such a change.
|
||||
3. Suggest a replacement for Selenium.
|
78
pom.xml
78
pom.xml
|
@ -119,6 +119,49 @@
|
|||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Testing-->
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-java</artifactId>
|
||||
<version>6.10.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-junit</artifactId>
|
||||
<version>6.10.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-spring</artifactId>
|
||||
<version>6.10.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>3.141.59</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.bonigarcia</groupId>
|
||||
<artifactId>webdrivermanager</artifactId>
|
||||
<version>4.4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.19.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -368,6 +411,41 @@
|
|||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>itest</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
<configuration>
|
||||
<testSourceDirectory>test/integration</testSourceDirectory>
|
||||
<includes>
|
||||
<include>**/CucumberRunner.java</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/*Tests.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration-test</id>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>verify</id>
|
||||
<goals>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
|
|
139
readme.md
139
readme.md
|
@ -1,133 +1,58 @@
|
|||
# Spring PetClinic Sample Application [](https://travis-ci.org/spring-projects/spring-petclinic/)
|
||||
# PetClinic Sample Application [](https://travis-ci.org/spring-projects/spring-petclinic/)
|
||||
|
||||
## Understanding the Spring Petclinic application with a few diagrams
|
||||
<a href="https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application">See the presentation here</a>
|
||||
## About
|
||||
Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/).
|
||||
|
||||
## Prerequisites
|
||||
The following items should be installed in your system:
|
||||
* JDK 11 or newer.
|
||||
* `git` command line tool (https://help.github.com/articles/set-up-git)
|
||||
* Your preferred IDE
|
||||
* IntelliJ IDEA
|
||||
* Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is
|
||||
not there, just follow the install process here: https://www.eclipse.org/m2e/
|
||||
* [Spring Tools Suite](https://spring.io/tools) (STS)
|
||||
* [VS Code](https://code.visualstudio.com)
|
||||
|
||||
## Running petclinic locally
|
||||
Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/). You can build a jar file and run it from the command line:
|
||||
|
||||
You can build a jar file and run it from the command line:
|
||||
|
||||
```
|
||||
git clone https://github.com/spring-projects/spring-petclinic.git
|
||||
# Clone the repository (remember to change the URL to your forked one):
|
||||
git clone git@github.com:cleankod/spring-petclinic.git
|
||||
|
||||
# Change working directory to inside the project:
|
||||
cd spring-petclinic
|
||||
|
||||
# Build:
|
||||
./mvnw package
|
||||
|
||||
# Run:
|
||||
java -jar target/*.jar
|
||||
```
|
||||
|
||||
You can then access petclinic here: http://localhost:8080/
|
||||
You can then access the application here: http://localhost:8080/
|
||||
|
||||
<img width="1042" alt="petclinic-screenshot" src="https://cloud.githubusercontent.com/assets/838318/19727082/2aee6d6c-9b8e-11e6-81fe-e889a5ddfded.png">
|
||||
|
||||
Or you can run it from Maven directly using the Spring Boot Maven plugin. If you do this it will pick up changes that you make in the project immediately (changes to Java source files require a compile as well - most people use an IDE for this):
|
||||
Or you can run it from Maven directly using the Spring Boot Maven plugin. If you do this it will pick up changes that you make in the project immediately
|
||||
(changes to Java source files require a compilation as well - most people use an IDE for this):
|
||||
|
||||
```
|
||||
./mvnw spring-boot:run
|
||||
```
|
||||
|
||||
## In case you find a bug/suggested improvement for Spring Petclinic
|
||||
Our issue tracker is available here: https://github.com/spring-projects/spring-petclinic/issues
|
||||
|
||||
|
||||
## Database configuration
|
||||
|
||||
In its default configuration, Petclinic uses an in-memory database (H2) which
|
||||
gets populated at startup with data. The h2 console is automatically exposed at `http://localhost:8080/h2-console`
|
||||
and it is possible to inspect the content of the database using the `jdbc:h2:mem:testdb` url.
|
||||
|
||||
A similar setup is provided for MySql in case a persistent database configuration is needed. Note that whenever the database type is changed, the app needs to be run with a different profile: `spring.profiles.active=mysql` for MySql.
|
||||
|
||||
You could start MySql locally with whatever installer works for your OS, or with docker:
|
||||
|
||||
```
|
||||
docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8
|
||||
```
|
||||
|
||||
Further documentation is provided [here](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt).
|
||||
|
||||
## Working with Petclinic in your IDE
|
||||
|
||||
### Prerequisites
|
||||
The following items should be installed in your system:
|
||||
* Java 8 or newer.
|
||||
* git command line tool (https://help.github.com/articles/set-up-git)
|
||||
* Your preferred IDE
|
||||
* Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is
|
||||
not there, just follow the install process here: https://www.eclipse.org/m2e/
|
||||
* [Spring Tools Suite](https://spring.io/tools) (STS)
|
||||
* IntelliJ IDEA
|
||||
* [VS Code](https://code.visualstudio.com)
|
||||
|
||||
### Steps:
|
||||
|
||||
1) On the command line
|
||||
```
|
||||
git clone https://github.com/spring-projects/spring-petclinic.git
|
||||
```
|
||||
2) Inside Eclipse or STS
|
||||
```
|
||||
File -> Import -> Maven -> Existing Maven project
|
||||
```
|
||||
1) Inside IntelliJ IDEA, in the main menu, choose `File -> Open` and select the Petclinic's [pom.xml](pom.xml). Click on the `Open` button.
|
||||
|
||||
Then either build on the command line `./mvnw generate-resources` or using the Eclipse launcher (right click on project and `Run As -> Maven install`) to generate the css. Run the application main method by right clicking on it and choosing `Run As -> Java Application`.
|
||||
CSS files are generated from the Maven build. You can either build them on the command line `./mvnw generate-resources` or right click on the
|
||||
`spring-petclinic` project then `Maven -> Generates sources and Update Folders`.
|
||||
|
||||
3) Inside IntelliJ IDEA
|
||||
In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button.
|
||||
A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application
|
||||
by right clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`.
|
||||
|
||||
CSS files are generated from the Maven build. You can either build them on the command line `./mvnw generate-resources` or right click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`.
|
||||
|
||||
A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`.
|
||||
|
||||
4) Navigate to Petclinic
|
||||
2) Navigate to Petclinic
|
||||
|
||||
Visit [http://localhost:8080](http://localhost:8080) in your browser.
|
||||
|
||||
|
||||
## Looking for something in particular?
|
||||
|
||||
|Spring Boot Configuration | Class or Java property files |
|
||||
|--------------------------|---|
|
||||
|The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) |
|
||||
|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) |
|
||||
|Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) |
|
||||
|
||||
## Interesting Spring Petclinic branches and forks
|
||||
|
||||
The Spring Petclinic "main" branch in the [spring-projects](https://github.com/spring-projects/spring-petclinic)
|
||||
GitHub org is the "canonical" implementation, currently based on Spring Boot and Thymeleaf. There are
|
||||
[quite a few forks](https://spring-petclinic.github.io/docs/forks.html) in a special GitHub org
|
||||
[spring-petclinic](https://github.com/spring-petclinic). If you have a special interest in a different technology stack
|
||||
that could be used to implement the Pet Clinic then please join the community there.
|
||||
|
||||
|
||||
## Interaction with other open source projects
|
||||
|
||||
One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found some bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days.
|
||||
Here is a list of them:
|
||||
|
||||
| Name | Issue |
|
||||
|------|-------|
|
||||
| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://jira.springsource.org/browse/SPR-10256) and [SPR-10257](https://jira.springsource.org/browse/SPR-10257) |
|
||||
| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) |
|
||||
| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://jira.springsource.org/browse/DATAJPA-292) |
|
||||
|
||||
|
||||
# Contributing
|
||||
|
||||
The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, features requests and submitting pull requests.
|
||||
|
||||
For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at <https://editorconfig.org>. If you have not previously done so, please fill out and submit the [Contributor License Agreement](https://cla.pivotal.io/sign/spring).
|
||||
|
||||
# License
|
||||
|
||||
The Spring PetClinic sample application is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0).
|
||||
|
||||
[spring-petclinic]: https://github.com/spring-projects/spring-petclinic
|
||||
[spring-framework-petclinic]: https://github.com/spring-petclinic/spring-framework-petclinic
|
||||
[spring-petclinic-angularjs]: https://github.com/spring-petclinic/spring-petclinic-angularjs
|
||||
[javaconfig branch]: https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig
|
||||
[spring-petclinic-angular]: https://github.com/spring-petclinic/spring-petclinic-angular
|
||||
[spring-petclinic-microservices]: https://github.com/spring-petclinic/spring-petclinic-microservices
|
||||
[spring-petclinic-reactjs]: https://github.com/spring-petclinic/spring-petclinic-reactjs
|
||||
[spring-petclinic-graphql]: https://github.com/spring-petclinic/spring-petclinic-graphql
|
||||
[spring-petclinic-kotlin]: https://github.com/spring-petclinic/spring-petclinic-kotlin
|
||||
[spring-petclinic-rest]: https://github.com/spring-petclinic/spring-petclinic-rest
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package org.springframework.samples.petclinic.integration;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openqa.selenium.Dimension;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.chrome.ChromeDriverService;
|
||||
import org.openqa.selenium.chrome.ChromeOptions;
|
||||
|
||||
import io.github.bonigarcia.wdm.WebDriverManager;
|
||||
|
||||
public class Browser {
|
||||
|
||||
public final static WebDriver webDriver = createDriver();
|
||||
|
||||
private static WebDriver createDriver() {
|
||||
setupDriver();
|
||||
ChromeDriver chromeDriver = new ChromeDriver(new ChromeDriverService.Builder().withSilent(true).build(),
|
||||
chromeOptions());
|
||||
chromeDriver.manage().window().setSize(new Dimension(1024, 768));
|
||||
chromeDriver.manage().timeouts().implicitlyWait(0L, TimeUnit.SECONDS);
|
||||
return chromeDriver;
|
||||
}
|
||||
|
||||
private static void setupDriver() {
|
||||
WebDriverManager.chromedriver().timeout(60).setup();
|
||||
}
|
||||
|
||||
private static ChromeOptions chromeOptions() {
|
||||
final ChromeOptions chromeOptions = new ChromeOptions();
|
||||
chromeOptions.addArguments("enable-automation");
|
||||
chromeOptions.addArguments("--no-sandbox");
|
||||
chromeOptions.addArguments("--disable-infobars");
|
||||
chromeOptions.addArguments("--disable-dev-shm-usage");
|
||||
chromeOptions.addArguments("--disable-browser-side-navigation");
|
||||
return chromeOptions;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package org.springframework.samples.petclinic.integration;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import io.cucumber.junit.Cucumber;
|
||||
import io.cucumber.junit.CucumberOptions;
|
||||
|
||||
@RunWith(Cucumber.class)
|
||||
@CucumberOptions(plugin = { "pretty", "html:target/cucumber-html-report" },
|
||||
glue = { "org.springframework.samples.petclinic.integration" }, features = "classpath:scenarios")
|
||||
public class CucumberRunner {
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.springframework.samples.petclinic.integration;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import io.cucumber.spring.CucumberContextConfiguration;
|
||||
|
||||
@CucumberContextConfiguration
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
public abstract class SpringIntegrationTest {
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package org.springframework.samples.petclinic.integration;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
import io.cucumber.java.en.Given;
|
||||
import io.cucumber.java.en.Then;
|
||||
import io.cucumber.java.en.When;
|
||||
|
||||
public class StepDefinition extends SpringIntegrationTest {
|
||||
|
||||
public static final String BASE_URL = "http://localhost:8080";
|
||||
|
||||
private final WebDriver webDriver = Browser.webDriver;
|
||||
|
||||
@Given("^I go to the main page$")
|
||||
public void mainPage() {
|
||||
webDriver.navigate().to(BASE_URL);
|
||||
}
|
||||
|
||||
@Given("^I go to the find-owners page$")
|
||||
public void findOwnersPage() {
|
||||
webDriver.navigate().to(BASE_URL + "/owners/find");
|
||||
}
|
||||
|
||||
@When("^I click on the link with title \"([^\"]*)\"$")
|
||||
public void clickOnLinkWithTitle(String linkTitle) {
|
||||
By elementSelector = By.xpath(String.format("//*[@title='%s']", linkTitle));
|
||||
new WebDriverWait(webDriver, 60L).until(driver -> driver.findElement(elementSelector).isDisplayed());
|
||||
WebElement webElement = webDriver.findElement(elementSelector);
|
||||
webElement.click();
|
||||
}
|
||||
|
||||
@Then("^I should see the \"([^\"]*)\" page$")
|
||||
public void shouldSeeThePage(String pageTitle) {
|
||||
By elementSelector = By.tagName("h2");
|
||||
new WebDriverWait(webDriver, 60L).until(driver -> driver.findElement(elementSelector).isDisplayed());
|
||||
WebElement webElement = webDriver.findElement(elementSelector);
|
||||
assertThat(webElement.getText()).isEqualTo(pageTitle);
|
||||
}
|
||||
|
||||
@When("^I fill the field named \"([^\"]*)\" with value \"([^\"]*)\"$")
|
||||
public void fillInputBoxWithValue(String name, String value) {
|
||||
By elementSelector = By.name(name);
|
||||
WebElement webElement = webDriver.findElement(elementSelector);
|
||||
webElement.sendKeys(value);
|
||||
}
|
||||
|
||||
@When("^I submit the form \"([^\"]*)\"$")
|
||||
public void submitForm(String id) {
|
||||
By elementSelector = By.id(id);
|
||||
WebElement webElement = webDriver.findElement(elementSelector);
|
||||
webElement.submit();
|
||||
}
|
||||
|
||||
}
|
3
src/test/resources/scenarios/AddOwners.feature
Normal file
3
src/test/resources/scenarios/AddOwners.feature
Normal file
|
@ -0,0 +1,3 @@
|
|||
Feature: Add owners
|
||||
|
||||
# Add scenarios covering all cases.
|
18
src/test/resources/scenarios/FindOwners.feature
Normal file
18
src/test/resources/scenarios/FindOwners.feature
Normal file
|
@ -0,0 +1,18 @@
|
|||
Feature: Find owners
|
||||
|
||||
Scenario: Find owners page
|
||||
Given I go to the main page
|
||||
When I click on the link with title "find owners"
|
||||
Then I should see the "Find Owners" page
|
||||
|
||||
Scenario: Should find an owner
|
||||
When I fill the field named "lastName" with value "Franklin"
|
||||
And I submit the form "search-owner-form"
|
||||
Then I should see the "Owner Information" page
|
||||
|
||||
Scenario: Should find multiple owners
|
||||
Given I go to the find-owners page
|
||||
When I fill the field named "lastName" with value "Davis"
|
||||
And I submit the form "search-owner-form"
|
||||
Then I should see the "Owners" page
|
||||
# Add additional checks here.
|
5
src/test/resources/scenarios/MainPage.feature
Normal file
5
src/test/resources/scenarios/MainPage.feature
Normal file
|
@ -0,0 +1,5 @@
|
|||
Feature: Main page
|
||||
|
||||
Scenario: Main page
|
||||
When I go to the main page
|
||||
Then I should see the "Welcome" page
|
Loading…
Reference in a new issue