1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-11-24 08:32:32 +02:00

seleniumExecuteTests & uiVeri5ExecuteTests: improve documentation (#568)

* generate docs for seleniumExecuteTests

* inherit docs for uiVeri5ExecuteTests

* add description for failOnError
This commit is contained in:
Christopher Fenner 2019-03-19 15:38:52 +01:00 committed by GitHub
parent 60cbd2cd57
commit 7177954e80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 119 deletions

View File

@ -1,18 +1,6 @@
# seleniumExecuteTests
# ${docGenStepName}
## Description
Enables UI test execution with Selenium in a sidecar container.
The step executes a closure (see example below) connecting to a sidecar container with a Selenium Server.
When executing in a
* local Docker environment, please make sure to set Selenium host to **`selenium`** in your tests.
* Kubernetes environment, plese make sure to set Seleniums host to **`localhost`** in your tests.
!!! note "Proxy Environments"
If work in an environment containing a proxy, please make sure that `localhost`/`selenium` is added to your proxy exclusion list, e.g. via environment variable `NO_PROXY` & `no_proxy`. You can pass those via parameters `dockerEnvVars` and `sidecarEnvVars` directly to the containers if required.
## ${docGenDescription}
## Prerequisites
@ -76,66 +64,9 @@ webdriverio
});
```
## Parameters
## ${docGenParameters}
| parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------|
|script|yes|||
|buildTool|no|`npm`|`maven`, `npm`|
|containerPortMappings|no|`[selenium/standalone-chrome:[[containerPort:4444, hostPort:4444]]]`||
|dockerEnvVars|no|||
|dockerImage|no|buildTool=`maven`: `maven:3.5-jdk-8`<br />buildTool=`npm`: `node:8-stretch`<br />||
|dockerName|no|buildTool=`maven`: `maven`<br />buildTool=`npm`: `npm`<br />||
|dockerWorkspace|no|buildTool=`maven`: <br />buildTool=`npm`: `/home/node`<br />||
|failOnError|no|`true`||
|gitBranch|no|||
|gitSshKeyCredentialsId|no|``||
|sidecarEnvVars|no|||
|sidecarImage|no|`selenium/standalone-chrome`||
|sidecarName|no|`selenium`||
|sidecarVolumeBind|no|`[/dev/shm:/dev/shm]`||
|stashContent|no|<ul><li>`tests`</li></ul>||
|testRepository|no|||
* `script` defines the global script environment of the Jenkinsfile run. Typically `this` is passed to this parameter. This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md) for storing the measured duration.
* `buildTool` defines the build tool to be used for the test execution.
* `containerPortMappings`, see step [dockerExecute](dockerExecute.md)
* `dockerEnvVars`, see step [dockerExecute](dockerExecute.md)
* `dockerImage`, see step [dockerExecute](dockerExecute.md)
* `dockerName`, see step [dockerExecute](dockerExecute.md)
* `dockerWorkspace`, see step [dockerExecute](dockerExecute.md)
* `failOnError` specifies if the step should fail in case the execution of the body of this step fails.
* `sidecarEnvVars`, see step [dockerExecute](dockerExecute.md)
* `sidecarImage`, see step [dockerExecute](dockerExecute.md)
* `sidecarName`, see step [dockerExecute](dockerExecute.md)
* `sidecarVolumeBind`, see step [dockerExecute](dockerExecute.md)
* If specific stashes should be considered for the tests, you can pass this via parameter `stashContent`
* In case the test implementation is stored in a different repository than the code itself, you can define the repository containing the tests using parameter `testRepository` and if required `gitBranch` (for a different branch than master) and `gitSshKeyCredentialsId` (for protected repositories). For protected repositories the testRepository needs to contain the ssh git url.
## Step configuration
We recommend to define values of step parameters via [config.yml file](../configuration.md).
In following sections the configuration is possible:
| parameter | general | step | stage |
| ----------|-----------|---------|-----------------|
|script||||
|buildTool||X|X|
|containerPortMappings|X|X|X|
|dockerEnvVars|X|X|X|
|dockerImage|X|X|X|
|dockerName|X|X|X|
|dockerWorkspace|X|X|X|
|failOnError|X|X|X|
|gitBranch|X|X|X|
|gitSshKeyCredentialsId|X|X|X|
|sidecarEnvVars|X|X|X|
|sidecarImage|X|X|X|
|sidecarName|X|X|X|
|sidecarVolumeBind|X|X|X|
|stashContent|X|X|X|
|testRepository|X|X|X|
## ${docGenConfiguration}
## Side effects

View File

@ -1,6 +1,7 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper
import com.sap.piper.GenerateDocumentation
import com.sap.piper.GitUtils
import com.sap.piper.Utils
import com.sap.piper.k8s.ContainerMap
@ -9,28 +10,70 @@ import groovy.text.SimpleTemplateEngine
@Field String STEP_NAME = getClass().getName()
@Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS
@Field Set STEP_CONFIG_KEYS = [
'buildTool', //defines the tool which is used for executing the tests
'containerPortMappings', //port mappings required for containers. This will only take effect inside a Kubernetes pod, format [[containerPort: 1111, hostPort: 1111]]
'dockerEnvVars', //envVars to be set in the execution container if required
'dockerImage', //Docker image for code execution
'dockerName', //name of the Docker container. This will only take effect inside a Kubernetes pod.
'dockerWorkspace', //user home directory for Docker execution. This will only take effect inside a Kubernetes pod.
//TODO: limit parameter visibility
@Field Set GENERAL_CONFIG_KEYS = [
/**
* Defines the tool which is used for executing the tests
* @possibleValues `'maven'`, `'npm'`
*/
'buildTool',
/** @see dockerExecute */
'containerPortMappings',
/** @see dockerExecute */
'dockerEnvVars',
/** @see dockerExecute */
'dockerImage',
/** @see dockerExecute */
'dockerName',
/** @see dockerExecute */
'dockerWorkspace',
/**
* With `failOnError` the behavior in case tests fail can be defined.
* @possibleValues `true`, `false`
*/
'failOnError',
'gitBranch', //only if testRepository is used: branch of testRepository. Default is master
'gitSshKeyCredentialsId', //only if testRepository is used: ssh credentials id in case a protected testRepository is used
'sidecarEnvVars', //envVars to be set in Selenium container if required
'sidecarImage', //image for Selenium execution which runs as sidecar to dockerImage
'sidecarName', //name of the Selenium container. If not on Kubernetes pod, this will define the name of the link to the Selenium container and is thus required for accessing the server, example http://selenium:4444 (default)
'sidecarVolumeBind', //volume bind. This will not take effect in Kubernetes pod.
'stashContent', //list of stash names which are required to be unstashed before test run
'testRepository' //if tests are in a separate repository, git url can be defined. For protected repositories the git ssh url is required
/**
* Only if `testRepository` is provided: Branch of testRepository, defaults to master.
*/
'gitBranch',
/**
* Only if `testRepository` is provided: Credentials for a protected testRepository
* @possibleValues Jenkins credentials id
*/
'gitSshKeyCredentialsId',
/** @see dockerExecute */
'sidecarEnvVars',
/** @see dockerExecute */
'sidecarImage',
/** @see dockerExecute */
'sidecarName',
/** @see dockerExecute */
'sidecarVolumeBind',
/** @see dockerExecute */
'stashContent',
/**
* Define an additional repository where the test implementation is located.
* For protected repositories the `testRepository` needs to contain the ssh git url.
*/
'testRepository'
]
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
/**
* Enables UI test execution with Selenium in a sidecar container.
*
* The step executes a closure (see example below) connecting to a sidecar container with a Selenium Server.
*
* When executing in a
*
* * local Docker environment, please make sure to set Selenium host to **`selenium`** in your tests.
* * Kubernetes environment, plese make sure to set Seleniums host to **`localhost`** in your tests.
*
* !!! note "Proxy Environments"
* If work in an environment containing a proxy, please make sure that `localhost`/`selenium` is added to your proxy exclusion list, e.g. via environment variable `NO_PROXY` & `no_proxy`. You can pass those via parameters `dockerEnvVars` and `sidecarEnvVars` directly to the containers if required.
*/
@GenerateDocumentation
void call(Map parameters = [:], Closure body) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
def script = checkScript(this, parameters) ?: this

View File

@ -11,33 +11,22 @@ import static com.sap.piper.Prerequisites.checkScript
@Field String STEP_NAME = getClass().getName()
@Field Set GENERAL_CONFIG_KEYS = [
/**
* In case a `testRepository` is provided and it is protected, access credentials (as Jenkins credentials) can be provided with `gitSshKeyCredentialsId`. **Note: In case of using a protected repository, `testRepository` should include the ssh link to the repository.**
* @possibleValues Jenkins credentialId
*/
/** @see seleniumExecuteTests */
'gitSshKeyCredentialsId'
]
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus([
/**
* A map of environment variables to set in the container, e.g. [http_proxy:'proxy:8080'].
*/
/** @see dockerExecute */
'dockerEnvVars',
/**
* The name of the docker image that should be used. If empty, Docker is not used and the command is executed directly on the Jenkins system.
*/
/** @see dockerExecute */
'dockerImage',
/**
* Only relevant for Kubernetes case: Specifies a dedicated user home directory for the container which will be passed as value for environment variable `HOME`.
*/
/** @see dockerExecute */
'dockerWorkspace',
/**
* With `failOnError` the behavior in case tests fail can be defined.
* @possibleValues `true`, `false`
*/
'failOnError',
/**
* In case a `testRepository` is provided the branch in this repository can be specified with `gitBranch`.
*/
/** @see seleniumExecuteTests */
'gitBranch',
/**
* The command that is executed to install the test tool.
@ -55,25 +44,17 @@ import static com.sap.piper.Prerequisites.checkScript
* The port of the selenium hub. The value is only needed for the `runCommand`.
*/
'seleniumPort',
/**
* A map of environment variables to set in the sidecar container, similar to `dockerEnvVars`.
*/
/** @see dockerExecute */
'sidecarEnvVars',
/**
* The name of the docker image of the sidecar container. If empty, no sidecar container is started.
*/
/** @see dockerExecute */
'sidecarImage',
/**
* If specific stashes should be considered for the tests, their names need to be passed via the parameter `stashContent`.
*/
/** @see dockerExecute */
'stashContent',
/**
* This allows to set specific options for the UIVeri5 execution. Details can be found [in the UIVeri5 documentation](https://github.com/SAP/ui5-uiveri5/blob/master/docs/config/config.md#configuration).
*/
'testOptions',
/**
* With `testRepository` the tests can be loaded from another reposirory.
*/
/** @see seleniumExecuteTests */
'testRepository',
/**
* The `testServerUrl` is passed as environment variable `TARGET_SERVER_URL` to the test execution.