github.com/xgoffin/jenkins-library@v1.154.0/documentation/docs/steps/uiVeri5ExecuteTests.md (about)

     1  # ${docGenStepName}
     2  
     3  !!! warning "Deprecation notice"
     4      Details of changes after the step migrated to a golang based step can be found [below](#exceptions).
     5  
     6  ## ${docGenDescription}
     7  
     8  ## Prerequisites
     9  
    10  ## ${docGenParameters}
    11  
    12  ## ${docGenConfiguration}
    13  
    14  ## ${docJenkinsPluginDependencies}
    15  
    16  ## Exceptions
    17  
    18  The parameter `testOptions` is deprecated and is replaced by array type parameter `runOptions`. Groovy templating for this parameter is deprecated and no longer supported.
    19  
    20  Using the `runOptions` parameter the 'seleniumAddress' for UIVeri5 can be set.
    21  The former groovy implementation included a default for seleniumAddress in the runCommand. Since this is not possible with the golang-based implementation, the seleniumAddress has to be added to the runOptions. For jenkins on kubernetes the host is 'localhost', in other environments, e.g. native jenkins installations, the host can be set to 'selenium'.
    22  
    23  ```yaml
    24  runOptions: ["--seleniumAddress=http://localhost:4444/wd/hub", ..... ]
    25  ```
    26  
    27  The parameter `failOnError` is no longer supported on the step due to strategic reasons of pipeline resilience. To achieve the former behaviour with `failOnError: false` configured, the step can be wrapped using try/catch in your custom pipeline script.
    28  
    29  The `installCommand` does not support queueing shell commands using `&&` and `|` operator any longer.
    30  
    31  If you see an error like `fatal: Not a git repository (or any parent up to mount point /home/jenkins)` it is likely that your test description cannot be found.<br />
    32  Please make sure to point parameter `runOptions` to your `conf.js` file like `runOptions: [...., './path/to/my/tests/conf.js']`
    33  
    34  ## Examples
    35  
    36  ### Passing credentials from Jenkins
    37  
    38  When running acceptance tests in a real environment, authentication will be enabled in most cases. UIVeri5 includes [features to automatically perform the login](https://github.com/SAP/ui5-uiveri5/blob/master/docs/config/authentication.md) with credentials in the `conf.js`. However, having credentials to the acceptance system stored in plain text is not an optimal solution.
    39  
    40  Therefore, UIVeri5 allows templating to set parameters at runtime, as shown in the following example `conf.js`:
    41  
    42  ```js
    43  // Read environment variables
    44  const defaultParams = {
    45      url: process.env.TARGET_SERVER_URL,
    46      user: process.env.TEST_USER,
    47      pass: process.env.TEST_PASS
    48  };
    49  
    50  // Resolve path to specs relative to the working directory
    51  const path = require('path');
    52  const specs = path.relative(process.cwd(), path.join(__dirname, '*.spec.js'));
    53  
    54  // export UIVeri5 config
    55  exports.config = {
    56      profile: 'integration',
    57      baseUrl: '\${params.url}',
    58      specs: specs,
    59      params: defaultParams, // can be overridden via cli `--params.<key>=<value>`
    60      auth: {
    61          // set up authorization for CF XSUAA
    62          'sapcloud-form': {
    63              user: '\${params.user}',
    64              pass: '\${params.pass}',
    65              userFieldSelector: 'input[id="j_username"]',
    66              passFieldSelector: 'input[id="j_password"]',
    67              logonButtonSelector: 'button[type="submit"]',
    68              redirectUrl: /cp.portal\/site/
    69          }
    70      }
    71  };
    72  ```
    73  
    74  While default values for `baseUrl`, `user` and `pass` are read from the environment, they can also be overridden when calling the CLI.
    75  
    76  In a custom Pipeline, this is very simple: Just wrap the call to `uiVeri5ExecuteTests` in `withCredentials`:
    77  
    78  ```groovy
    79  withCredentials([usernamePassword(
    80      credentialsId: 'MY_ACCEPTANCE_CREDENTIALS',
    81      passwordVariable: 'password',
    82      usernameVariable: 'username'
    83  )]) {
    84      uiVeri5ExecuteTests script: this, runOptions: ["--baseURL=NEW_BASE_URL", "--params.user=${username}", "--params.pass=${password}", "--seleniumAddress=http://localhost:4444/wd/hub", "./uiveri5/conf.js"]
    85  }
    86  ```
    87  
    88  **Please note:** It is not recommended to override any secrets with the runOptions, because they may be seen in the Jenkins pipeline run console output. During the `withCredentials` call, the credentials are written to the environment and can be accessed by the test code.
    89  
    90  The following example shows the recommended way to handle the username and password for a uiVeri5ExecuteTests call that needs authentication. The `passwordVariable` and `usernameVariable` need to match the environment variables in the test code.
    91  
    92  ```groovy
    93  withCredentials([usernamePassword(
    94      credentialsId: 'MY_ACCEPTANCE_CREDENTIALS',
    95      passwordVariable: 'TEST_PASS',
    96      usernameVariable: 'TEST_USER'
    97  )]) {
    98      uiVeri5ExecuteTests script: this, runOptions: ["--seleniumAddress=http://localhost:4444/wd/hub", "./uiveri5/conf.js"]
    99  }
   100  ```
   101  
   102  There is also the option to use [vault for test credentials](https://www.project-piper.io/infrastructure/vault/#using-vault-for-test-credentials).
   103  
   104  In a Pipeline Template, a [Stage Exit](../extensibility/#1-extend-individual-stages) can be used to fetch the credentials and store them in the environment. As the environment is passed down to uiVeri5ExecuteTests, the variables will be present there. This is an example for the stage exit `.pipeline/extensions/Acceptance.groovy` where the `credentialsId` is read from the `config.yml`:
   105  
   106  ```groovy
   107  void call(Map params) {
   108      // read username and password from the credential store
   109      withCredentials([usernamePassword(
   110          credentialsId: params.config.acceptanceCredentialsId,
   111          passwordVariable: 'password',
   112          usernameVariable: 'username'
   113      )]) {
   114          // store the result in the environment variables for executeUIVeri5Test
   115          withEnv(["TEST_USER=\${username}", "TEST_PASS=\${password}"]) {
   116              //execute original stage as defined in the template
   117              params.originalStage()
   118          }
   119      }
   120  }
   121  return this
   122  ```