Help with Datadog Provider - Synthetic Browser Test - params - elements

Hi,

I’m having a hard time getting the synthetic browser test working for datadog. Perhaps it’s because I don’t have a lot of web dev experience.

I’m having a hard time getting the browser_step.params element configured properly, I keep getting 400’s back from Datadog upstream, implying invalid syntax and I’m just not sure how to write it out.

For example:

resource "datadog_synthetics_test" "test_login" {
  name = var.name
  type = var.type

  request_definition {
    method = var.method
    url    = var.url
  }

  device_ids = var.device_ids
  locations  = var.locations

  options_list {
    tick_every = var.tick_every
  }

  message = var.message
  tags    = var.tags

  status = var.status

  browser_step {
    name = var.browser_step_name
    type = var.browser_step_type

    allow_failure = var.browser_step_allow_failure
    #    force_element_update = var.browser_step_force_element_update
    #    timeout              = var.browser_step_timeout

    params {
      element = jsonencode({
        "username"="test123"
      })
    }
  }
}

I know this not the proper code as it fails. However I used a selenium python script on a website I’m trying to make sure UI login works. I’ve identified the element as “username”, which is why I used it above
This is the error:

2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: HTTP/1.1 400 Bad Request
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: Content-Length: 73
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: Cache-Control: no-cache
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: Connection: keep-alive
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: Content-Security-Policy: frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: Content-Type: application/json
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: Date: Wed, 10 Mar 2021 23:07:00 GMT
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: Pragma: no-cache
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: Strict-Transport-Security: max-age=15724800;
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: X-Content-Type-Options: nosniff
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: X-Dd-Version: 35.4073548
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: X-Frame-Options: SAMEORIGIN
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: X-Ratelimit-Limit: 120
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: X-Ratelimit-Period: 60
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: X-Ratelimit-Remaining: 119
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: X-Ratelimit-Reset: 60
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: 
2021-03-10T17:07:00.855-0600 [DEBUG] plugin.terraform-provider-datadog_v2.21.0: {"errors": ["Step 0 has invalid params: 'value' is a required property"]}
2021/03/10 17:07:00 [DEBUG] datadog_synthetics_test.test_login: apply errored, but we're indicating that via the Error pointer rather than returning it: error creating synthetics test: 400 Bad Request: {"errors": ["Step 0 has invalid params: 'value' is a required property"]}

Error: error creating synthetics test: 400 Bad Request: {"errors": ["Step 0 has invalid params: 'value' is a required property"]}

  on main.tf line 1, in resource "datadog_synthetics_test" "test_login":
   1: resource "datadog_synthetics_test" "test_login" {


2021-03-10T17:07:00.884-0600 [WARN]  plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2021-03-10T17:07:00.887-0600 [DEBUG] plugin: plugin process exited: path=.terraform/providers/registry.terraform.io/datadog/datadog/2.21.0/darwin_amd64/terraform-provider-datadog_v2.21.0 pid=61095
2021-03-10T17:07:00.887-0600 [DEBUG] plugin: plugin exited

And if I try (and fail miserable) to use a value, I get an error stating value is unexpected. I just can’t figure this out.

    datadog = {
      source  = "DataDog/datadog",
      version = ">= 2.21.0"

TF version 0.14.6

The documentation is not clear to me.

Overall, lets say “example.com” has an element username and an element password. I’m simply trying to get a synthetic test created that lets me simulate logging in and out.

here is the html of the element for username, if I can figure out how to code that into terraform I can for sure figure out the password element syntax:

<input _ngcontent-xwa-c13="" autocomplete="off" autofocus="" class="input_login ng-pristine ng-invalid ng-touched" formcontrolname="username" item-id="login-username" name="username" required="" tabindex="0" type="text" placeholder="User ID">

I just can’t find any info I need and I’ve exhausted my searches.

Please help teach me how to reference elements, thanks!

1 Like

OK so maybe this is just hashicorp not finishing the resources functionality before putting into GA?:

# Example Usage (Synthetics Browser test)
# Support for Synthetics Browser test steps is limited (see below)
# Create a new Datadog Synthetics Browser test starting on https://www.example.org

I may assume at this point that only assertion browser tests work, and that a simple synthetic test of logging into a website and logging out of a website using element & params (Need more documentation on that please) is not possible at the moment.

Hashicorp, can you prove me wrong and show me an example? If not I’ll just keep hand rolling datadog resources and turn it into OaC once this resource works & once the documentation is updated.

I’ve also ran into this issue: Browser synthetic test creation fails with `'bucketKey' is a required property` · Issue #933 · DataDog/terraform-provider-datadog · GitHub however again, I’m still not sure if the actual resource is fully functional yet.

After further research this seems to be on the Datadog side of things?..

I’ll keep an eye on that issue and see what happens

In this case error stating:
“{“errors”: [“Step 0 has invalid params: ‘value’ is a required property”]}”
That’s is because you need to provide a value for params in “Step” step as it is a required property for this block.
if you look to official documentation here: https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/synthetics_test
you can find following:

  step {
    name = "Check current url"
    type = "assertCurrentUrl"
    params = jsonencode({
      "check" : "contains",
      *value" : "datadoghq"            <=========== HERE IS VALUE
    })
  }

Its been 3 months since this post, and still the element locator looks unreadable, there is a way wherein you can import browser test (create in Datadog UI and import in terraform), still terraform should provide a way to identify element by using data-qa/ data-id tags.