tag:blogger.com,1999:blog-2411958903224745637.post6308881016791369487..comments2024-03-14T10:48:54.941+05:30Comments on All about application performance and test automation: Selenium - Capture Screenshot using TestNGBharath Marrivadahttp://www.blogger.com/profile/12485730458517413391noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-2411958903224745637.post-5501007257422430322014-09-08T15:15:51.245+05:302014-09-08T15:15:51.245+05:30NewFileNamePath = "ScreenShot"+ Count + ... NewFileNamePath = "ScreenShot"+ Count + "";<br /> Reporter.log(NewFileNamePath);<br /> <br />by using this code i not able to see the link in testng reported createdpavanhttps://www.blogger.com/profile/13271343123210926732noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-88615750625601842013-08-25T15:42:25.800+05:302013-08-25T15:42:25.800+05:30public class TestListenerAdapter implements ITestL...public class TestListenerAdapter implements ITestListener {<br /> private int Count = 0;<br /> public void onFinish(ITestContext result) {}<br /> public void onStart(ITestContext result) {}<br /> @Override<br /> public void onTestFailure(ITestResult result) {<br /> System.out.println("Finished Executing Test: "+result.getName()+"Status: Failed"+"\n Reason:"+result.getThrowable());<br /> try {<br /> screenshot(result);<br />} catch (AWTException e) {<br /> // TODO Auto-generated catch block<br /> e.printStackTrace();<br />}<br />} <br /><br /><br /> @Override<br /> public void onTestSkipped(ITestResult result) {<br /> System.out.println("Skipped test: "+result.getName()+"Reason:"+result.getThrowable());<br /> }<br /> @Override<br /> public void onTestStart(ITestResult result) {<br /> System.out.println("Starting Test: "+result.getName());<br /> }<br /> @Override<br /> public void onTestSuccess(ITestResult result) {<br /> System.out.println("Finished Executing Test: "+result.getName()+"Status: Success.");<br /> }<br /> public void onTestFailedButWithinSuccessPercentage(ITestResult result) {<br /> System.out.println("Test failed but within success percentage");<br /> try {<br /> screenshot(result);<br /> } catch (AWTException e) {<br /> // TODO Auto-generated catch block<br /> e.printStackTrace();<br /> }<br /> }<br /> <br /> private void screenshot(ITestResult result) throws AWTException{<br /> try {<br /> <br /> Calendar calendar = Calendar.getInstance();<br /> String screenShotsFolder ="E:\\Programming\\eclipse-java-indigo-win32-andriod" +<br /> "\\Eclipse Workspace\\Test Datamoat Web Apps\\test-output\\ScreenShots\\";<br /> String testMethodAndTestClass = result.getMethod().getMethodName() + "(" + result.getTestClass().getName() + ")";<br /> String filename = screenShotsFolder <br /> + testMethodAndTestClass + "-"<br /> + calendar.get(Calendar.YEAR) + "-"<br /> + calendar.get(Calendar.MONTH) + "-"<br /> + calendar.get(Calendar.DAY_OF_MONTH) + "-"<br /> + calendar.get(Calendar.HOUR_OF_DAY) + "-"<br /> + calendar.get(Calendar.MINUTE) + "-"<br /> + calendar.get(Calendar.SECOND) + "-"<br /> + calendar.get(Calendar.MILLISECOND)<br /> + ".png";<br /> <br /> //Take Scrrenshot<br /> File scrnsht =((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);<br /> //Copy screenshot into a specific location<br /> FileUtils.copyFile(scrnsht, new File(filename));<br /> //Reporter.log("result");<br /> <br /> <br /> //Place the reference in TestNG web report<br /> <br /> Reporter.log(filename);<br /> <br /> <br /> <br /> <br /> <br /> }<br /> <br /> catch (IOException e) {<br /> <br /> e.printStackTrace();<br /> <br /> }<br /> <br /> }<br /> <br />}<br /><br /><br />But it does not working . Actually i did not get any screen shot in the location<br />can any one help me?sakiburrahmanhttps://www.blogger.com/profile/02354447174491731708noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-80605773127564168122013-04-24T15:28:11.350+05:302013-04-24T15:28:11.350+05:30please mail me the stuff since am also facing the ...please mail me the stuff since am also facing the same issue faced by Somesh BansalAbhilash Gopidashttps://www.blogger.com/profile/10126592723529743322noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-44800536659711139462012-12-13T23:16:05.402+05:302012-12-13T23:16:05.402+05:30I think there is an issue with TestNG wile parsing...I think there is an issue with TestNG wile parsing the escape sequence.<br />Look at following link for more details.<br /><br />https://groups.google.com/forum/?fromgroups=#!topic/testng-users/9iIn-8kiYAoBharath Marrivadahttps://www.blogger.com/profile/12485730458517413391noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-53201027794736624542012-12-13T15:25:55.639+05:302012-12-13T15:25:55.639+05:30Hi,
thank you for posting such a beautiful concept...Hi,<br />thank you for posting such a beautiful concept !!!!!!!!<br />I tried same concept, for me 'Snapshot1' link also coming but problem is , if i click that link i am unable to see snapshot.<br /><br />Its coming like this <br /><br />"The page cannot be found <br />The page you are looking for might have been removed, had its name changed, or is temporarily unavailable. <br /><br />--------------------------------------------------------------------------------<br /><br />Please try the following:<br /><br />If you typed the page address in the Address bar, make sure that it is spelled correctly.<br /><br />Open the draft.blogger.com home page, and then look for links to the information you want. <br />Click the Back button to try another link. <br />Click Search to look for information on the Internet. <br /><br />HTTP 404 - File not found<br />Internet Explorer "<br /> <br />Please guide me how to over come this issue .....<br /><br />Thanks<br />Sangeeta MohnatyAnonymoushttps://www.blogger.com/profile/16277629863614088929noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-57615740266016723802012-11-01T15:21:23.338+05:302012-11-01T15:21:23.338+05:30unable to continue with my other work ???
Why you ...unable to continue with my other work ???<br />Why you are not able to continue with your work?<br /><br />It silently take the screen shot of the entire desktop and store it in a file. If your application is minimized, you will get desktop screen shot.Bharath Marrivadahttps://www.blogger.com/profile/12485730458517413391noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-84587505023163733872012-11-01T15:16:50.290+05:302012-11-01T15:16:50.290+05:30The problem with thiscode is , it captures the scr...The problem with thiscode is , it captures the screenshot of whatever application I am working on.This makes me unable to continue with my other work Gaurav Guptahttps://www.blogger.com/profile/06755631081685199264noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-28853546278404776652012-08-22T18:09:42.866+05:302012-08-22T18:09:42.866+05:30Hello Rakesh,
I think there is an issue with Test...Hello Rakesh,<br /><br />I think there is an issue with TestNG wile parsing the escape sequence.<br />Look at following link for more details.<br /><br />https://groups.google.com/forum/?fromgroups=#!topic/testng-users/9iIn-8kiYAoBharath Marrivadahttps://www.blogger.com/profile/12485730458517413391noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-9694709915688053482012-08-12T13:54:39.188+05:302012-08-12T13:54:39.188+05:30Hi Bharath,
The problem with above code is , it c...Hi Bharath,<br /><br />The problem with above code is , it captures the screenshot of whatever application I am working on.This makes me unable to continue with my other work ,with selenium running in other window.<br /><br />Also I guess the code You used to generate the Hyperlink will not work without using href.Rakesh kapoorhttps://www.blogger.com/profile/09891729754709337143noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-83702355816942997632012-08-10T00:28:33.741+05:302012-08-10T00:28:33.741+05:30Thanks alot for this post. I had followed your cod...Thanks alot for this post. I had followed your code for taking screenshot.For me ,screenshot is getting loaded in ScreenShots folder in my workspace. But I am unable to make it as a link in Testng-XSLT report.Could you please clarify my doubt.<br />In Testng-XSLT, ReporterOutput page,only text is printed as "Screenshot"Suhurthu...https://www.blogger.com/profile/08703543737006719978noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-19457009753247667322012-08-01T14:21:47.585+05:302012-08-01T14:21:47.585+05:30I have sent you an email, now it should work fine....I have sent you an email, now it should work fine.Bharath Marrivadahttps://www.blogger.com/profile/12485730458517413391noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-23462384294674668962012-08-01T13:20:17.585+05:302012-08-01T13:20:17.585+05:30my bad luck :(
unable to make out where I am makin...my bad luck :(<br />unable to make out where I am making mistakeAnonymoushttps://www.blogger.com/profile/12236280781548303105noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-52264507052132175542012-08-01T12:55:59.182+05:302012-08-01T12:55:59.182+05:30Hyper link is generated using following code.
Ne...Hyper link is generated using following code. <br />NewFileNamePath = "<a href="+%20NewFileNamePath%20+" rel="nofollow">ScreenShot" + "</a>";<br />Reporter.log(NewFileNamePath);<br /><br />Check whether the file really getting created in the designated path (NewFileNamePath)Bharath Marrivadahttps://www.blogger.com/profile/12485730458517413391noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-81700530767367528732012-08-01T12:50:16.747+05:302012-08-01T12:50:16.747+05:30Hi Bharat,
Thanks for taking out time and respond...Hi Bharat,<br /><br />Thanks for taking out time and responding to my queries, but still no success<br /><br />Not getting hyperlink, shows only text<br /><br />Can you please provide your email id, so that I can share you my detailed code (or you can share your's as undersigned)<br /><br />Thanking You<br />Somesh bansal<br />sbansal.ece@gmail.comAnonymoushttps://www.blogger.com/profile/12236280781548303105noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-77862048574216086492012-08-01T12:20:02.569+05:302012-08-01T12:20:02.569+05:30In my post some of the html content was not copied...In my post some of the html content was not copied properly(It is not allowing to past certain tags due to conflicts), so I have copied the latest code from my machine. Try to execute this code, hope this will resolve the issue.Bharath Marrivadahttps://www.blogger.com/profile/12485730458517413391noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-54995261116432674332012-08-01T12:13:58.134+05:302012-08-01T12:13:58.134+05:30HI Bharat,
I could not understand your response,...HI Bharat, <br /><br />I could not understand your response, can you please elaborate..??Anonymoushttps://www.blogger.com/profile/12236280781548303105noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-2019332603808073662012-08-01T12:02:45.934+05:302012-08-01T12:02:45.934+05:30String NewFileNamePath;
java.awt.Dimension res...String NewFileNamePath;<br /><br /> java.awt.Dimension resolution = Toolkit.getDefaultToolkit()<br /> .getScreenSize();<br /> Rectangle rectangle = new Rectangle(resolution);<br /><br /> // Get the dir path<br /> File directory = new File(".");<br /> // System.out.println(directory.getCanonicalPath());<br /><br /> // get current date time with Date() to create unique file name<br /> DateFormat dateFormat = new SimpleDateFormat(<br /> "MMM_dd_yyyy__hh_mm_ssaa");<br /> // get current date time with Date()<br /> Date date = new Date();<br /> // System.out.println(dateFormat.format(date));<br /><br /> // To identify the system<br /> InetAddress ownIP = InetAddress.getLocalHost();<br /> // System.out.println("IP of my system is := "+ownIP.getHostAddress());<br /><br /> NewFileNamePath = directory.getCanonicalPath() + "\\ScreenShots\\"<br /> + TestCaseId + "___" + dateFormat.format(date) + "_"<br /> + ownIP.getHostAddress() + ".png";<br /> Print(NewFileNamePath);<br /><br /> // Capture the screen shot of the area of the screen defined by the<br /> // rectangle<br /> Robot robot = new Robot();<br /> BufferedImage bi = robot.createScreenCapture(new Rectangle(<br /> rectangle));<br /> ImageIO.write(bi, "png", new File(NewFileNamePath));<br /> NewFileNamePath = "<a href="+%20NewFileNamePath%20+" rel="nofollow">ScreenShot"<br /> + "</a>";<br /> // Place the reference in TestNG web report<br /> Reporter.log(NewFileNamePath);<br /> Wait(3000);Bharath Marrivadahttps://www.blogger.com/profile/12485730458517413391noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-80197123233605538162012-08-01T11:48:19.317+05:302012-08-01T11:48:19.317+05:30Hello,
I ran the same scenario but unable to emb...Hello, <br /><br />I ran the same scenario but unable to embed the hyperlink to the index.html report generated in old folder of test-output folder<br /><br />It just shows it as text<br /><br />Reporter output<br />[a href="C:\Projects\TestArtifact-2tr\Failure_ScreenShots\testSclGrp_TopRecentNews_01_Aug_2012__11_34_07AM.png",target='_blank']ScreenShot1[/a]<br /><br />Please take a look and provide your commentsAnonymoushttps://www.blogger.com/profile/12236280781548303105noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-88337389192184956542012-07-25T14:05:38.905+05:302012-07-25T14:05:38.905+05:30Thanks for information!
BHARATH MARRIVADAThanks for information! <br />BHARATH MARRIVADAshreeneelghttps://www.blogger.com/profile/14235565130402356867noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-11212271215945179812012-03-14T13:38:10.993+05:302012-03-14T13:38:10.993+05:30Hello Bharath,
Screenshot functionality is working...Hello Bharath,<br />Screenshot functionality is working fine on my local machine. But when I deploy it on my HUB machine(Linux machine) and execute it through HUDSON then it is not working and below error found in Hudson console: <br />[testng] java.awt.AWTException: headless environment<br /> [testng] at java.awt.Robot.(Robot.java:75)<br /> [testng] at fbTAF.TestNGCustom.ScreenShot(TestNGCustom.java:74)<br /> [testng] at fbTAF.TestNGCustom.onTestSuccess(TestNGCustom.java:38)<br /> [testng] at org.testng.internal.Invoker.runTestListeners(Invoker.java:1800)<br /> [testng] at org.testng.internal.Invoker.runTestListeners(Invoker.java:1780)<br /> [testng] at org.testng.internal.Invoker.invokeMethod(Invoker.java:749)<br /> [testng] at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846)<br /> [testng] at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)<br /> [testng] at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)<br /> [testng] at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)<br /> [testng] at org.testng.TestRunner.runWorkers(TestRunner.java:1147)<br /> [testng] at org.testng.TestRunner.privateRun(TestRunner.java:749)<br /> [testng] at org.testng.TestRunner.run(TestRunner.java:600)<br /> [testng] at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)<br /> [testng] at org.testng.SuiteRunner.access$000(SuiteRunner.java:34)<br /> [testng] at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:351)<br /> [testng] at org.testng.internal.thread.ThreadUtil$CountDownLatchedRunnable.run(ThreadUtil.java:147)<br /> [testng] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)<br /> [testng] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)<br /> [testng] at java.lang.Thread.run(Thread.java:662)<br /> [testng] /var/lib/hudson/jobs/FBIB_TAF/workspace\ScreenShots\14_Mar_2012__08_56_56AM_127.0.0.1.png<br /><br />I am using Selenium-grid-1.0.8 and RC machine is WIN7 having Firefox browser. My RC machine IP is 192.168.1.164 but InetAddress ownIP=InetAddress.getLocalHost(); return 127.0.0.1 as shown in above log.<br /><br />Please help me in resolving this issue.subhashhttps://www.blogger.com/profile/17071337102491620323noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-83796680096475000372012-03-13T16:42:34.949+05:302012-03-13T16:42:34.949+05:30Hello Bharath/Rama, same error I am facing on Ecli...Hello Bharath/Rama, same error I am facing on Eclipse..syntax error,insert';' to complete statement.Can you tell me how you resolve it?<br /><br />In my case if I am using below code then report log shows ScreenShot but not hyperlink<br />NewFileNamePath = "ScreenShot"+ Count + "";<br />Reporter.log(NewFileNamePath);<br /><br />And if I use NewFileNamePath = "<a href="http://draft.blogger.com/+NewFileNamePath+" rel="nofollow">ScreenShot"+ Count + "</a>";<br /><br />then above syntex error is coming.subhashhttps://www.blogger.com/profile/17071337102491620323noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-9494924862907918472011-11-10T11:06:18.445+05:302011-11-10T11:06:18.445+05:30Rama,
No, copy the results in an excel graph manua...Rama,<br />No, copy the results in an excel graph manually or extract the results and create an excel for creating graphs.Bharath Marrivadahttps://www.blogger.com/profile/12485730458517413391noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-45087517026306946542011-11-10T00:29:04.978+05:302011-11-10T00:29:04.978+05:30Bharath,
Its working now.I was just confused.
Th...Bharath,<br /><br />Its working now.I was just confused.<br /><br />This is really helpful.<br /><br />bharath, can we produce graphs with testng?Ramahttps://www.blogger.com/profile/04387027084716891228noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-60707215807171921362011-11-09T22:53:22.909+05:302011-11-09T22:53:22.909+05:30Folder created in in root directory.
But the prob...Folder created in in root directory.<br /><br />But the problem is with this - <br />NewFileNamePath = "<a href="http://draft.blogger.com/+NewFileNamePath+" rel="nofollow">ScreenShot"+ Count + "</a>";<br /><br />Here I'm getting syntax error,insert';' to complete statement.Ramahttps://www.blogger.com/profile/04387027084716891228noreply@blogger.comtag:blogger.com,1999:blog-2411958903224745637.post-66529861433462114932011-11-09T11:04:06.973+05:302011-11-09T11:04:06.973+05:30Hello Rama,
Screen shot is stored in the followin...Hello Rama,<br /><br />Screen shot is stored in the following location<br /><br /> NewFileNamePath = directory.getCanonicalPath()+ "\\ScreenShots\\"+ dateFormat.format(date)+"_"+ownIP.getHostAddress()+ ".png";<br /> System.out.println(NewFileNamePath);<br /><br /><br />Hyper link is created using following code<br /><br />NewFileNamePath = "<a href="+NewFileNamePath+" rel="nofollow">ScreenShot"+ Count + "</a>";<br />Reporter.log(NewFileNamePath);<br /><br />Do you have "ScreenShots" folder in your root directory?Bharath Marrivadahttps://www.blogger.com/profile/12485730458517413391noreply@blogger.com