Goal

Create a test to validate individual JSON Paths. Use a section of a JSON template to validate a service transaction.

Prerequisites

Have basic understanding of databases and/or document databases

Starting code

Start tag: lesson/10-testing-only

Steps

It’s time to dive deeper into the backend aspects of Verne by validating specific items on the service transaction and also sections of the structure. This will allow to us also validate items not visible on the UI.

From a technical point of view service transaction is a single MongoDB document. From a functional point of view service transaction is an instance of a user interacting with the system, be it: Creating or maintaining registry data, Viewing registry data and Searching for registry data

Scenario description

We are going to create a simple registration for a super hero and validate the pending status for a saved service and active status for a submitted service.

On file 1 we are going to create a scenario to save and exit and Submit the service successfully

Scenario Name: The scenario name must be short and descriptive of what needs to be achieved.
Scenario: Validate status of pending and activated service via service transaction validator
Actions we are going to perform in this scenario: Create a simple service to Save And Exit, Open the saved service and Submit

Create a new folder H008 and a test file called ValidateServiceTransaction

As a starting point we are going to reuse the scenario from Lesson 3 as shown below. (This scenario is a copy from Lesson 3):

Feature: heroes/tests/hercules/tests/H008/ValidateServiceTransaction

 Scenario: Validate service transaction on Save and Exit and Submit
    Given I set application to heroes
    Then I logon as External01@fostermoore.com with password External01
      And I click menu Online Services
      And I click menu Register a Super Hero
And I create a random 10 titlecase character variable called superheroname
    When I enter text ${superheroname}SaveAndExitTest in Super Hero Name
      And I select radio button Yes in radio button group Do you usually or intend to don a cape?
      And I select option Agility from dropdown Hero Powers
    When I click button Save and Exit
      And I click button Go back
      And I click button Save and Exit
      And I click button Yes, exit now
      And I expect no invalid config
      And I click tab Things in Progress
      And I click Continue for dashboard item ${superheroname}SaveAndExitTest
      And I expect no invalid config
      #Secret identity is a mandatory field
      And I add new Add Secret Identity
      And I enter text Optimus in Secret Identity>First name
      And I enter text Transformers in Secret Identity>Middle name(s)
      And I enter text Prime in Secret Identity>Last name
      And I click button Continue
    When I click button Submit
    Then I expect no invalid config
      And I expect service-title Success
      And I expect text Your super hero is now registered and ready to save the world!
      And I expect text Super Hero Name > ${superheroname}SaveAndExitTest
      And I expect text Registration Date > #FORMATTED_TODAY#dd MMMM yyyy#FORMATTED_TODAY#
      And I expect text Uniform/costume/outfit? > Yes
      And I expect text Including a cape? > Yes
      And I expect text Hero Powers > Agility
    Then I click button Back
      And I expect text Welcome External01, what next?

Adding a simple service transaction validation

Step 1 in the test is to validate the Save and Exit status and Step 2 is to validate the status after we successfully submit.

For this scenario to begin with we will perform the following actions below manually to gain a better understanding of the service transaction repository.

  1. Login with External01@fostermoore.com user
  2. Start Register a super heroe
  3. Complete the hero name
  4. Save and Exit
  5. Open System administration
  6. Click Svc Txn Repository
  7. Inspect the status of the service at the time of save and exit

In the test scenario we will use the steps definitions

I retrieve (pending service transaction|active service transaction|email delivery logs|compliance workflow instances|service transaction workflow instances) with uid (.*) and

I expect JSON element (.) to be equal to (.) . This step allows to the user to check the service transaction at the time of the service.

The steps on this page requires usage of a special variable called ${currentServiceTransactionUid}. This variable it’s a unique identification generated at the time of start of the service.
Feature: heroes/tests/hercules/tests/H008/ValidateServiceTransaction

  Scenario: Validate service transaction on Save and Exit and Submit
    Given I set application to heroes
    Then I logon as External01@fostermoore.com with password External01
      And I click menu Online Services
      And I click menu Register a Super Hero
      And I create a random 10 titlecase character variable called superheroname
    When I enter text ${superheroname}SaveAndExitTest in Super Hero Name
      And I select radio button Yes in radio button group Do you usually or intend to don a cape?
      And I select option Agility from dropdown Hero Powers
    When I click button Save and Exit
      And I click button Go back
      And I click button Save and Exit
      And I click button Yes, exit now
    When I retrieve pending service transaction with uid ${currentServiceTransactionUid}
    Then I expect JSON element status to be equal to pending
      And I expect no invalid config
      And I click tab Things in Progress
      And I click Continue for dashboard item ${superheroname}SaveAndExitTest
      And I expect no invalid config
      #Secret identity is a mandatory field
      And I add new Add Secret Identity
      And I enter text Optimus in Secret Identity>First name
      And I enter text Transformers in Secret Identity>Middle name(s)
      And I enter text Prime in Secret Identity>Last name
      And I click button Continue
    When I click button Submit
    Then I expect no invalid config
      And I expect service-title Success
      And I expect text Your super hero is now registered and ready to save the world!
      And I expect text Super Hero Name > ${superheroname}SaveAndExitTest
      And I expect text Registration Date > #FORMATTED_TODAY#dd MMMM yyyy#FORMATTED_TODAY#
      And I expect text Uniform/costume/outfit? > Yes
      And I expect text Including a cape? > Yes
      And I expect text Hero Powers > Agility
    Then I click button Back
      And I expect text Welcome External01, what next?

We are going to update the test to reflect this change by adding I retrieve pending service transaction with uid ${currentServiceTransactionUid} and I expect JSON element status to be equal to pending after we complete the save and exit process. Once we run the test the step should be green.

If by any chance the status is not pending the Magellan log will let us know. Let’s make it fail!!

Change the line Then I expect JSON element status to be equal to pending to Then I expect JSON element status to be equal to active.

The scenario fails with the error below

Let’s complete our test by adding the remaining steps at the end and validating the status activated (Please see Life-cycle of a service transaction)

Feature: heroes/tests/hercules/tests/H008/ValidateServiceTransaction

  Scenario: Validate service transaction on Save and Exit and Submit
    Given I set application to heroes
    Then I logon as External01@fostermoore.com with password External01
      And I click menu Online Services
      And I click menu Register a Super Hero
      And I create a random 10 titlecase character variable called superheroname
    When I enter text ${superheroname}SaveAndExitTest in Super Hero Name
      And I select radio button Yes in radio button group Do you usually or intend to don a cape?
      And I select option Agility from dropdown Hero Powers
    When I click button Save and Exit
      And I click button Go back
      And I click button Save and Exit
      And I click button Yes, exit now
    When I retrieve pending service transaction with uid ${currentServiceTransactionUid}
    Then I expect JSON element status to be equal to pending
      And I expect no invalid config
      And I click tab Things in Progress
      And I click Continue for dashboard item ${superheroname}SaveAndExitTest
      And I expect no invalid config
      #Secret identity is a mandatory field
      And I add new Add Secret Identity
      And I enter text Optimus in Secret Identity>First name
      And I enter text Transformers in Secret Identity>Middle name(s)
      And I enter text Prime in Secret Identity>Last name
      And I click button Continue
    When I click button Submit
    When I retrieve active service transaction with uid ${currentServiceTransactionUid}
    Then I expect JSON element status to be equal to activated
    Then I expect no invalid config
      And I expect service-title Success
      And I expect text Your super hero is now registered and ready to save the world!
      And I expect text Super Hero Name > ${superheroname}SaveAndExitTest
      And I expect text Registration Date > #FORMATTED_TODAY#dd MMMM yyyy#FORMATTED_TODAY#
      And I expect text Uniform/costume/outfit? > Yes
      And I expect text Including a cape? > Yes
      And I expect text Hero Powers > Agility
    Then I click button Back
      And I expect text Welcome External01, what next?

You can notice we added the steps to validate the activated entity by checking activated status after submit

Adding a complex service transaction validation

As we mentioned at the beginning of the lesson we can validate simple elements on a JSON or we can validate sections of the JSON or even all the entire JSON structure. To add a new JSON structure validation we are going to repeat some of the steps we did before, but with the simple test, we created before by running and inspecting the Svc Txn Repository. We are going to create a service transaction validation on the section highlighted.

To do so we are going to recreate the same test by using the step I (compare|strictly compare) (service transaction|email delivery logs|workflow instances) against (.*)

Let’s create a new JSON file in dataValidation folder. Right click over the H008 folder and create a plain file with name Validation.json and ensure the path has dataValidation folder

Once the file is created we are going to copy and paste the content from the Svc Txn Repository record that is highlighted inside of the Json file.

Please note the JSON structure is not correct, because we are copying a section and Magellan will show some errors:

We need to fix it by changing the structure at the beginning and at the end please note that we need to add { and at the end of the file }, also remove the comma of the last line.

The JSON structure will look like:

Now it’s time to update the test by adding 2 lines after Submit

The new test will look like:

Feature: heroes/tests/hercules/tests/H008/ValidateServiceTransaction

  Scenario: Validate service transaction on Save and Exit and Submit
    Given I set application to heroes
    Then I logon as External01@fostermoore.com with password External01
      And I click menu Online Services
      And I click menu Register a Super Hero
      And I create a random 10 titlecase character variable called superheroname
    When I enter text ${superheroname}SaveAndExitTest in Super Hero Name
      And I select radio button Yes in radio button group Do you usually or intend to don a cape?
      And I select option Agility from dropdown Hero Powers
      And I add new Add Secret Identity
      And I enter text Optimus in Secret Identity>First name
      And I enter text Transformers in Secret Identity>Middle name(s)
      And I enter text Prime in Secret Identity>Last name
      And I click button Continue
    When I click button Save and Exit
      And I click button Go back
      And I click button Save and Exit
      And I click button Yes, exit now
      And I expect no invalid config
      And I click tab Things in Progress
      And I click View for dashboard item ${superheroname}
      And I expect no invalid config
    Then I click button Submit
    When I retrieve active service transaction with uid ${currentServiceTransactionUid}
      And I compare service transaction against /tests/hercules/tests/H008/dataValidation/Validation.json
    Then I expect no invalid config
      And I expect service-title Success
      And I expect text Your super hero is now registered and ready to save the world!
      And I expect text Super Hero Name > ${superheroname}SaveAndExitTest
      And I expect text Registration Date > #FORMATTED_TODAY#dd MMMM yyyy#FORMATTED_TODAY#
      And I expect text Year of Arrival on Earth > not specified
      And I expect text Do you have a uniform, costume or outfit? > Yes
      And I expect text Do you usually or intend to don a cape? > Yes
      And I expect text Hero Powers > Flight
    Then I click button Back
      And I expect text Welcome External01, what next?

If we attempt to run the test Magellan will show 10 errors found. This is due to the values from the JSON template and the actual results coming from the server are random and different. To avoid this problem we are going to use the value #NONBLANK#

Next step is to update the JSON file by adding #NONBLANK# to those values that are random and also use the variable ${superheroname} from the test that can be consume automatically.

{
  "_id" : "#NONBLANK#",
  "appCode" : "heroes",
  "rootDomainName" : "Hero",
  "serviceCode" : "heroRegister",
  "serviceMode" : "Create",
  "identifier" : "#NONBLANK#",
  "businessIdentifier" : "#NONBLANK#",
  "serviceIdentifier" : "#NONBLANK#",
  "serviceCreateDate" : "#NONBLANK#",
  "businessName" : "${superheroname}",
  "sequence" : "#NONBLANK#",
  "configurationVersion" : "#NONBLANK#",
  "status" : "activated",
  "ghost" : false,
  "createdDate" : "#NONBLANK#",
  "createdBy" : "#NONBLANK#",
  "createdByName" : "External01 Organisational User",
  "updatedDate" : "#NONBLANK#",
  "updatedBy" : "#NONBLANK#",
  "updatedByName" : "External01 Organisational User"
}

Recap

In this lessons we discover:

  • We need to retrieve the service transaction by using I retrieve active service transaction with uid ${currentServiceTransactionUid}
  • Validated a single element of a service transaction
  • Validated a section of a service transaction by creating a JSON file.
  • Used #NONBLANK# to declare a JSON path that should always return a value.

Additional info about data validation step definitions here

0
0

Jump to Section