Forum Discussion

Arunachalam_RM's avatar
Arunachalam_RM
Occasional Contributor
4 years ago
Solved

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 code which I will get from API responses
Please respond anything is fine
Thanks in advance

 

AlexKaras  Marsha_R  @richie

  • 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.

7 Replies

      • ChrisAdams's avatar
        ChrisAdams
        Champion Level 2

        Hi,

        You could do this within your test.  E.g. outside of loop, create a file.  Each row of the loop write out the results of the step, wrapped in some html.  Once out of loop 'close' the html.

        That, to me, seems to be a bit of a faff.  You'd have to manage the test flow and reporting in parallel.  A lot to go wrong.  

         

        Personally, I'd be more inclined to use a datasink step to save the results of the calls.  E.g. save to CSV.  Then build the html and merge in results by whatever means you choose.