E2E Clinical Visit Test: Patient Dashboard adding/deleting Allergies and conditions

Am currently working on this ticket … Do the following user stories look fine ??? Anotherwords is it ok to repeat the the user stories incase the user stories of a given scenario are repeated ??? Refer to the following block of code

Scenario: Patient Dashboard adding/deleting Allergies and conditions
    # User story: Adding New Allergy
    When a user clicks on Allergies link from Patient dashboard page
    Then the system loads Allergies board page
    When a user clicks Add New Allergy button
    Then the system loads Add New Allergy dashboard
    And the user selects a new Allergy
    And the user clicks on the Save button
    Then the system adds a new Allergy
    
    # User story: Adding New Condition
    When a user clicks on Conditions link from Patient dashboard page
    Then the system loads Conditions board page
    When a user clicks Add New Condition button
    Then the system loads Add New Condition dashboard
    And the user selects a new Condition
    And the user clicks on the Save button
    Then the system adds a new Condition

    # User story: Adding New Allergy and Deleting New Allergy
    When a user clicks on Allergies link from Patient dashboard page
    Then the system loads Allergies board page
    When a user clicks Add New Allergy button
    Then the system loads Add New Allergy dashboard
    And the user selects a new Allergy
    And the user clicks on the Save button
    Then the system adds a new Allergy
    When the user click on the delete button
    Then the system loads Remove Allergy dashboard
    And the user clicks on the Yes button
    Then the system removes the added allergy 

    # User story: Adding New Condition and Delleting New Condition
    When a user clicks on Conditions link from Patient dashboard page
    Then the system loads Conditions board page
    When a user clicks Add New Condition button
    Then the system loads Add New Condition dashboard
    And the user selects a new Condition
    And the user clicks on the Save button
    Then the system adds a new Condition
    When the user click on the delete button
    Then the system loads Remove Condition dashboard
    And the user clicks on the Yes button
    Then the system removes the added Condition

cc @kdaud @sharif @irenyak1 @insookwa @jwnasambu @ibacher @dkayiwa

1 Like

This is a good start @ndacyayisenga

A user story can not be repeated in a feature, usually in Gherkin language is known as scenario.

Its not a good practice to use @when annotation more than once in a single scenario( user story), make use of cucumber logical functions. See the documentation here !

1 Like

Thanks @kdaud

With that above in consideration I have one or two more questions. I have been seeing through the qa framework but its like this kind of ascenerio has not appeared there before unless I missed out something. Taking this as an example, we are required to add new allergy

User story: Adding New Allergy

When a user clicks on Allergies link from Patient dashboard page
Then the system loads Allergies board page
When a user clicks Add New Allergy button
Then the system loads Add New Allergy dashboard
And the user selects a new Allergy
And the user clicks on the Save button
Then the system adds a new Allergy

and then we are supposed to add another allergy and then delete it whose user stroy I suppose should be like this

User story: Adding New Allergy and Deleting New Allergy

When a user clicks on Allergies link from Patient dashboard page
Then the system loads Allergies board page
When a user clicks Add New Allergy button
Then the system loads Add New Allergy dashboard
And the user selects a new Allergy
And the user clicks on the Save button
Then the system adds a new Allergy
When the user click on the delete button
Then the system loads Remove Allergy dashboard
And the user clicks on the Yes button
Then the system removes the added allergy

When you look closely, the first user story appears in the second one. So since I have to add new allergy and save it and then add another one and deleted it… How can I merge these user stories to avoid code repitition and make it easy to write methods in the step definitions

You can have user stories that specify the exact allergy you are capturing to avoid repeating the same scenario. However, scenarios can have some similar steps(but not all steps) and these shared steps are written once in the steps definition.

You can split the user story into two;

Scenario: Adding <Allergy name>

Scenario: Deleting an allergy

2 Likes

take a look at the scenarios used in this presentation https://www.youtube.com/watch?v=jhJJAEBS9sQ might shade some light

Hi all… I have a blocker where anm try to implement my last method… All other methods before it execute successfully its only this last step that’s jaming

I want to delete a condition

blocker2

I want to create a method that clicks the Yes button …

This is how am tryiny to do it but it doesn’t seem working…

@Then("user clicks on the yes button to confirm")
	public void clicksToConfirm(){
		conditionPage.clickOn(By.className("confirm"));
	}

I dint find the appropriate method to call to confirm the yes button and thats why I opted to use the browser inspection tool.

Would anyone suggest for me a better way of writing this method???

cc @kdaud @sharif @irenyak1 @dkayiwa @ibacher

@ndacyayisenga add the method in ConditionsPage and then calling it in the test implementation is what you probably need.

Hi @kdaud … following what you told me, this how I tried to do it but am still blocked

private static final By CONFIRM_DELETE = By.className("confirm");

public void confirmDeleteCondition(){
        clickOn(CONFIRM_DELETE);
    }

The above method was added here and below is how I tried to implement it in my step definitions

@Then("user clicks on the yes button to confirm")
	public void clicksToConfirm(){
		conditionPage.confirmDeleteCondition();
	}

but it doesn’t excute still

cc @kdaud @sharif @ibacher @dkayiwa

When the test is executing uses the distro-referenceapplication artifacts stored in .m2 repository probably at ~/.m2/repository/org/openmrs/distro.

That said you need to build the openmrs-distro-referenceappliction local repo so that your changes are included in the artifacts. mvn clean install works like a charm then run the test and share the experience!

@ndacyayisenga was the snag sorted?

@kdaud

Am actually stilling looking for better ways to implement this… I have done it several ways but it doesn’t pick up.
blocker2

@kdaud in regards to the above screenshot, What can

public void loadsRemoveCondition2Dashboard(){
		conditionsPage.acceptAlert();
	}

do… Do you think the .acceptAlert should work in the above case???

cc @kdaud @sharif @dkayiwa

@ndacyayisenga did you notice that you added the functionality on a wrong page?

Take a look again here!

1 Like

@kdaud, i need more clarification on this. When i watched Design Meeting - Indiana University, i noticed in the 35th minute that we can repeat the And, when and then. I need to understand this deeper. What effect could it cause in code especially in the new test framework?

We can have many scenarios (user stories) in a single feature file and we can use When, And and Then as many times appropriately. Here is the use case of a feature file for Vitals Management !

Feature: Vitals Management

  Background:
    Given a user clicks on Capture Vitals link from Patient dashboard
    Then the system loads Vitals page

  Scenario: Normal Vitals
    When a user enters normal patient vitals
    And a user clicks on save button
    Then the system adds patient vitals into the vitals table 
   
  Scenario: Vitals under minimum value
    When a user enters a vital below minimum value and the system alerts until valid
    And a user clicks on save button
    Then the system adds patient vitals into the vitals table
    
  Scenario: Vitals over maximum value
    When a user enters a vital above maximum value and the system alerts until valid
    And a user clicks on save button
    Then the system adds patient vitals into the vitals table

@gracebish not sure whether I get your question well But this is what I can say; when writing user stories in a feature file we need to embrace Best Practices in Scenario Writing !

1 Like

@kdaud I just made a look up for the link, the one you shared had a small error it is here

2 Likes

Thanks @irenyak1 for the initiative!

Hope @gracebish has taken a look into the documentation!

Thanks @kdaud for the great resource!

2 Likes

Helpful content, thanks @irenyak1 @kdaud

2 Likes

Hello @devs I was trying to see through the logs of Clinical Visit Test… but the failing tests are already existing not the ones I included RATEST-225: E2E Clinical Visit Test: Patient Dashboard adding/deleting Allergies and conditions by Ndacyayisenga-droid · Pull Request #168 · openmrs/openmrs-contrib-qaframework · GitHub… And the existing clinicalVisit tests seem fine… The following method was failing initially because it couldn’t return twice which would not allow it to spin from the patientDashboard because it could not get to it… I had to add dashboardPage = visitsDashboardPage.goToPatientDashboard(); for the second time for this method to return twice and get to patientDashboard. I don’t whether thats a good practice in terms of sanity in code.

@Then("the system adds the note into visit note table")
public void systemAddsVisitNote() {
		assertEquals(DIAGNOSIS_PRIMARY, visitNotePage.primaryDiagnosis());
		assertEquals(DIAGNOSIS_SECONDARY, visitNotePage.secondaryDiagnosis());
		visitsDashboardPage.waitForPageToLoad();
		dashboardPage = visitsDashboardPage.goToPatientDashboard();
		dashboardPage = visitsDashboardPage.goToPatientDashboard();
	}

The following test is also failing but I haven’t figured out why

@Then("the system ends the patient visit")
	public void systemEndsPatientVisit() {
		assertNull(visitsDashboardPage.getActiveVisit());
		dashboardPage = visitsDashboardPage.goToPatientDashboard();

Note: All the above methods are already exisiting in master… Am not certain whether the problem is from my side but I would wish any volunteer from the quality assuarance team to run this test and see whether they have the same experience.

cc @kdaud @mherman22 @sharif @irenyak1

You don’t need to recursively invoke the same method in the function systemAddsVisitNote(). The test might be failing due to either spinning from an online instance with unstable connection Or the PC memory is not well managed which affects the test performance.

The test is passing locally and also with CI, so most probably the concern might be on what have mentioned above. @ndacyayisenga which server are you using to run the test? and is your PC memory well managed?