2018-09-21 16:55:31 +02:00
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
2018-10-04 17:06:42 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
2019-03-19 16:38:52 +02:00
|
|
|
import com.sap.piper.GenerateDocumentation
|
2018-10-08 11:30:42 +02:00
|
|
|
import com.sap.piper.GitUtils
|
2018-10-04 17:06:42 +02:00
|
|
|
import com.sap.piper.Utils
|
|
|
|
import com.sap.piper.k8s.ContainerMap
|
|
|
|
import groovy.transform.Field
|
2019-10-23 13:38:31 +02:00
|
|
|
import groovy.text.GStringTemplateEngine
|
2018-10-04 17:06:42 +02:00
|
|
|
|
2018-11-29 10:54:05 +02:00
|
|
|
@Field String STEP_NAME = getClass().getName()
|
2018-10-25 14:01:44 +02:00
|
|
|
|
2019-03-19 16:38:52 +02:00
|
|
|
//TODO: limit parameter visibility
|
|
|
|
@Field Set GENERAL_CONFIG_KEYS = [
|
|
|
|
/**
|
|
|
|
* Defines the tool which is used for executing the tests
|
2019-04-29 11:43:26 +02:00
|
|
|
* @possibleValues `maven`, `npm`, `bundler`
|
2019-03-19 16:38:52 +02:00
|
|
|
*/
|
|
|
|
'buildTool',
|
|
|
|
/** @see dockerExecute */
|
|
|
|
'containerPortMappings',
|
|
|
|
/** @see dockerExecute */
|
|
|
|
'dockerEnvVars',
|
|
|
|
/** @see dockerExecute */
|
|
|
|
'dockerImage',
|
|
|
|
/** @see dockerExecute */
|
|
|
|
'dockerName',
|
|
|
|
/** @see dockerExecute */
|
2019-07-25 11:57:21 +02:00
|
|
|
'dockerOptions',
|
|
|
|
/** @see dockerExecute */
|
2019-03-19 16:38:52 +02:00
|
|
|
'dockerWorkspace',
|
|
|
|
/**
|
|
|
|
* With `failOnError` the behavior in case tests fail can be defined.
|
|
|
|
* @possibleValues `true`, `false`
|
|
|
|
*/
|
2018-10-04 17:06:42 +02:00
|
|
|
'failOnError',
|
2019-03-19 16:38:52 +02:00
|
|
|
/**
|
|
|
|
* 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',
|
2020-02-17 15:34:19 +02:00
|
|
|
/**
|
|
|
|
* Defines the id of the user/password credentials to be used to connect to a Selenium Hub. The credentials are provided in the environment variables `PIPER_SELENIUM_HUB_USER` and `PIPER_SELENIUM_HUB_PASSWORD`.
|
|
|
|
*/
|
|
|
|
'seleniumHubCredentialsId',
|
2019-03-19 16:38:52 +02:00
|
|
|
/** @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'
|
2018-10-04 17:06:42 +02:00
|
|
|
]
|
2019-03-19 16:38:52 +02:00
|
|
|
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS
|
2018-10-04 17:06:42 +02:00
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
|
|
|
|
2019-03-19 16:38:52 +02:00
|
|
|
/**
|
|
|
|
* Enables UI test execution with Selenium in a sidecar container.
|
|
|
|
*
|
2023-08-28 16:42:07 +02:00
|
|
|
* This step is Jenkins-only.
|
|
|
|
*
|
2019-03-19 16:38:52 +02:00
|
|
|
* 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
|
2018-10-17 12:00:09 +02:00
|
|
|
void call(Map parameters = [:], Closure body) {
|
2018-10-04 17:06:42 +02:00
|
|
|
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
2018-10-31 09:40:12 +02:00
|
|
|
def script = checkScript(this, parameters) ?: this
|
2018-10-04 17:06:42 +02:00
|
|
|
def utils = parameters?.juStabUtils ?: new Utils()
|
2020-08-26 15:32:58 +02:00
|
|
|
String stageName = parameters.stageName ?: env.STAGE_NAME
|
2018-10-04 17:06:42 +02:00
|
|
|
|
|
|
|
// load default & individual configuration
|
2018-10-18 11:02:09 +02:00
|
|
|
Map config = ConfigurationHelper.newInstance(this)
|
2020-08-26 15:32:58 +02:00
|
|
|
.loadStepDefaults([:], stageName)
|
2018-10-25 14:01:44 +02:00
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
2018-10-04 17:06:42 +02:00
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
2020-08-26 15:32:58 +02:00
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS)
|
2018-10-04 17:06:42 +02:00
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
.dependingOn('buildTool').mixin('dockerImage')
|
|
|
|
.dependingOn('buildTool').mixin('dockerName')
|
|
|
|
.dependingOn('buildTool').mixin('dockerWorkspace')
|
|
|
|
.use()
|
|
|
|
|
2020-02-13 10:09:08 +02:00
|
|
|
// Inject config via env vars so that scripts running inside selenium can respond to that
|
|
|
|
config.dockerEnvVars = config.dockerEnvVars ?: [:]
|
2020-02-19 12:21:11 +02:00
|
|
|
config.dockerEnvVars.PIPER_SELENIUM_HOSTNAME = config.dockerName
|
|
|
|
config.dockerEnvVars.PIPER_SELENIUM_WEBDRIVER_HOSTNAME = config.sidecarName
|
2020-03-03 18:09:09 +02:00
|
|
|
if(config.containerPortMappings[config.sidecarImage]){
|
|
|
|
config.dockerEnvVars.PIPER_SELENIUM_WEBDRIVER_PORT = '' + (config.containerPortMappings[config.sidecarImage][0]?.containerPort ?: '')
|
|
|
|
}
|
2020-02-13 10:09:08 +02:00
|
|
|
|
2018-10-04 17:06:42 +02:00
|
|
|
dockerExecute(
|
|
|
|
script: script,
|
|
|
|
containerPortMappings: config.containerPortMappings,
|
2018-10-17 16:44:20 +02:00
|
|
|
dockerEnvVars: config.dockerEnvVars,
|
2018-10-04 17:06:42 +02:00
|
|
|
dockerImage: config.dockerImage,
|
|
|
|
dockerName: config.dockerName,
|
2019-07-25 11:57:21 +02:00
|
|
|
dockerOptions: config.dockerOptions,
|
2018-10-04 17:06:42 +02:00
|
|
|
dockerWorkspace: config.dockerWorkspace,
|
|
|
|
sidecarEnvVars: config.sidecarEnvVars,
|
|
|
|
sidecarImage: config.sidecarImage,
|
|
|
|
sidecarName: config.sidecarName,
|
|
|
|
sidecarVolumeBind: config.sidecarVolumeBind
|
|
|
|
) {
|
|
|
|
try {
|
2020-02-17 14:24:56 +02:00
|
|
|
sh returnStatus: true, script: """
|
|
|
|
node --version
|
|
|
|
npm --version
|
|
|
|
"""
|
2018-10-08 11:30:42 +02:00
|
|
|
config.stashContent = config.testRepository
|
|
|
|
?[GitUtils.handleTestRepository(this, config)]
|
|
|
|
:utils.unstashAll(config.stashContent)
|
2020-02-17 15:34:19 +02:00
|
|
|
if (config.seleniumHubCredentialsId) {
|
|
|
|
withCredentials([usernamePassword(credentialsId: config.seleniumHubCredentialsId, passwordVariable: 'PIPER_SELENIUM_HUB_PASSWORD', usernameVariable: 'PIPER_SELENIUM_HUB_USER')]) {
|
|
|
|
body()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
body()
|
|
|
|
}
|
2018-10-04 17:06:42 +02:00
|
|
|
} catch (err) {
|
|
|
|
if (config.failOnError) {
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|