How to use External HTML file in Karate.embed()?

Viewed 19

In my current karate reporting, I am trying to display a table format which looks similar to this -

Key V1 V2 Result
ID 1234 1234 PASS

The values of Key, V1, V2, Result are defined in my feature file.

Now, in order to display this table format in karate report, I am using Karate.embed() function -

karate.embed(*HTML code*,"text/html")

Instead of scripting the HTML code directly in Karate.embed() function and to avoid placing redundant HTML code inside this function, I am trying to store the exact same code in an external file and read it into my script -

* def HTML = karate.read('karatetabledisplay.html')
* karate.embed(HTML, "text/html")

When I do this, I am unable to display the values of Key, V1, V2 and Result.

Is there anyway I can pass these variables into the external HTML file and then display those values in my report?

1 Answers

I think you should look at the doc keyword. It is relatively new and can be considered "experimental". But I think it does exactly what you want: https://github.com/karatelabs/karate#doc

* doc { read: 'users.html' }
Related