HTML tags in console output using Reporter.log

1,558 views
Skip to first unread message

ingmar thompson

unread,
Feb 24, 2017, 2:25:33 PM2/24/17
to testng-users
Hello,
I am rather new to testNG (6.9.9) and am using it with Selenium WebDriver (2.53.1).  I am having a problem formatting the output using Reporter.log.  The output in the generated detailed report looks fine.  Please see the included image file formatted_output_in_report_html.  Then when I look at the report in the index.html file called Reporter Output, the same formatting is not replicated.  Please see the image file unformatted_output_in_reporter_output.  The format that I see in the console when running my tests looks fine as well.  Please see the included image file correctly_formatted_strings_to_console.  I understand HTML tags can be added to the Reporter.log(...) statements, but when I do this, I see HTML tags in the console output and the output in the generated detailed report takes on these new tags, which messes up the formatting.  I have tried using the Reporter.log(), log(java.lang.String s, int level, boolean logToStandardOut) to send a text only message to the console and another HTML message to the HTML generated reports, with Reporter.log("This is a test, 10, true) and Reporter.log("This is a test", 1, false), but this results in two strings being written to the HTML reports and one to the console when verbosity is set to 9 in testng.xml file.  This seems like a simple problem, but I have not found a way to get the formatting of the Reporter output to be the same as the detailed report.  Do you have any advise on how this problem can be resolved?

Thanks,
-ingmar
unformatted_output_in_reporter_output.png
formatted_output_in_report_html.png
correctly_formatted_strings_to_console.png

ingmar thompson

unread,
Mar 1, 2017, 8:47:30 PM3/1/17
to testng-users
Hello,
Does anyone have an answer for me?

Thanks,
-ingmar

ingmar thompson

unread,
Mar 10, 2017, 4:23:47 PM3/10/17
to testng-users
Hello,
I was wondering if anyone might know the answer to this?

Thanks much,
-ingmar

On Friday, February 24, 2017 at 12:25:33 PM UTC-7, ingmar thompson wrote:

ingmar thompson

unread,
Apr 3, 2017, 12:28:16 PM4/3/17
to testng-users
Hello,
I am still having this issue.  Does anyone have an answer?  Thanks much Ingmar


On Friday, February 24, 2017 at 12:25:33 PM UTC-7, ingmar thompson wrote:

SUBRAMANYESWARA RAO BHAVIRISETTY

unread,
Apr 4, 2017, 8:07:46 PM4/4/17
to testng-users
Hi ingmar,

Can you try using reportng to get proper html reports?

http://reportng.uncommons.org/ has all the details and you would get sample reports like http://reportng.uncommons.org/sample/index.html.

Regarding Reporter.log you should be able to use html tags.

String reason = "http://bugzilla.com/show_bug.cgi?id="
					+ bugid;
Reporter.log("<a href=\""+ reason + "\">Bug " + bugid + "</a>" );

If you are using maven project, then you could add the following in the dependency as documented at https://solidsoft.wordpress.com/2011/01/23/better-looking-html-test-reports-for-testng-with-reportng-maven-guide/

Please try using reportng and see if it solves your issue.

<dependency>

<groupId>org.uncommons</groupId>

<artifactId>reportng</artifactId>

<version>1.1.2</version>

<scope>test</scope>

<exclusions>

<exclusion>

<groupId>org.testng</groupId>

<artifactId>testng</artifactId>

</exclusion>

</exclusions>

</dependency>




            <plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.9</version>
				<configuration>
					
						<org.uncommons.reportng.failures-only>true</org.uncommons.reportng.failures-only>
						<org.uncommons.reportng.escape-output>false</org.uncommons.reportng.escape-output>
					</systemPropertyVariables>
					<!-- Add support for reportng -->
					<properties>
						<property>
							<name>listener</name>
							<value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter,org.testng.reporters.JUnitReportReporter</value>
							<name>org.uncommons.reportng.failures-only</name>
							<value>true</value>
						</property>
					</properties>


					
				</configuration>
			</plugin>
Subramanyam


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
Subramanyam

ingmar thompson

unread,
Apr 19, 2017, 6:29:06 PM4/19/17
to testng-users
Yes, I do understand that I can add HTML for the Reporter.log statements, but then if I have true (so I can also log to console), I then get horrible HTML tag code displayed in the console logs as well,  Not what I want.  Does reportng give you greater control over logging, so you can log a different message to the console and a different message to the HTML reports?  If Reporter.log had a switch so you didn't always by default have the string sent to the HTML report, then this would solve my problem.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.

To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
Subramanyam

SUBRAMANYESWARA RAO BHAVIRISETTY

unread,
Apr 20, 2017, 12:53:02 AM4/20/17
to testng-users
Unfortunately Reportng doesn't have it. You can only control the escaping of html characters.

Reporter.log always logs to html reports . If we say Reporter.log("test1") it will log to html report. If I
public static void log(java.lang.String s,
                       int level)
Log the passed string to the HTML reports if the current verbosity is equal or greater than the one passed in parameter

If you pass level 3  and use level 4 in reporter.log, then we don't write to html report right??

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.

To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
Subramanyam

ingmar thompson

unread,
Apr 21, 2017, 4:38:32 PM4/21/17
to testng-users
Yes, I have used this feature of the Reporter class to turn on/off DEBUG: statements, based on the verbose level setting.  Turning off/on HTML statements doesn't help with my problem.  I want to write to the console and the HTML reports, just using a text format for the console logging and a HTML format for the reports.  So from what you say and my own research, what I want to do is not possible with TestNG.  I appreciate your answers to me questions.  Thanks much for your time.
Reply all
Reply to author
Forward
0 new messages