1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/documentation/docs/steps/seleniumExecuteTests.md
Marcus Holl 7446b1e93d Remove return value from step documentation
In the meantime the steps do not have a return value anymore.
2018-11-09 16:09:29 +01:00

4.7 KiB

seleniumExecuteTests

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.

Prerequisites

none

Example

seleniumExecuteTests (script: this) {
    git url: 'https://github.wdf.sap.corp/xxxxx/WebDriverIOTest.git'
    sh '''npm install
        node index.js'''
}

Example test using WebdriverIO

Example based on http://webdriver.io/guide/getstarted/modes.html and http://webdriver.io/guide.html

Configuration for Local Docker Environment

var webdriverio = require('webdriverio');
var options = {
    host: 'selenium',
    port: 4444,
    desiredCapabilities: {
        browserName: 'chrome'
    }
};

Configuration for Kubernetes Environment

var webdriverio = require('webdriverio');
var options = {
    host: 'localhost',
    port: 4444,
    desiredCapabilities: {
        browserName: 'chrome'
    }
};

Test Code (index.js)

// ToDo: add configuration from above

webdriverio
    .remote(options)
    .init()
    .url('http://www.google.com')
    .getTitle().then(function(title) {
        console.log('Title was: ' + title);
    })
    .end()
    .catch(function(err) {
        console.log(err);
    });

Parameters

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
buildTool=npm: node:8-stretch
dockerName no buildTool=maven: maven
buildTool=npm: npm
dockerWorkspace no buildTool=maven:
buildTool=npm: /home/node
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
  • tests
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 for storing the measured duration.
  • buildTool defines the build tool to be used for the test execution.
  • containerPortMappings, see step dockerExecute
  • dockerEnvVars, see step dockerExecute
  • dockerImage, see step dockerExecute
  • dockerName, see step dockerExecute
  • dockerWorkspace, see step dockerExecute
  • failOnError specifies if the step should fail in case the execution of the body of this step fails.
  • sidecarEnvVars, see step dockerExecute
  • sidecarImage, see step dockerExecute
  • sidecarName, see step dockerExecute
  • sidecarVolumeBind, see step dockerExecute
  • 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.

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

Side effects

none

Exceptions

none