BDDFramework in ODC
As of 2023/10/07, four Forge components are related to the BDD Framework in ODC.
All of them are made by OutSystems Experts.
The descriptions on each Forge component say or imply:
- BDD Framework: This corresponds to BDDFramework in O11. A template for this component is recommended to use with this
- BDD Framework API: provides a REST API to trigger BDD Framework tests
- BDDFrameworkTestRunLib: A Library to get BDD Framework test suite URLs and retrieve the results from test screens
- Template_BDD Framework: Works as a starting point for creating test Apps
BDD Framework is the necessary component. Template_BDD Framework should be used to accelerate test creation.
If we want to run tests automatically, like for CI/CD, we use BDD Framework API and BDDFrameworkTestRunLib.
We can install Forge components from the ODC Portal.
On the sidebar, click Forge > All assets.
As the first step, let's try using Template_BDD Framework.
- Click Create in ODC Studio
- Select App and click Continue
- Select BDD Framework as a template and click Continue
- Enter name and description. then click Create app
- Add references to the target Actions
- Create a UI Flow as a test suite to hold test cases
- Copy a test screen under ScreenTemplates UI Flow according to a type of test case and past it under the UI Flow created, then rename it
How to create DataDriven tests using Static Entity
- Start from a new App created from the Template for the BDD Framework
- Copy a template screen and a template block into UI Flow(s) for tests
- Change the block inside the List Pattern of the test Screen to the newly copied Test Scenario Block
- Change the definition of TestData Static Entity to hold Input and Outputs for test scenarios
- Change the name to show a relationship with the test scenario Screen
- Add an Attribute for Input of the test scenario
- Add Attributes for Output of the test scenario
- Add test data as Records in the Static Entity
- Implement test scenario (Screen) following Gherkin Syntax. Use the Aggregate Output Parameter as the source for the Expected Values and Output Parameters of the Action under test as the source for the Obtained Values
Regarding Gherkin and Assert Actions, it is done in the same way as in the OutSystems 11 version of BDDFramework.
If we just copy and run a template screen, there should be an error.
This is because of the new feature in the BDD Framework for ODC.
It is explained in the "Security of the screens" section and the "Configure the security of your tests screens:" section in the component's Documentation.
BDD Framework has a Secret Setting called AuthenticationSecretToken. The Layouts in the Library require us to pass the AuthToken used to verify if our request is authoritative.
According to this document, secret Settings don't have default values.
So, we need to fill in the Setting.
- BDD Framework is a library, so open the app for tests in the ODC Portal, then AuthenticationSecretToken under Configuration > Settings
- Click the Edit button on the top right of the screen
- Fill in the Value Input and click the
- Wait for "Pending configurations" to be finished
- Open the test screen with the parameter "AuthToken=<the value we set in above step>"
When I tried opening the BDD Framework in ODC Studio, the below message was shown.
I wanted to see how AuthenticationSecretToken Setting is defined.
Trying BDD Framework API.
BDD Framework API is an App that uses the BDDFrameworkTestRunLib Library.
On the ODC Portal > FORGE > All assets, search with the term "BDD" and click Install buttons of the above components.
BDD Framework API requires BDDFrameworkTestRunLib, so install the latter first.
Installed Versions
- BDD Framework API: 0.1.3
- BDDFrameworkTestRunLib: 0.1.0
BDDFrameworkTestRunLib is an External Library.
So, this should have been written in C#, however I can't find the source repository. Maybe it is not public.
This External Library has only two public elements. One Action to run tests and a Structure used in its Output Parameter.
The entire architecture and I/F of components are similar to those of "BDDFramework Client Side" of OutSystems 11. In that component, actual test executions are done using Chromium and there was a screen to install Chromium. Although there was no ChromiumFolder Input Parameter on External Logic Action, there is a possibility that they have the same construction.
Try calling the API
Get a link to the swagger file from the API Documentation.
Open a test App and create a Consume REST API from the link.
The API exposed by BDD Framework API has the Custom Authentication, so the created Consume REST API has Type = No authentication.
Just call it this way, and I got an error.
HTTP status code 401 is set by OnAuthentication of TestTrigger REST API in BDD Framework API.
How to solve 401 error?
Here is an excerpt from OnAuthentication.
- GetRequestHeaderSecurityToken Action retrieves HTTP Header value of Authorization, and then cut the text after "Bearer "
- ValidateTestCanBeTriggered Action is from BDDFramework Library (The main component of BDDFramework). This verifies if the Input Parameter (returned by GetRequestHeaderSecurityToken) and Settings.AuthenticationSecretToken has the same value. BDDFramework is a Library, so we need to set the Settings.AuthenticationSecretToken on the BDD Framework API page of the ODC Portal
So, first we need to set a value to Settings.AuthenticationSecretToken of BDD Framework API.
Then, add OnBeforeRequest to the Consume REST API and Append Authorization Header to Request.Headers. The value should start with "Bearer <AuthenticationSecretToken>".
Above settings and extending Server Request Timeout made it possible to proceed past Authentication, but there was still another error.
Error Message
Could not find tests in the screen '<Screen Name>' of eSpace '<Test App Name>.
This is because, the API access the test screen with the same AuthToken it receives.
It leads to the necessity that BDD Framework API and the actual BDD test Apps have the same AuthToken set.