Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Breaking changes

### New features & improvements
- Refactor the Browser tests to use the builder approach ([#188](https://github.com/personio/datadog-synthetic-test-support/pull/188), [#189](https://github.com/personio/datadog-synthetic-test-support/pull/189))
- Refactor the Browser tests to use the builder approach ([#188](https://github.com/personio/datadog-synthetic-test-support/pull/188), [#189](https://github.com/personio/datadog-synthetic-test-support/pull/189), [#190](https://github.com/personio/datadog-synthetic-test-support/pull/190))

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.datadog.api.client.v1.model.SyntheticsStep
import com.datadog.api.client.v1.model.SyntheticsStepType
import com.personio.synthetics.model.actions.ActionsParams
import com.personio.synthetics.model.actions.SpecialActionsParams
import com.personio.synthetics.model.actions.WaitParams
import com.personio.synthetics.step.ui.model.TargetElement
import kotlin.time.Duration

private const val DEFAULT_TEXT_DELAY_MILLIS: Long = 25

Expand All @@ -15,6 +17,11 @@ class StepsBuilder {
return steps
}

/**
* Adds a new "type text" step to the synthetic browser test
* @param stepName Name of the step
* @param targetElement The web element where the text needs to be set
*/
fun typeText(
stepName: String,
targetElement: TargetElement,
Expand All @@ -32,6 +39,11 @@ class StepsBuilder {
)
}

/**
* Adds a new click step to the synthetic browser test
* @param stepName Name of the step
* @param targetElement The web element where the click is to be performed
*/
fun click(
stepName: String,
targetElement: TargetElement,
Expand All @@ -46,6 +58,11 @@ class StepsBuilder {
)
}

/**
* Adds a new hover step to the synthetic browser test
* @param stepName Name of the step
* @param targetElement The web element to which the hover has to be performed
*/
fun hover(
stepName: String,
targetElement: TargetElement,
Expand All @@ -60,6 +77,22 @@ class StepsBuilder {
)
}

/**
* Adds a new wait step to the synthetic browser test
* @param stepName Name of the step
* @param duration The duration to wait
*/
fun wait(
stepName: String,
duration: Duration,
) {
addStep(
stepName = stepName,
type = SyntheticsStepType.WAIT,
params = WaitParams(value = duration.inWholeSeconds.toInt()),
)
}

private fun addStep(
stepName: String,
type: SyntheticsStepType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import com.personio.synthetics.TEST_LOCATOR
import com.personio.synthetics.TEST_STEP_NAME
import com.personio.synthetics.model.actions.ActionsParams
import com.personio.synthetics.model.actions.SpecialActionsParams
import com.personio.synthetics.model.actions.WaitParams
import com.personio.synthetics.step.ui.model.TargetElement
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import kotlin.time.Duration.Companion.seconds

class StepsBuilderTest {
@Test
Expand Down Expand Up @@ -75,4 +77,21 @@ class StepsBuilderTest {
result.first(),
)
}

@Test
fun `wait adds wait step`() {
val sut = StepsBuilder()
sut.wait(TEST_STEP_NAME, 5.seconds)

val result = sut.build()

assertEquals(1, result.count())
assertEquals(
SyntheticsStep()
.name(TEST_STEP_NAME)
.type(SyntheticsStepType.WAIT)
.params(WaitParams(5)),
result.first(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.time.LocalTime
import java.time.ZoneId
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

/**
* Since the builder is still in progress, don't use it for the browser test creation
Expand Down Expand Up @@ -52,6 +53,7 @@ class E2EBrowserTest {
typeText("Type text", TargetElement("#my-element"), "new_text")
click("Click", TargetElement("#my-element"))
hover("Hover", TargetElement("#my-element"))
wait("Wait", 3.seconds)
}
}
}
Expand Down