Forum Discussion

Arunachalam_RM's avatar
Arunachalam_RM
Occasional Contributor
4 years ago

How to create html file in groovy script and how to use dynamic values from response to html code

How to create html file in groovy script and how to use dynamic values from response to html code Basic HTML code in groovy will be little helpful for me and dynamically need to change value in html...
  • ChrisAdams's avatar
    ChrisAdams
    4 years ago

    Hi,

    Beyond some advice, I cannot help much further.  Why?  Well, I don't know your test, expected responses, step names, what you need to report, how you want to report, headings, CSS styles etc.

     

    I still think you'd be better off using a datasink and then using some other method/language to build the html with the results from the datasink output.

     

    I'd start simple.  Firstly you're going to need a Groovy step at the start of your test to create an empty HTML file and put some starter tags in that give the start of the HTML page.  E.g.

    <!DOCTYPE html>
    <html>
    <body>
    
    <h1>My Test Report</h1>
    <p>Some sub-heading</p>

     

    To achieve this, you're going to have to learn about Groovy and how to create and write strings to a file.  There's plenty of on-line resources that will help with this, so no need to write it here.

     

    At the very end of the test, you then need to 'close' the HTML.  Add another Groovy step at the end that also writes to the same file...

    </body>
    </html>

     

    Once you have that, then you need to think about how to report the line items of interest.  E.g html table.  For each call, and inside the loop, you're going to need a Groovy step that simply write the result of the test.

    file.write("<tr><td>" + ${Step Name#result} + "</td></tr>");

     

    As I say, there is too much in this query of yours to be able to help with specifics.