cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Arunachalam_RM
Occasional Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisAdams
Community Leader

Re: How to create html file in groovy script and how to use dynamic values from response to html cod

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.

View solution in original post

7 REPLIES 7
Marsha_R
Community Hero

Re: How to create html file in groovy script and how to use dynamic values from response to html cod

 
Arunachalam_RM
Occasional Contributor

Re: How to create html file in groovy script and how to use dynamic values from response to html cod

I think u missed some texts
ChrisAdams
Community Leader

Re: How to create html file in groovy script and how to use dynamic values from response to html cod

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.

 

Arunachalam_RM
Occasional Contributor

Re: How to create html file in groovy script and how to use dynamic values from response to html cod

How to get the values from API response to external file(test step)?
ChrisAdams
Community Leader

Re: How to create html file in groovy script and how to use dynamic values from response to html cod

Hi,

 

As mentioned above, you can use a Datasink step to write the results of each Datasource iteration to an external file.

Arunachalam_RM
Occasional Contributor

Re: How to create html file in groovy script and how to use dynamic values from response to html cod

I need the output in html page..so I need values from response to html code.how to do that please help
ChrisAdams
Community Leader

Re: How to create html file in groovy script and how to use dynamic values from response to html cod

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.

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors