Generating link through Reporter.log()

799 views
Skip to first unread message

M Bharath Raj Reddy

unread,
Aug 21, 2012, 7:39:52 AM8/21/12
to testng...@googlegroups.com
Hello,

I am using following code to generate the link for png file.


NewFileNamePath = "<a href=\"#\"  <span>" + NewFileNamePath + "</span> </a>";
System.out.println(NewFileNamePath);
Reporter.log(NewFileNamePath); 

Console Output: <a href="#"  <span>C:\eclipse\WorkspaceVSS\p2p\ScreenShots\Requisition_0001___Aug_21_2012__04_28_15PM_172.22.0.130.png</span> </a>

It is not generating link in the Reporter-Output, can some one help me in generating the link.


Regards,
Bharath.

Roman Hiden

unread,
Aug 21, 2012, 5:54:18 PM8/21/12
to testng...@googlegroups.com, mbr....@gmail.com
could you please check the source of the report if it does not contain your output?

some time ago I get an issue when reporter was not properly escaping special characters e.g <>

Bharath

unread,
Aug 22, 2012, 5:54:48 AM8/22/12
to testng...@googlegroups.com, mbr....@gmail.com
Hello,

I have verified the report, it is showing the below HTML
<span class="reporter-method-output">&lt;a href="#" &lt;span&gt;C:\eclipse\WorkspaceVSS\p2p\ScreenShots\Requisition_0001___Aug_22_2012__03_12_25PM_172.22.0.130.png&lt;/span&gt; &lt;/a&gt;<br></span> 


When I update it manually with following HTML, it shows the hyper link.
<span class="reporter-method-output"><a href="#"><span>C:\eclipse\WorkspaceVSS\p2p\ScreenShots\Requisition_0002___Aug_21_2012__12_48_24PM_172.22.0.130.png</span></a></span> 

Thanks,
Bharath.

Roman Hiden

unread,
Aug 22, 2012, 6:17:17 AM8/22/12
to testng...@googlegroups.com, mbr....@gmail.com
In my opinion that is a bug in Reporter. It should properly escape all characters. I will try to investigate this later on when will have some time

M Bharath Raj Reddy

unread,
Aug 22, 2012, 8:35:20 AM8/22/12
to Roman Hiden, testng...@googlegroups.com
Thank you Roman.

Regards,
Bharath.

Mike

unread,
Aug 25, 2012, 5:15:18 PM8/25/12
to testng...@googlegroups.com, mbr....@gmail.com
Why are you doing "&lt;" in your string?  I simply do this:
                String str = System.getProperty("user.dir") + "/"; // Current dir
                selenium.captureScreenshot(filename);
                Reporter.log("<img src=\"file:///" + str + filename +
                             "\" alt=\"\"/><br />");

Where filename is simply the name of the file, of course.

Mike

M Bharath Raj Reddy

unread,
Aug 27, 2012, 9:31:42 AM8/27/12
to Mike, testng...@googlegroups.com
Hello Mike,

I am getting following output on the screen

[img src="file:///C:\eclipse\WorkspaceVSS\p2p\ScreenShots\Testing_1___Aug_27_2012__06_58_41PM_172.22.0.130.png" alt=""/][br /]



Regards,
Bharath.

Mike

unread,
Sep 5, 2012, 7:03:18 PM9/5/12
to testng...@googlegroups.com, Mike, mbr....@gmail.com
If you look at my example code you will see I use a forward slash for the path, because Java will replace it in Windows if it has to.

Still, I am not sure that is your issue here.

Try looking at the page source for the report where it has the link.

You should also be able to put the path into your location field in the browser and have it display the image.  If it doesn't work then your path is likely incorrect.

Mike
Reply all
Reply to author
Forward
0 new messages