Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
README.md 13.9 KiB
Newer Older
rui rodrigues's avatar
rui rodrigues committed
# PSO-testing

## Tables of contents
Adolfo Han's avatar
Adolfo Han committed

rui rodrigues's avatar
rui rodrigues committed
- [About PSO-testing](#about-pso-testing)
- [Technologies recommended](#technologies-recommended)
- [Playwright](#playwright)
- [Structure](#structure)
- [Writing tests](#writing-tests)
Adolfo Han's avatar
Adolfo Han committed
    - [Keywords](#keywords)
    - [Background](#background)
    - [Steps tense](#steps-tense)
    - [Scenario outline](#scenario-outline)
rui rodrigues's avatar
rui rodrigues committed
- [How to Run tests](#how-to-run-tests)
- [How to generate html report](#how-to-generate-html-report)
Adolfo Han's avatar
Adolfo Han committed
- [How to use Checkstyle linter](#how-to-use-checkstyle-linter)
- [How to add properties file](#How-to-add-properties-file)
rui rodrigues's avatar
rui rodrigues committed
- [Conventions](#conventions)
- [CI Pipelines](#ci-pipelines)
Adolfo Han's avatar
Adolfo Han committed
    - [Pipeline Stages](#pipeline-stages)
    - [Merge Requests Pipeline](#merge-requests-pipeline)
        - [Recommended Branch Naming Conventions](#recommended-branch-naming-conventions)
    - [Scheduled Pipeline](#scheduled-pipeline)
rui rodrigues's avatar
rui rodrigues committed
## About PSO-testing
Adolfo Han's avatar
Adolfo Han committed

The PSO-testing is an automated test framework designed allow to automate test cases about Commission European projects.
rui rodrigues's avatar
rui rodrigues committed

## Technologies recommended
Adolfo Han's avatar
Adolfo Han committed

rui rodrigues's avatar
rui rodrigues committed
- Java 11
- Maven 3.9.6
- IntelliJ Community
- maven-atf-reports:1.0.0 (request to testing tower)

## Playwright

Adolfo Han's avatar
Adolfo Han committed
Playwright (https://playwright.dev/) is a framework used to automate tests on web pages. It interacts with page
elements (named locators) to check their behavior.
Playwright uses core version of the browser (chromium, webkit and stable version of Firefox). It allows testing on
stable browser versions which are not polluted by branding content and which are the most used. The version of those
browsers will be the same for all people using the test project.
rui rodrigues's avatar
rui rodrigues committed
In addition, it can also run tests on the local chrome and edge version.

## Structure
Adolfo Han's avatar
Adolfo Han committed

rui rodrigues's avatar
rui rodrigues committed
**Configuration file** is split in data and locators (src/main/java/configuration):
Adolfo Han's avatar
Adolfo Han committed

- locators: all locators should be defined here. Each ui page should have its own java class.
rui rodrigues's avatar
rui rodrigues committed
- data: all test data should be defined here. Each ui page should have its own java class.

**Helpers file** for all helpers that supports our stepDefinitions (src/main/java).

Adolfo Han's avatar
Adolfo Han committed
**Features file** where should be defined all scenario tests. Use scenario outline if needs but avoid define test data
here (src/main/java).
rui rodrigues's avatar
rui rodrigues committed

**Framework file** where should be defined all code to allow run the tests (src/test/java).

**StepDefinitions** folder where should be defined all cucumber steps (src/test/java).

**TestRunner** folder where should be defined the cucumber test runner (src/test/java).

**resources** should contain config.properties file with sensitive data:

```
rui rodrigues's avatar
rui rodrigues committed
//SIMPL-LABS
URL=https://poc-simpl-labs.dev.simpl-europe.eu/data-spaces
USERNAME=
PASSWORD=
SECRET_KEY=
rui rodrigues's avatar
rui rodrigues committed

//SIMPL-OPEN
URL_WIZARD=https://sd-creation-wizard.uatpso.com

//COMMON
IS_HEADLESS=false
rui rodrigues's avatar
rui rodrigues committed
## Writing tests

Adolfo Han's avatar
Adolfo Han committed
Writing test cases in a correct way requires you to respect some easy rules. Our test cases are written with **Gherkin**
syntax (https://cucumber.io/docs/gherkin/reference/).
rui rodrigues's avatar
rui rodrigues committed

All scenario and steps name should start with a lowercase letter.

### Keywords

Gherkin as three main keywords for steps:

- **Given** for prerequisites steps
- **When** for actions steps
- **Then** for expectations steps

Keywords shouldn't be mixed: You should have this order of keywords: Given, When, Then.
Adolfo Han's avatar
Adolfo Han committed
Note that a test couldn't have any **Given** steps if there is no prerequisites and in some rare cases it could happen
that a test has no **When** steps.
rui rodrigues's avatar
rui rodrigues committed

E.g.:

```gherkin
Scenario: a user logs in
Adolfo Han's avatar
Adolfo Han committed
Given a user opened the login form
When the user fills the login form
And the user validates the login form
Then the user name should be displayed
rui rodrigues's avatar
rui rodrigues committed
```

### Background

If all tests of your feature share some common steps, you can put them in a background.
All background steps should be of **Given** type.

E.g.:

```gherkin
Background:
Adolfo Han's avatar
Adolfo Han committed
Given the website is displayed
And the user accepted the cookies
rui rodrigues's avatar
rui rodrigues committed

Scenario: a user logs in
Adolfo Han's avatar
Adolfo Han committed
Given a user opened the login form
When the user fills the login form
And the user validates the login form
Then the user name should be displayed
But the login button shouldn't be displayed
rui rodrigues's avatar
rui rodrigues committed
```

### Steps tense

Each type of step has its own tense rule.

Adolfo Han's avatar
Adolfo Han committed
- **Given** steps should be written in **past** tense most of the time as they represent prerequisites actions that have
  to be donne for the test's main action to be executed. But sometimes when the step is written in a passive way, given
  steps could be written in **present** tense
- **When** steps have to be written in **present** tense as they represent the main actions that will be performed in
  the test
- **Then** steps have to be written in **conditional** tense as they represent an expected behavior that could be not
  right when tested
rui rodrigues's avatar
rui rodrigues committed

Adolfo Han's avatar
Adolfo Han committed
If you have a step that is defined in a certain type and could be used as another type in another test, the step should
be duplicated and written with the type format.
rui rodrigues's avatar
rui rodrigues committed

E.g.:

```gherkin
Scenario: a user logs in
Adolfo Han's avatar
Adolfo Han committed
Given a user opened the login form
When the user fills the login form
And the user validates the login form
Then the user should be logged in
rui rodrigues's avatar
rui rodrigues committed

Scenario: a user logs out
Adolfo Han's avatar
Adolfo Han committed
Given a user is logged in
When the user clicks the log out button
Then the user shouldn't be logged in
rui rodrigues's avatar
rui rodrigues committed
```

### Scenario outline

Adolfo Han's avatar
Adolfo Han committed
In some cases, a scenario can be used for several test cases with only some variations. In such a situation you can use
a Scenario outline which will allow you to execute tests with parameters. To do that, you'll have to use create a *
*Scenario Outline** instead of a **Scenario** and define your parameters into your steps by putting them between **<>
** (parameters should be written in pascal case).
rui rodrigues's avatar
rui rodrigues committed
Then you'll have the define the parameters combinations in the **Examples** section.

E.g.:

```gherkin
Scenario Outline: a user <userStatus> logs in
Adolfo Han's avatar
Adolfo Han committed
Given a user opened the login form
When the user fills the login form
And the user validates the login form
Then the user <loginResult> be logged in

Examples:
| userStatus | loginResult |
| valid      | should      |
| invalid    | shouldn't   |
rui rodrigues's avatar
rui rodrigues committed
```

### How to run tests
Adolfo Han's avatar
Adolfo Han committed

rui rodrigues's avatar
rui rodrigues committed
## ATTENTION: BEFORE RUN ANY TEST CONFIGURE PROPERTIES FILE

rui rodrigues's avatar
rui rodrigues committed
Run the following command
rui rodrigues's avatar
rui rodrigues committed
```bash
mvn clean test -Dtest=ApiSimplOpenRunner
mvn clean test -Dtest=UiSimplOpenRunner
```
Adolfo Han's avatar
Adolfo Han committed

To simplLabs project
Adolfo Han's avatar
Adolfo Han committed

```bash
// to api testing
mvn clean test -Dtest=UiSimplLabsRunner
rui rodrigues's avatar
rui rodrigues committed
```
Adolfo Han's avatar
Adolfo Han committed

To run a test by tag it just needed to add the following option to the previous command (consider the tag @TCW01 as an
example):

```bash
-Dcucumber.filter.tags="@TCW01"
```
rui rodrigues's avatar
rui rodrigues committed

### How to generate html report
Adolfo Han's avatar
Adolfo Han committed

rui rodrigues's avatar
rui rodrigues committed
To generate the report of the first time it´s mandatory install the dependency maven-atf-reports.
It´s not available in the internet. Talk with testing tower to get it

Run the following command
Adolfo Han's avatar
Adolfo Han committed

rui rodrigues's avatar
rui rodrigues committed
```bash
mvn com.qa.atf.reports:maven-atf-reports:1.0.0:generate@execution
rui rodrigues's avatar
rui rodrigues committed
```
Adolfo Han's avatar
Adolfo Han committed

rui rodrigues's avatar
rui rodrigues committed
After run the command with success, the html report will be available in target/pluma-report/overview-features.html

To add some information to report type the following code to the cucumber step:
Adolfo Han's avatar
Adolfo Han committed

rui rodrigues's avatar
rui rodrigues committed
```bash
 scenario.attach(<information to add>, "text/plain", <title>);
```

To add a screenshot to report type the following code to the cucumber step:
Adolfo Han's avatar
Adolfo Han committed

rui rodrigues's avatar
rui rodrigues committed
```bash
byte[] screenshot = page.screenshot(new Page.ScreenshotOptions());
scenario.attach(screenshot, "image/png", <title>);
```

Adolfo Han's avatar
Adolfo Han committed
### How to use Checkstyle linter

Checkstyle is a development tool that helps programmers write Java code that adheres to a coding standard.
It automates the process of checking Java code for adherence to a set of rules, which can include formatting,
naming conventions, and other coding standards. By enforcing these rules, Checkstyle helps maintain code quality,
readability, and consistency across a project.

**Run Checkstyle locally**:
To run Checkstyle validation locally, use the following Maven command:

   ```bash
   mvn checkstyle:check
   ```

### How to add properties file
Adolfo Han's avatar
Adolfo Han committed

rui rodrigues's avatar
rui rodrigues committed
- Go to directory src/main/resources
- Add a file with name config.properties
rui rodrigues's avatar
rui rodrigues committed
- Add the information that is needed (see the chapter [Structure](#structure))
rui rodrigues's avatar
rui rodrigues committed
### Conventions
Adolfo Han's avatar
Adolfo Han committed

- cucumber tags: each feature file should be a tag with feature name and each test should be tag with test case number
  and initial letter of feature name (e.g. L01 - first scenario to login.feature).
rui rodrigues's avatar
rui rodrigues committed
- write typing:
Adolfo Han's avatar
Adolfo Han committed
  <<<<<<< HEAD
    - java class - pascal case
    - data and locators - snake case + upper case
    - feature files and methods name - camel case

## CI Pipelines

### Pipeline Stages
Adolfo Han's avatar
Adolfo Han committed

The following stages are included in the CI Pipeline for PSO Test Automation Repo:
Adolfo Han's avatar
Adolfo Han committed

- **quality** --> for running SonarQube verifications for the repo (TODO)
Adolfo Han's avatar
Adolfo Han committed
- **test** --> for running automation tests during Merge Requests and Scheduled Pipeline executions
- **report** --> for generating reports based on the test results in the previous stage

### Merge Requests Pipeline
Adolfo Han's avatar
Adolfo Han committed

- **test** followed by **report** stages of the defined pipeline will be executed during Merge Request events
Adolfo Han's avatar
Adolfo Han committed
- It has been agreed that for every merge request, a subset of test cases (marked with tag '**@smoke**') will be
  executed
- TestRunner and Tags to be used to run the Automation tests will be derived from the branch name
Adolfo Han's avatar
Adolfo Han committed
    - `xvfb-run mvn clean test -Dtest=<TESTRUNNER_TO_USE> -Dcucumber.filter.tags="<TAGS_TO_USE>"`

### Recommended Branch Naming Conventions
Adolfo Han's avatar
Adolfo Han committed

##### **For Features (test cases):**
Adolfo Han's avatar
Adolfo Han committed

The following branch naming convention is recommended when creating or updating test cases:

> feature/`<TestRunner_Identifier>`-`<JIRA_TestCaseId>`
Adolfo Han's avatar
Adolfo Han committed

- `<TestRunner_Identifier>` could be any of the following values:
    - `SOUI` - Implies feature is related to SimplOpen UI &#8594; SimplOpen UI TestRunner is to be used for test
      execution
    - `SOAPI` - Implies feature is related to SimplOpen API &#8594; SimplOpen API TestRunner is to be used for test
      execution
    - `SLUI` - Implies feature is related to SimplLabs UI &#8594; SimplLabs UI TestRunner is to be used for test
      execution
    - `SLAPI` - Implies feature is related to SimplLabs API &#8594; SimplLabs API TestRunner is to be used for test
      execution
- `<JIRA_TestCaseId>` is the test case identifier in JIRA. `e.g. SIMPL-1234`

> NOTE:
> - Remember to tag the newly created or updated test case with the JIRA id. `e.g. @SIMPL-1234`
> - If the TestRunner_Identifier is not provided in the branch name, SimplOpen UI TestRunner will be used as default
> - If the JIRA_TestCaseId is not provided in the branch name, "@smoke" tag will be used as default

**Illustrations:**
Adolfo Han's avatar
Adolfo Han committed
> 1. **feature/SOUI-SIMPL-111** --> For MRs, Tests will be executed with SimplOpen UI TestRunner and Tags "@smoke or
     @SIMPL-111".
     >
     >
- Following command will be executed in pipeline:
>   - `xvfb-run mvn clean test -Dtest=UiSimplOpenRunner -Dcucumber.filter.tags="@smoke or @SIMPL-111"`
Adolfo Han's avatar
Adolfo Han committed
> 2. **feature/SOAPI-SIMPL-222** --> For MRs, Tests will be executed with SimplOpen API TestRunner and Tags "@smoke or
     @SIMPL-222".
     >
     >
- Following command will be executed in pipeline:
>   - `xvfb-run mvn clean test -Dtest=ApiSimplOpenRunner -Dcucumber.filter.tags="@smoke or @SIMPL-222"`
Adolfo Han's avatar
Adolfo Han committed
> 3. **feature/SLUI-SIMPL-333** --> For MRs, Tests will be executed with SimplLabs UI TestRunner and Tags "@smoke or
     @SIMPL-333".
     >
     >
- Following command will be executed in pipeline:
>   - `xvfb-run mvn clean test -Dtest=UiSimplLabsRunner -Dcucumber.filter.tags="@smoke or @SIMPL-333"`
Adolfo Han's avatar
Adolfo Han committed
> 4. **feature/SLAPI-SIMPL-444** --> For MRs, Tests will be executed with SimplLabs API TestRunner and Tags "@smoke or
     @SIMPL-444".
     >
     >
- Following command will be executed in pipeline:
>   - `xvfb-run mvn clean test -Dtest=ApiSimplLabsRunner -Dcucumber.filter.tags="@smoke or @SIMPL-444"`
Adolfo Han's avatar
Adolfo Han committed
> 5. **feature/SOAPI-some-feature** --> For MRs, Tests will be executed with SimplOpen API TestRunner and default Tag "
     @smoke".
     >
     >
- Following command will be executed in pipeline:
>   - `xvfb-run mvn clean test -Dtest=ApiSimplOpenRunner -Dcucumber.filter.tags="@smoke"`
Adolfo Han's avatar
Adolfo Han committed
> 6. **feature/some-feature** --> For MRs, Tests will be executed with default SimplOpen UI TestRunner and default Tag "
     @smoke".
     >
     >
- Following command will be executed in pipeline:
>   - `xvfb-run mvn clean test -Dtest=UiSimplOpenRunner -Dcucumber.filter.tags="@smoke"`
Adolfo Han's avatar
Adolfo Han committed
> 7. **this-is-some-feature** --> For MRs, Tests will be executed with default SimplOpen UI TestRunner and default Tag "
     @smoke".
     >
     >
- Following command will be executed in pipeline:
>   - `xvfb-run mvn clean test -Dtest=UiSimplOpenRunner -Dcucumber.filter.tags="@smoke"`

##### **For Spikes:**
Adolfo Han's avatar
Adolfo Han committed

The following branch naming convention is recommended for spikes and changes not related to test cases:

> spike/`<short-description>`
Adolfo Han's avatar
Adolfo Han committed

- `<short-description>` is a text description about the spike
- During MRs for spike branches, Tests will be executed with default SimplOpen UI TestRunner and default Tag "@smoke".
- `xvfb-run mvn clean test -Dtest=UiSimplOpenRunner -Dcucumber.filter.tags="@smoke"`

### Scheduled Pipeline
Adolfo Han's avatar
Adolfo Han committed

- **test** followed by **report** stages of the defined pipeline will be executed during Scheduled Pipeline events
Adolfo Han's avatar
Adolfo Han committed
- It has been agreed that for every Scheduled Pipeline execution, regression test cases (marked with tag '**@regression
  **') will be executed
- TestRunner and Tags to be used to run the Automation tests have to be provided in the Scheduled Pipeline definition
Adolfo Han's avatar
Adolfo Han committed
- Any number of Scheduled Pipelines can be created as needed. e.g. Dedicated Daily Regression tests for different
  applications (SimplOpenUI, SimplOpenAPI, SimplLabsUI, SimplLabsAPI etc)
- Targets for Scheduled Pipelines can be the main 'develop' branch or any other branch
Adolfo Han's avatar
Adolfo Han committed
- Scheduled Pipelines can be created using the UI (necessary permissions needed):
  `pso-test-automation --> Builds --> Pipeline schedules--> New schedule`

**Example illustration:**
> - Setting up a daily regression for SimplOpen UI:
Adolfo Han's avatar
Adolfo Han committed
    >
- Running daily at 19:00 UTC+2
>   - With target branch 'develop'
>   - Using TestRunner 'UiSimplOpenRunner' (via variable RUNNER_TO_USE)
>   - Matching tags '@regression or @wizard' (via variable TAGS_TO_USE)

![img.png](src/main/resources/sample_schedule_pipeline.png)