我正在尝试使用 URL 映射通过 Terraform 在 Datadog 中构建一系列综合浏览器测试。测试将转到一个 URL,在登录表单中键入虚拟凭据,尝试登录,并断言将有一个无效的用户名/密码响应。当我尝试运行
terraform apply
时,我的代码失败了。我已经参考了文档,但我无法找到步骤类型为typeText
的浏览器测试示例。我是否错误地设置了参数?
代码:
resource "datadog_synthetics_test" "login_tests" {
for_each = var.browser_test_urls
type = "browser"
request_definition {
method = "GET"
url = each.value
}
device_ids = ["laptop_large"]
locations = ["aws:us-east-1"]
options_list {
tick_every = 1800
follow_redirects = true
retry {
count = 2
interval = 60000
}
}
name = "Login Test for ${each.key}"
message = "Login test failed for ${each.key} on url ${each.value}"
status = "paused"
browser_step {
name = "Type Username"
type = "typeText"
params {
element = "#userItem"
value = "username"
}
}
browser_step {
name = "Type Password"
params {
element = "#passItem"
value = "password"
}
type = "typeText"
}
browser_step {
name = "Click Login Button"
params {
element = "#btlogin"
}
type = "click"
}
browser_step {
name = "Check for Invalid Login Message"
params {
check = "contains"
value = "Invalid username or password!"
}
type = "assertPageContains"
}
}
错误:
│ Error: error creating synthetics browser test from https://us3.datadoghq.com/api/v1/synthetics/tests/browser: 400 Bad Request: {"errors":["Invalid steps data:
Step 0 has invalid params: None is not of type 'object'"]}
│
│ with module.datadog.datadog_synthetics_test.login_tests["Test"],
│ on modules\datadog\browser_tests.tf line 1, in resource "datadog_synthetics_test" "login_tests":
│ 1: resource "datadog_synthetics_test" "login_tests" {
对于面临类似问题的任何人,这就是我最终解决它的方式。
我通过 Datadog UI 创建了合成器,然后将其导入到我的 Terraform 状态中。从那里我查看了我的状态文件以查看元素属性的值。这是一个很长的 x 路径样式。我将整个字符串复制并粘贴到我的元素属性中,效果非常好!