Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Feature: Patient Exercise Diary Functionality
- I want to be able to add, edit, and view exercise diaries
- So I can share and view my health data
- Scenario Outline: Patient has no exercise diary entries (patientViewExerciseOnStartup)
- Given There is a patient in the system, and there are no exercise diary entries
- Then I log on as a patient for exercise diaries.
- When I navigate to the view exercise diary entries page.
- Then <text> shows.
- Examples:
- | text |
- | There are no Exercise Diary entries. |
- Scenario Outline: The Add exercise diary entry as a patient displays correctly on startup (patientAddOnStartup)
- Given There is a patient in the system.
- Then I log on as a patient for exercise diaries.
- When I navigate to the Add Exercise Diary Entry page.
- Then the exercise diary entry is blank
- Scenario Outline: Add exercise diary entry as patient (TestAddExerciseValid)
- Given There is a patient in the system.
- Then I log on as a patient for exercise diaries.
- When I navigate to the Add Exercise Diary Entry page.
- And I choose to add a new exercise diary entry with <date>, <type>, <name>, <duration>, <caloriesBurned>.
- Then The exercise diary entry is added successfully and the patient is returned to the view exercise diary page.
- Examples:
- | date | type | name | duration | caloriesBurned |
- | 02/06/2019 | Endurance | Cross-Country Ski | 60 | 500 |
- Scenario Outline: Invalid add exercise diary entry as patient (TestAddExerciseInvalid)
- Given There is a patient in the system.
- Then I log on as a patient for exercise diaries.
- When I navigate to the Add Exercise Diary Entry page.
- And I choose to incorrectly add a new exercise diary entry with <date>, <type>, <name>, <duration>, <caloriesBurned>.
- Then "Please input a valid date." shows
- And The exercise diary entry is not added.
- Examples:
- | date | type | name | duration | caloriesBurned |
- | 02/06/2020 | Strength | Building Strong Character | 60 | 400 |
- Scenario Outline: View exercise diary entry as a Patient (patientViewExercise)
- Given There is a patient in the system.
- And The patient has added an entry <date>, <type>, <name>, <duration>, <caloriesBurned>.
- Then The patient has navigated to view exercise diary page.
- And The patient chooses <date>.
- Then The patient can view the entry <date>, <type>, <name>, <duration>, <caloriesBurned>.
- And This patient's action is logged on the iTrust2 homepage.
- Examples:
- | date | type | name | duration | caloriesBurned |
- | 02/06/2018 | Endurance | Cross-Country Ski | 60 | 500 |
- Scenario Outline: View exercise diary entry as an HCP (hcpView)
- Given There is an patient in the system.
- And There is an HCP in the system.
- And The patient has added an entry <date>, <type>, <name>, <duration>, <caloriesBurned>.
- Then The HCP logs in and navigates to the view patient exercise diary entry page.
- And The HCP chooses the entries for the patient on <date>.
- Then The HCP can view the entry <date>, <type>, <name>, <duration>, <caloriesBurned>.
- And The HCP's action is logged on the iTrust2 homepage.
- Examples:
- | date | type | name | duration | caloriesBurned |
- | 02/06/2018 | Endurance | Cross-Country Ski | 60 | 500 |
- Scenario Outline: Edit exercise diary entry successfully (TestEditExerciseValid)
- Given There is an patient in the system.
- And The patient has added an entry <date>, <type>, <name>, <duration>, <caloriesBurned>.
- Then I log on as a patient for exercise diaries.
- When I navigate to the Edit Exercise Diary Entry page.
- And The patient chooses the name <name>.
- Then I successfully edit that exercise to have name: <newName>.
- And The recipe is edited.
- Scenario Outline: Edit exercise diary entry unsuccessfully (TestEditExerciseInvalid1, TestEditExerciseInvalid2)
- Given There is an patient in the system.
- And The patient has added an entry <date>, <type>, <name>, <duration>, <caloriesBurned>.
- Then I log on as a patient for exercise diaries.
- When I navigate to the Edit Exercise Diary Entry page.
- And The patient chooses <name>.
- Then I edit the duration to be: <negativeNumber>
- And <text> shows.
- When I edit the date to be <invalidDate>
- Then <text> shows
- Examples:
- | 06/07/2019 | Endurance | Enduring CSC326 | -60 | 400 |
- | mm/dd/yyyy | Flexibility | Yoga | 1 | 400 |
- package edu.ncsu.csc.itrust2.cucumber;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertTrue;
- import static org.junit.Assert.fail;
- import java.util.List;
- import org.openqa.selenium.By;
- import org.openqa.selenium.JavascriptExecutor;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.Select;
- import org.openqa.selenium.support.ui.WebDriverWait;
- import cucumber.api.java.en.And;
- import cucumber.api.java.en.Given;
- import cucumber.api.java.en.Then;
- import cucumber.api.java.en.When;
- import edu.ncsu.csc.itrust2.models.enums.Role;
- import edu.ncsu.csc.itrust2.models.persistent.Patient;
- import edu.ncsu.csc.itrust2.models.persistent.User;
- /**
- * Step definitions for FoodDiaryEntry feature.
- *
- * Citation: Most functions follow FoodDiaryEntryStepDefs very closely, 2/16/19.
- *
- * @author Frances Henshall (fahensha)
- * @author Daniel Izatt (djizatt)
- */
- public class ExerciseDiaryEntryStepDefs extends CucumberTest {
- private final String baseUrl = "http://localhost:8080/iTrust2";
- private final String patientString = "janice";
- private final String hcpString = "janiceDoctor";
- /**
- * Asserts that the text is on the page. Function copied from
- * FoodDiaryEntryStepDefs on 2/16/19.
- *
- * @param text
- * text to check
- */
- public void assertTextPresent ( final String text ) {
- try {
- assertTrue( driver.getPageSource().contains( text ) );
- }
- catch ( final Exception e ) {
- fail();
- }
- }
- private void clickAndCheckDateButton ( final String viewDate ) {
- final List<WebElement> radioList = driver.findElements( By.name( "date" ) );
- for ( final WebElement element : radioList ) {
- if ( element.getAttribute( "value" ).equals( viewDate ) ) {
- element.click();
- assertTextPresent( "Exercise Diary Entries for: " + viewDate );
- return;
- }
- }
- fail( "The date isn't in the radio list." );
- }
- private void clickAndCheckNameButton ( final String viewName ) {
- final List<WebElement> radioList = driver.findElements( By.name( "name" ) );
- for ( final WebElement element : radioList ) {
- if ( element.getAttribute( "value" ).equals( viewName ) ) {
- element.click();
- assertTextPresent( "Edit" );
- return;
- }
- }
- fail( "The date isn't in the radio list." );
- }
- /**
- * Attempts to log out any User who is logged in, then creates a new patient
- * User. The patient User is also created as a new Patient object.
- */
- @Given ( "^There is a patient in the system.$" )
- public void patientExistsDiaries () {
- attemptLogout();
- // Create the test User
- final User user = new User( patientString, "$2a$10$EblZqNptyYvcLm/VwDCVAuBjzZOI7khzdyGPBr08PpIi0na624b8.",
- Role.ROLE_PATIENT, 1 );
- user.save();
- // The User must also be created as a Patient
- // to show up in the list of Patients
- final Patient patient = new Patient( user.getUsername() );
- patient.save();
- // All tests can safely assume the existence of the 'hcp', 'admin', and
- // 'patient' users
- }
- /**
- * Attempts to log out any User who is logged in, then creates a new hcp
- * User.
- */
- @Given ( "^There is an HCP in the system.$" )
- public void hcpExistsDiaries () {
- attemptLogout();
- final User hcp = new User( hcpString, "$2a$10$EblZqNptyYvcLm/VwDCVAuBjzZOI7khzdyGPBr08PpIi0na624b8.",
- Role.ROLE_HCP, 1 );
- hcp.save();
- // All tests can safely assume the existence of the 'hcp', 'admin', and
- // 'patient' users
- }
- /**
- * Attempts to log out any User who is logged in, then logs in as a patient.
- */
- @Then ( "^I log on as a patient for exercise diaries.$" )
- public void loginPatientDiaries () {
- attemptLogout();
- driver.get( baseUrl );
- final WebElement username = driver.findElement( By.name( "username" ) );
- username.clear();
- username.sendKeys( patientString );
- final WebElement password = driver.findElement( By.name( "password" ) );
- password.clear();
- password.sendKeys( "123456" );
- final WebElement submit = driver.findElement( By.className( "btn" ) );
- submit.click();
- assertEquals( "iTrust2: Patient Home", driver.getTitle() );
- }
- /**
- * Navigates to the view Exercise Diary Entry page by type casting the
- * WebDriver to a JavascriptExecutor. Asserts that the title of the page is
- * correct.
- */
- @When ( "^I navigate to the view exercise diary entries page.$" )
- public void navigateToView () {
- ( (JavascriptExecutor) driver ).executeScript( "document.getElementById('viewExerciseDiaryEntries').click();" );
- assertEquals( "iTrust2: View Exercise Diary Entries", driver.getTitle() );
- }
- /**
- * Asserts that the correct text is displayed for the
- * viewExerciseDiaryEntries page when there are no entries.
- *
- * @param text
- * the text to display
- */
- @Then ( "^(.+) shows.$" )
- public void noDiaryEntries ( final String text ) {
- waitForAngular();
- assertTextPresent( text );
- }
- /**
- * Navigates to the add Exercise Diary Entry page by type casting the
- * WebDriver to a JavascriptExecutor. Asserts that the title of the page is
- * correct.
- */
- @When ( "^I navigate to the Add Exercise Diary Entry page.$" )
- public void requestAddDiaryPage () {
- ( (JavascriptExecutor) driver ).executeScript( "document.getElementById('addExerciseDiaryEntry').click();" );
- final WebDriverWait wait = new WebDriverWait( driver, 20 );
- wait.until( ExpectedConditions.titleContains( "Add Exercise Diary Entry" ) );
- assertEquals( "iTrust2: Add Exercise Diary Entry", driver.getTitle() );
- }
- /**
- * Adds a new exercise diary entry with valid input.
- *
- * @param date
- * the date of the exercise diary entry
- * @param type
- * the date of the exercise diary entry
- * @param name
- * the name of the exercise diary entry
- * @param duration
- * the duration of the exercise diary entry
- * @param caloriesBurned
- * the calories burned for the exercise diary entry
- */
- @And ( "^I choose to add a new exercise diary entry with (.+), (.+), (.+), (\\d+), (\\d+)\\.$" )
- public void addEntry ( final String date, final String type, final String name, final int duration,
- final int caloriesBurned ) {
- waitForAngular();
- final WebElement dateElement = driver.findElement( By.name( "date" ) );
- dateElement.sendKeys( date.replace( "/", "" ) );
- final Select dropdown = new Select( driver.findElement( By.name( "exerciseType" ) ) );
- dropdown.selectByVisibleText( type );
- driver.findElement( By.name( "name" ) ).clear();
- driver.findElement( By.name( "name" ) ).sendKeys( name );
- driver.findElement( By.name( "duration" ) ).clear();
- driver.findElement( By.name( "duration" ) ).sendKeys( Integer.toString( duration ) );
- driver.findElement( By.name( "caloriesBurned" ) ).clear();
- driver.findElement( By.name( "caloriesBurned" ) ).sendKeys( Integer.toString( caloriesBurned ) );
- driver.findElement( By.name( "submit" ) ).click();
- }
- /**
- * Waits 20 seconds, and then waits again until the user is returned to the
- * view page. Asserts that the title of the page is correct.
- */
- @Then ( "^The diary entry is added successfully and the patient is returned to the view exercise diary page.$" )
- public void checkForSuccess () {
- final WebDriverWait wait = new WebDriverWait( driver, 20 );
- wait.until( ExpectedConditions.titleContains( "View Exercise Diary Entries" ) );
- assertEquals( "iTrust2: View Exercise Diary Entries", driver.getTitle() );
- }
- /**
- * Attempts to add a new exercise diary entries with invalid input.
- *
- * @param date
- * the date of the exercise diary entry
- * @param type
- * the date of the exercise diary entry
- * @param name
- * the name of the exercise diary entry
- * @param duration
- * the duration of the exercise diary entry
- * @param caloriesBurned
- * the calories burned for the exercise diary entry
- */
- @And ( "^I choose to incorrectly add a new diary entry with (.+), (.+), (.+), (.+), (.+)\\.$" )
- public void incorrectlyAdd ( final String date, final String type, final String name, final String duration,
- final String caloriesBurned ) {
- waitForAngular();
- final WebElement dateElement = driver.findElement( By.name( "date" ) );
- dateElement.sendKeys( date.replace( "/", "" ) );
- final Select dropdown = new Select( driver.findElement( By.name( "mealType" ) ) );
- dropdown.selectByVisibleText( type );
- driver.findElement( By.name( "name" ) ).clear();
- driver.findElement( By.name( "name" ) ).sendKeys( name );
- driver.findElement( By.name( "duration" ) ).clear();
- driver.findElement( By.name( "duration" ) ).sendKeys( duration );
- driver.findElement( By.name( "caloriesBurned" ) ).clear();
- driver.findElement( By.name( "caloriesBurned" ) ).sendKeys( caloriesBurned );
- driver.findElement( By.name( "submit" ) ).click();
- }
- /**
- * Checks to make sure that the right validation error message displays on
- * an invalid add.
- */
- @Then ( "^The exercise diary entry is not added.$" )
- public void checkForFailure () {
- assertTrue( driver.getPageSource().contains( "Could not add diary entry." ) );
- // assertTextPresent( "Could not add diary entry", driver );
- }
- /**
- * Adds the exercise diary entry as a precondition.
- *
- * @param date
- * the date of the exercise diary entry
- * @param type
- * the date of the exercise diary entry
- * @param name
- * the name of the exercise diary entry
- * @param duration
- * the duration of the exercise diary entry
- * @param caloriesBurned
- * the calories burned for the exercise diary entry
- */
- @And ( "^The patient has added an entry (.+), (.+), (.+), (\\d+), (\\d+)\\.$" )
- public void addDiaryEntry ( final String date, final String type, final String name, final int duration,
- final int caloriesBurned ) {
- // logs in as the patient
- loginPatientDiaries();
- // navigates to the add exercise diary page
- requestAddDiaryPage();
- // adds a new entry with valid input
- addEntry( date, type, name, duration, caloriesBurned );
- }
- /**
- * Waits until the user is returned to the view exercise diary page, and
- * asserts that the title of the page is correct.
- */
- @Then ( "^The patient has navigated to view exercise diary page.$" )
- public void onViewPagePatient () {
- final WebDriverWait wait = new WebDriverWait( driver, 20 );
- wait.until( ExpectedConditions.titleContains( "View Exercise Diary Entries" ) );
- assertEquals( "iTrust2: View Exercise Diary Entries", driver.getTitle() );
- }
- /**
- * Selects the radio button with the date viewDate using a private helper
- * method.
- *
- * @param viewDate
- * the date on the button to view
- */
- @And ( "^The patient chooses (.+)." )
- public void selectDate ( final String viewDate ) {
- clickAndCheckDateButton( viewDate );
- }
- /**
- * Views the exercise diary entry on the patient page to make sure it
- * matches the values of the parameters.
- *
- * @param date
- * the date of the exercise diary entry
- * @param type
- * the date of the exercise diary entry
- * @param name
- * the name of the exercise diary entry
- * @param duration
- * the duration of the exercise diary entry
- * @param caloriesBurned
- * the calories burned for the exercise diary entry
- */
- @Then ( "^The patient can view the entry (.+), (.+), (.+), (\\d+), (\\d+)\\.$" )
- public void viewEntryPatient ( final String date, final String type, final String name, final int duration,
- final int caloriesBurned ) {
- assertEquals( type, driver.findElement( By.id( "exerciseType-0" ) ).getText() );
- assertEquals( name, driver.findElement( By.id( "name-0" ) ).getText() );
- assertEquals( duration, Integer.parseInt( driver.findElement( By.id( "duration-0" ) ).getText() ) );
- assertEquals( caloriesBurned, Integer.parseInt( driver.findElement( By.id( "caloriesBurned-0" ) ).getText() ) );
- }
- /**
- * Checks the logging functionality by asserting that the action performed
- * appears on the home page.
- */
- @And ( "^This patient's action is logged on the iTrust2 homepage.$" )
- public void checkLogsPatient () {
- driver.get( baseUrl );
- waitForAngular();
- assertTextPresent( "Patient Views Exercise Diary Entry" );
- }
- /**
- * Logs in as the HCP, navigates to the view Patient Exercise Diary page,
- * and asserts that the page title is correct.
- */
- @Then ( "^The HCP logs in navigates to the veiw patient exercise diary entry page.$" )
- public void onViewPageHCP () {
- attemptLogout();
- driver.get( baseUrl );
- final WebElement username = driver.findElement( By.name( "username" ) );
- username.clear();
- username.sendKeys( hcpString );
- final WebElement password = driver.findElement( By.name( "password" ) );
- password.clear();
- password.sendKeys( "123456" );
- final WebElement submit = driver.findElement( By.className( "btn" ) );
- submit.click();
- assertEquals( "iTrust2: HCP Home", driver.getTitle() );
- ( (JavascriptExecutor) driver ).executeScript( "document.getElementById('HCPExerciseDiary').click();" );
- assertEquals( "iTrust2: View Patient Exercise Diary", driver.getTitle() );
- }
- /**
- * Clicks on the patient and then the date while on the HCP View Patient
- * Exercise Diary page. The date button is checked with a private helper
- * method.
- *
- * @param viewDate
- * the date to view
- */
- @And ( "^The HCP chooses the entries for the patient on (.+).$" )
- public void selectDateHCP ( final String viewDate ) {
- waitForAngular();
- driver.findElement( By.id( "janice" ) ).click();
- waitForAngular();
- clickAndCheckDateButton( viewDate );
- }
- /**
- * Views the exercise diary entry on the hcp page to make sure it matches
- * the values of the parameters.
- *
- * @param date
- * the date of the exercise diary entry
- * @param type
- * the date of the exercise diary entry
- * @param name
- * the name of the exercise diary entry
- * @param duration
- * the duration of the exercise diary entry
- * @param caloriesBurned
- * the calories burned for the exercise diary entry
- */
- @Then ( "^The HCP can view the entry (.+), (.+), (.+), (\\d+), (\\d+)\\.$" )
- public void viewEntryHCP ( final String date, final String type, final String name, final int duration,
- final int caloriesBurned ) throws Throwable {
- assertEquals( type, driver.findElement( By.id( "exerciseType-0" ) ).getText() );
- assertEquals( name, driver.findElement( By.id( "name-0" ) ).getText() );
- assertEquals( duration, Integer.parseInt( driver.findElement( By.id( "duration-0" ) ).getText() ) );
- assertEquals( caloriesBurned, Integer.parseInt( driver.findElement( By.id( "caloriesBurned-0" ) ).getText() ) );
- }
- /**
- * Checks that the HCP viewing the Exercise Diary Entry action is logged
- * correctly on the homepage.
- */
- @And ( "^The HCP's action is logged on the iTrust2 homepage.$" )
- public void checkLoggingHCP () {
- driver.get( baseUrl );
- waitForAngular();
- assertTextPresent( "HCP Views Exercise Diary Entry" );
- }
- /**
- * Navigates to the edit Exercise Diary Entry page by type casting the
- * WebDriver to a JavascriptExecutor. Asserts that the title of the page is
- * correct.
- */
- @When ( "^I navigate to the edit exercise diary entries page.$" )
- public void navigateToEdit () {
- ( (JavascriptExecutor) driver ).executeScript( "document.getElementById('editExerciseDiaryEntries').click();" );
- assertEquals( "iTrust2: Edit Exercise Diary Entries", driver.getTitle() );
- }
- /**
- * Logs in as the HCP, navigates to the view Patient Exercise Diary page,
- * and asserts that the page title is correct.
- */
- @Then ( "^I successfully edit that exercise to have name: <newName>.$" )
- public void SuccessfullyEditName () {
- driver.findElement( By.name( "name" ) ).clear();
- driver.findElement( By.name( "name" ) ).sendKeys( "Getting Big" );
- driver.findElement( By.cssSelector( "input[type=\"submit\"]" ) ).click();
- }
- /**
- * navigates to the view Patient Exercise Diary page, and asserts that the
- * page title is correct.
- */
- @And ( "^The recipe is edited.$" )
- public void validateRecipe ( final String date ) {
- clickAndCheckDateButton( date );
- assertTextPresent( "Getting Big" );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement