2018-10-04 17:06:42 +02:00
|
|
|
import hudson.AbortException
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.ExpectedException
|
|
|
|
import org.junit.rules.RuleChain
|
|
|
|
import util.*
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.*
|
|
|
|
import static org.junit.Assert.assertThat
|
|
|
|
|
|
|
|
class SeleniumExecuteTestsTest extends BasePiperTest {
|
|
|
|
private ExpectedException thrown = ExpectedException.none()
|
2019-01-22 10:25:42 +02:00
|
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
2019-01-22 10:22:15 +02:00
|
|
|
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
2019-01-22 10:19:28 +02:00
|
|
|
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
|
2019-01-22 10:34:18 +02:00
|
|
|
private JenkinsDockerExecuteRule dockerExecuteRule = new JenkinsDockerExecuteRule(this)
|
2018-10-04 17:06:42 +02:00
|
|
|
|
|
|
|
@Rule
|
|
|
|
public RuleChain rules = Rules
|
|
|
|
.getCommonRules(this)
|
|
|
|
.around(new JenkinsReadYamlRule(this))
|
|
|
|
.around(thrown)
|
2019-01-22 10:34:18 +02:00
|
|
|
.around(dockerExecuteRule)
|
|
|
|
.around(stepRule) // needs to be activated after dockerExecuteRule, otherwise executeDocker is not mocked
|
2018-10-04 17:06:42 +02:00
|
|
|
|
|
|
|
boolean bodyExecuted = false
|
|
|
|
|
|
|
|
def gitMap
|
|
|
|
|
|
|
|
@Before
|
|
|
|
void init() throws Exception {
|
|
|
|
bodyExecuted = false
|
2018-10-08 11:30:42 +02:00
|
|
|
helper.registerAllowedMethod('stash', [String.class], null)
|
2018-10-04 17:06:42 +02:00
|
|
|
helper.registerAllowedMethod('git', [Map.class], {m ->
|
|
|
|
gitMap = m
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testExecuteSeleniumDefault() {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.seleniumExecuteTests(
|
2018-10-04 17:06:42 +02:00
|
|
|
script: nullScript,
|
|
|
|
juStabUtils: utils
|
|
|
|
) {
|
|
|
|
bodyExecuted = true
|
|
|
|
}
|
|
|
|
assertThat(bodyExecuted, is(true))
|
2019-01-22 10:34:18 +02:00
|
|
|
assertThat(dockerExecuteRule.dockerParams.containerPortMappings, is(['selenium/standalone-chrome': [[containerPort: 4444, hostPort: 4444]]]))
|
|
|
|
assertThat(dockerExecuteRule.dockerParams.dockerEnvVars, is(null))
|
|
|
|
assertThat(dockerExecuteRule.dockerParams.dockerImage, is('node:8-stretch'))
|
|
|
|
assertThat(dockerExecuteRule.dockerParams.dockerName, is('npm'))
|
|
|
|
assertThat(dockerExecuteRule.dockerParams.dockerWorkspace, is('/home/node'))
|
|
|
|
assertThat(dockerExecuteRule.dockerParams.sidecarEnvVars, is(null))
|
|
|
|
assertThat(dockerExecuteRule.dockerParams.sidecarImage, is('selenium/standalone-chrome'))
|
|
|
|
assertThat(dockerExecuteRule.dockerParams.sidecarName, is('selenium'))
|
|
|
|
assertThat(dockerExecuteRule.dockerParams.sidecarVolumeBind, is(['/dev/shm': '/dev/shm']))
|
2018-10-04 17:06:42 +02:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:44:20 +02:00
|
|
|
@Test
|
|
|
|
void testExecuteSeleniumCustomBuildTool() {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.seleniumExecuteTests(
|
2018-10-17 16:44:20 +02:00
|
|
|
script: nullScript,
|
|
|
|
buildTool: 'maven',
|
|
|
|
juStabUtils: utils
|
|
|
|
) {
|
|
|
|
bodyExecuted = true
|
|
|
|
}
|
|
|
|
assertThat(bodyExecuted, is(true))
|
2019-01-22 10:34:18 +02:00
|
|
|
assertThat(dockerExecuteRule.dockerParams.dockerImage, is('maven:3.5-jdk-8'))
|
|
|
|
assertThat(dockerExecuteRule.dockerParams.dockerName, is('maven'))
|
|
|
|
assertThat(dockerExecuteRule.dockerParams.dockerWorkspace, is(''))
|
2018-10-17 16:44:20 +02:00
|
|
|
}
|
2018-10-04 17:06:42 +02:00
|
|
|
@Test
|
|
|
|
void testExecuteSeleniumError() {
|
|
|
|
thrown.expectMessage('Error occured')
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.seleniumExecuteTests(
|
2018-10-04 17:06:42 +02:00
|
|
|
script: nullScript,
|
|
|
|
juStabUtils: utils
|
|
|
|
) {
|
|
|
|
throw new AbortException('Error occured')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testExecuteSeleniumIgnoreError() {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.seleniumExecuteTests(
|
2018-10-04 17:06:42 +02:00
|
|
|
script: nullScript,
|
|
|
|
failOnError: false,
|
|
|
|
juStabUtils: utils
|
|
|
|
) {
|
|
|
|
bodyExecuted = true
|
|
|
|
throw new AbortException('Error occured')
|
|
|
|
}
|
|
|
|
assertThat(bodyExecuted, is(true))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testExecuteSeleniumCustomRepo() {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.seleniumExecuteTests(
|
2018-10-04 17:06:42 +02:00
|
|
|
script: nullScript,
|
|
|
|
gitBranch: 'test',
|
|
|
|
gitSshKeyCredentialsId: 'testCredentials',
|
|
|
|
juStabUtils: utils,
|
|
|
|
testRepository: 'git@test/test.git'
|
|
|
|
) {
|
|
|
|
bodyExecuted = true
|
|
|
|
}
|
|
|
|
assertThat(bodyExecuted, is(true))
|
|
|
|
assertThat(gitMap, hasEntry('branch', 'test'))
|
|
|
|
assertThat(gitMap, hasEntry('credentialsId', 'testCredentials'))
|
|
|
|
assertThat(gitMap, hasEntry('url', 'git@test/test.git'))
|
|
|
|
}
|
|
|
|
}
|