finalize 'Find owner' tests and add 'Add owner' tests

This commit is contained in:
Valentin-qa 2021-05-21 10:31:46 +03:00
parent 3705e4c8ec
commit a3efe259c8
5 changed files with 204 additions and 11 deletions

View file

@ -1,14 +1,14 @@
package org.springframework.samples.petclinic.integration;
import java.util.concurrent.TimeUnit;
import io.github.bonigarcia.wdm.WebDriverManager;
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 org.springframework.test.context.event.annotation.AfterTestClass;
import io.github.bonigarcia.wdm.WebDriverManager;
import java.util.concurrent.TimeUnit;
public class Browser {
@ -17,7 +17,7 @@ public class Browser {
private static WebDriver createDriver() {
setupDriver();
ChromeDriver chromeDriver = new ChromeDriver(new ChromeDriverService.Builder().withSilent(true).build(),
chromeOptions());
chromeOptions());
chromeDriver.manage().window().setSize(new Dimension(1024, 768));
chromeDriver.manage().timeouts().implicitlyWait(0L, TimeUnit.SECONDS);
return chromeDriver;
@ -37,4 +37,8 @@ public class Browser {
return chromeOptions;
}
}

View file

@ -1,15 +1,14 @@
package org.springframework.samples.petclinic.integration;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
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;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
public class StepDefinition extends SpringIntegrationTest {
@ -57,4 +56,63 @@ public class StepDefinition extends SpringIntegrationTest {
webElement.submit();
}
@Then("I should see {string} error")
public void shouldSeeErrorOnFindOwnerPage(String error) {
By elementSelector = By.tagName("p");
new WebDriverWait(webDriver, 60L).until(driver -> driver.findElement(elementSelector).isDisplayed());
WebElement webElement = webDriver.findElement(elementSelector);
assertThat(webElement.getText()).isEqualTo(error);
}
@Given("I go to add owner page")
public void goToAddOwnerPage() {
webDriver.navigate().to(BASE_URL + "/owners/new");
}
@Then("I should see {string} error message")
public void shouldSeeErrorMessageOnAddOwnerPage(String error) {
By elementSelector = By.xpath("//span[@class='help-inline']");
new WebDriverWait(webDriver, 60L).until(driver -> driver.findElement(elementSelector).isDisplayed());
WebElement webElement = webDriver.findElement(elementSelector);
assertThat(webElement.getText()).contains(error);
}
@When("I click on the link with heading {string}")
public void clickOnTheLinkWithHeading(String heading) {
By elementSelector = By.xpath(String.format("//*[text()='%s']", heading));
new WebDriverWait(webDriver, 60L).until(driver -> driver.findElement(elementSelector).isDisplayed());
WebElement webElement = webDriver.findElement(elementSelector);
webElement.click();
}
@Then("I should see {string} exception")
public void shouldSeeException(String exception) {
By elementSelector = By.tagName("h2");
new WebDriverWait(webDriver, 60L).until(driver -> driver.findElement(elementSelector).isDisplayed());
WebElement webElement = webDriver.findElement(elementSelector);
assertThat(webElement.getText()).contains(exception);
}
@Then("I should see owner named {string}")
public void shouldSeeOwnerInformationOnOwnerPage(String lastName) {
By elementSelector = By.xpath("//table[@class='table table-striped']//b");
new WebDriverWait(webDriver, 60L).until(driver -> driver.findElement(elementSelector).isDisplayed());
WebElement webElement = webDriver.findElement(elementSelector);
assertThat(webElement.getText()).contains(lastName);
}
@Then("I should see owners named {string}")
public void shouldSeeMultipleOwnersInformationOnOwnersPage(String lastName) {
By elementSelector = By.xpath("//table[@id='owners']//a");
new WebDriverWait(webDriver, 60L).until(driver -> driver.findElement(elementSelector).isDisplayed());
WebElement webElement = webDriver.findElement(elementSelector);
assertThat(webElement.getText()).contains(lastName);
}
}

View file

@ -1,3 +1,100 @@
Feature: Add owners
# Add scenarios covering all cases.
Scenario: Go to Add Owner page
Given I go to the main page
Then I go to the find-owners page
When I click on the link with heading "Add Owner"
Then I should see the "Owner" page
Scenario: Add new owner
Given I go to add owner page
Then I fill the field named "firstName" with value "John"
And I fill the field named "lastName" with value "Smith"
And I fill the field named "address" with value "50th Street"
And I fill the field named "city" with value "New York"
And I fill the field named "telephone" with value "1234567"
And I submit the form "add-owner-form"
Then I should see the "Owner Information" page
Scenario: Try and fail to add new owner without name
Given I go to add owner page
Then I fill the field named "firstName" with value ""
And I fill the field named "lastName" with value "Smith"
And I fill the field named "address" with value "50th Street"
And I fill the field named "city" with value "New York"
And I fill the field named "telephone" with value "1234567"
And I submit the form "add-owner-form"
Then I should see "must not be empty" error message
Scenario: Try and fail to add new owner with name with length>32 characters
Given I go to add owner page
Then I fill the field named "firstName" with value "qwertyuiopasdfghjklzxcvbnmqwertyu"
And I fill the field named "lastName" with value "Smith"
And I fill the field named "address" with value "50th Street"
And I fill the field named "city" with value "New York"
And I fill the field named "telephone" with value "1234567"
And I submit the form "add-owner-form"
Then I should see "Something happened..." exception
Scenario: Try and fail to add new owner with last name with length>32 characters
Given I go to add owner page
Then I fill the field named "firstName" with value "John"
And I fill the field named "lastName" with value "qwertyuiopasdfghjklzxcvbnmqwertyu"
And I fill the field named "address" with value "50th Street"
And I fill the field named "city" with value "New York"
And I fill the field named "telephone" with value "1234567"
And I submit the form "add-owner-form"
Then I should see "Something happened..." exception
Scenario: Try and fail to add new owner without lastname
Given I go to add owner page
Then I fill the field named "firstName" with value "John"
And I fill the field named "lastName" with value ""
And I fill the field named "address" with value "50th Street"
And I fill the field named "city" with value "New York"
And I fill the field named "telephone" with value "1234567"
And I submit the form "add-owner-form"
Then I should see "must not be empty" error message
Scenario: Try and fail to add new owner without address
Given I go to add owner page
Then I fill the field named "firstName" with value "John"
And I fill the field named "lastName" with value "Smith"
And I fill the field named "address" with value ""
And I fill the field named "city" with value "New York"
And I fill the field named "telephone" with value "1234567"
And I submit the form "add-owner-form"
Then I should see "must not be empty" error message
Scenario: Try and fail to add new owner without city
Given I go to add owner page
Then I fill the field named "firstName" with value "John"
And I fill the field named "lastName" with value "Smith"
And I fill the field named "address" with value "50th Street"
And I fill the field named "city" with value ""
And I fill the field named "telephone" with value "1234567"
And I submit the form "add-owner-form"
Then I should see "must not be empty" error message
Scenario: Try and fail to add new owner without telephone
Given I go to add owner page
Then I fill the field named "firstName" with value "John"
And I fill the field named "lastName" with value "Smith"
And I fill the field named "address" with value "50th Street"
And I fill the field named "city" with value "New York"
And I fill the field named "telephone" with value ""
And I submit the form "add-owner-form"
Then I should see "must not be empty" error message
Then I should see "numeric value out of bounds (<10 digits>.<0 digits> expected)" error message
Scenario: Try and fail to add new owner when fill literals instead of numbers in telephone field
Given I go to add owner page
Then I fill the field named "firstName" with value "John"
And I fill the field named "lastName" with value "Smith"
And I fill the field named "address" with value "50th Street"
And I fill the field named "city" with value "New York"
And I fill the field named "telephone" with value "hello"
And I submit the form "add-owner-form"
Then I should see "numeric value out of bounds (<10 digits>.<0 digits> expected)" error message

View file

@ -6,13 +6,46 @@ Feature: Find owners
Then I should see the "Find Owners" page
Scenario: Should find an owner
Given I go to the find-owners page
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
Then I should see owner named "Franklin"
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.
Then I should see owners named "Davis"
Scenario: Should find all users when input field is empty
Given I go to the find-owners page
When I fill the field named "lastName" with value ""
And I submit the form "search-owner-form"
Then I should see the "Owners" page
Scenario: Should see error message when wrong lastname is entered
Given I go to the find-owners page
When I fill the field named "lastName" with value "Brown"
And I submit the form "search-owner-form"
Then I should see "has not been found" error
Scenario: Should see error message when wrong few white spaces are entered
Given I go to the find-owners page
When I fill the field named "lastName" with value "Brown"
And I submit the form "search-owner-form"
Then I should see "has not been found" error
Scenario: Should see error message when 'number' lastname is entered
Given I go to the find-owners page
When I fill the field named "lastName" with value "12345"
And I submit the form "search-owner-form"
Then I should see "has not been found" error
Scenario: Should see error message when 'empty spaces' lastname is entered
Given I go to the find-owners page
When I fill the field named "lastName" with value " "
And I submit the form "search-owner-form"
Then I should see "has not been found" error

View file

@ -3,3 +3,4 @@ Feature: Main page
Scenario: Main page
When I go to the main page
Then I should see the "Welcome" page