cheerioartillery

Get text content of captured selector in artillery test


I have an artillery test which I'd like to have check a title on a page to ensure that it is correct. I'm able to capture the element nicely using

      capture:
         - selector: "#BodyContent_lblWelcome"
           as: title

This element is a span and I'd like to check what text is in that span. I've tried various combinations of attr such as text, value, innerHTML and I've tried logging properties off the capture like so

  - log: "{{title}}"
  - log: "{{title.value}}"

The first log here prints something like [Object: null prototype] { id: 'BodyContent_lblWelcome' } but the second prints nothing. How can I get at the content of the node without resorting to a regex or xpath match?


Solution

  • It seems you can't currently as it only works with attributes, from the code:

    function extractCheerio(doc, expr, opts) {
      let $ = cheerio.load(doc);
      let els = $(expr);
      let i = 0;
      //snip...
      return els.slice(i, i + 1).attr(opts.attr);
    }