1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-16 11:09:33 +02:00
sap-jenkins-library/documentation/docs/steps/seleniumExecuteTests.md
Oliver Nocon 7a961ef38e
seleniumExecuteTests - add step to run Selenium tests (#318)
It comes with an extension to executeDocker and executeDockerOnKubernetes to run sidecar containers.

This helps to execute Selenium tests using two Docker images:

1. Execution runtime for tests (e.g. node image)
2. Selenium instance which holds Selenium server + browser

* add documentation & some name cleanup
* include PR feedback
* add step documentation to structure
2018-10-04 17:06:42 +02:00

4.2 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.

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
containerPortMappings no [selenium/standalone-chrome:[[containerPort:4444, hostPort:4444]]]
dockerImage no buildTool=maven: maven:3.5-jdk-7
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.
  • containerPortMappings, 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
containerPortMappings 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

Return value

none

Side effects

none

Exceptions

none