(JavascriptExecutor) driver.executeScript("document.wite()") does not return the control back

1,030 views
Skip to first unread message

Brad

unread,
Apr 25, 2013, 8:32:41 PM4/25/13
to seleniu...@googlegroups.com
Hi All,

Here is what i'm trying to do..

driver - new FirefoxDriver();
htmlString ="return document.write ('Print the Test values in html format');";
(JavascriptExecutor) driver.executeScript(htmlString);

When I executed this script, it displays the output in the browser which is correct  but the script did not complete its execution and browser keep running which displays "connecting.." on top of browser. And when I interrupt and close the browser manually it displays the following. But my question is why the test script did not complete execution and why the browser keep on running once it has rendered the output. I'm using Selenium Webdriver (selenium-2.31.0) and I'm using Java as my programming language. If anyone can help me to address this one that'll be helpful


"The exception while displaying HTML isorg.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_05'
Driver info: driver.version: RemoteWebDriver"

Regards,
Brad

Brad

unread,
Apr 25, 2013, 8:36:09 PM4/25/13
to seleniu...@googlegroups.com


On Friday, 26 April 2013 10:32:41 UTC+10, Brad wrote:
Hi All,

Here is what i'm trying to do..

driver - new FirefoxDriver();
htmlString ="return document.write ('Print the Test values in html format');";
((JavascriptExecutor) driver).executeScript(htmlString);

David

unread,
Apr 28, 2013, 12:44:01 AM4/28/13
to seleniu...@googlegroups.com
I don't get what you're trying to do with that code snippet. Why are you writing output into the current page? How is this code snippet used in the context of your overall test?

If you have problems with this code snippet, then you might have to try a different method of writing to or updating the page, something along the lines of:

String script = "var anElement = document.createElement(\"p\");"
script += "anElement.innerHTML = \"Print the Test values in html format\";";
script += "document.body.appendChild(anElement);";
((JavascriptExecutor) driver).executeScript(script);

and also bear in mind that writing to or updating the page does not require a "return" in the javascript code unless you expect to get back some value to store in a variable.

Brad

unread,
Apr 28, 2013, 11:35:51 PM4/28/13
to seleniu...@googlegroups.com
Hi David,

Thanks for your update..That was really helpful indeed and it worked out good for me with little tweek..

But just to brief you..

What I'm attempting to do is to build a html report to display the Summary of Test results including step by step results, for which i need to build htmlstring and concatenate it together and execute as one Javascript. As of now I found that I could not use other reporting tools as it only displays the overall Summary of the Test results. But I may be wrong, so in case you know any reporting tool that can be used to build html report and can display step by step results, Pls let me know..

Thanks,
Brad

On Friday, 26 April 2013 10:32:41 UTC+10, Brad wrote:

Krishnan Mahadevan

unread,
Apr 28, 2013, 11:43:05 PM4/28/13
to seleniu...@googlegroups.com
How are you running your tests?
If its via TestNG then TestNG provides you with listener capabilities. 
You need to implement IReporter listener and put in your custom listener logic in there. 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rCRC-4gO5AwJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

David Lai

unread,
Apr 29, 2013, 11:38:36 AM4/29/13
to seleniu...@googlegroups.com
Feels kinda weird to me to build a report in the dom.  I think it might be easier to create a report in an XML object, then open it using an XLST template.

David

unread,
Apr 29, 2013, 1:44:20 PM4/29/13
to seleniu...@googlegroups.com
Building report with DOM/HTML doesn't seem strange to me. But what is strange is building such report using Selenium.

Brad, so my assumption is you're constructing this report with Selenium at the end of your Selenium test? Either way, are you constructing this against a blank page (ie. about:blank, etc.)? I don't see how it would be feasible long term to build test report from Selenium since the constructed report page is only saved to temp storage and never as an explicit output file. To save it as such would then require use of external tools like AutoIt, Sikuli, etc. to save it from the OS + browser side where it's not available as an option from Selenium APIs (and you can't execute a "save" from javascript due to security sandboxing). Additionally, Selenium tends to close the browser at the end of the test, so I fail to see how the results will persist under file storage. Or should I assume you're writing to the site under tests DOM which somehow backs up the DOM changes to your web app/server?

If you're not using an exsiting test framework, I'd suggest you write your report generator from scratch in pure programming language. Since your original design was javascript's "document.write()", I don't see how that's any different from a "print" statement in any programming language where you simply print out HTML (but to file instead of standard output).

Brad

unread,
Apr 29, 2013, 7:26:57 PM4/29/13
to seleniu...@googlegroups.com
Hi Krishnan,

Thanks for your updates

I'm not using TestNG, but JUnit4

Cheers,
Barani

Brad

unread,
Apr 29, 2013, 7:29:12 PM4/29/13
to seleniu...@googlegroups.com

Brad

unread,
Apr 29, 2013, 7:29:50 PM4/29/13
to seleniu...@googlegroups.com
Hi Krishnan,

Thanks for your updates

I'm not using TestNG, but JUnit4

Cheers,
Barani


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

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rCRC-4gO5AwJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Brad

unread,
Apr 29, 2013, 8:09:14 PM4/29/13
to seleniu...@googlegroups.com
HI David,

Thanks for providing more insight on this..

Basically I was asked to create HTML & Excel report for the Test cases executed (displaying step level results) . So I thought of creating the HTML report via Selenum driver as a first step to make sure i'm able to populate the HTML report in a right format and then proceed on to save the report in my local drive.  

But I see your point that there is no necessity to use the Selenium driver if I've to build the report and save in the local drive. Also what I could see here is I might have to use other external tools like AutoIt or Sikuli etc to save it in the local disk. So in this case may be I might have to change my coding for that. And just to let you know there is no existing framework in our system. I'm creating the framework from the scratch with programming language as JAVA (but using Javascript to build dynamic HTML content). 

As of now, I've got couple of questions popping in my mind:

1. Can you Pls confirm that the approach for creating report and save it in the local drive is possible only by using other external tools . If so, can I have any material or link as a reference for the same?. But Pls remember that we have already decided to use Selenium web driver as our Automation tool. So in my case using Selenium web driver could you pls suggest me the best method of creating HTML & Excel report.

2. The other way of what i'm thinking now is, use Java & Javascript (but without using Selenium driver) to build the HTML report and save it in the local drive.

Pls let me know your thoughts on this

Cheers,
Barani

David Lai

unread,
Apr 29, 2013, 8:14:31 PM4/29/13
to seleniu...@googlegroups.com
If you're using Maven, you can easily convert the unit test results into readable reports just by adding a Surefire report task.


If  you need to create a custom report, it's still pretty easy to just create an static HTML file that opens the xml result file using a XSLT transform to display the test result.

http://stackoverflow.com/questions/1727616/custom-junit-report

Brad

unread,
Apr 29, 2013, 8:16:31 PM4/29/13
to seleniu...@googlegroups.com
Hi David Lai,

My aim is to create HTML & Excel report for the Test cases executed (displaying step level results).

But if creating a report in an XML report is feasible and beneficial, may be I can take it forward to my management. But if can you Pls let me know the highlights of this, that'll help me to decide.

Thanks,
Brad




On Tuesday, 30 April 2013 01:38:36 UTC+10, David Lai wrote:

Krishnan Mahadevan

unread,
Apr 29, 2013, 9:13:12 PM4/29/13
to seleniu...@googlegroups.com
Brad,
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/A7Q_6axi-SgJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

David Lai

unread,
Apr 29, 2013, 9:24:26 PM4/29/13
to seleniu...@googlegroups.com
XML is more flexible since it's not tied to the HTML.  You can create a Html/Java script /w and different XSLT style sheets for different views.  It can easily be parsed by other APIs if you want to consume the test result as part of an automated process.  For example, say you have a clean up script that reads the result files into a database or a test manager for a test coverage report.  Then you can feed it to an XML api and read the results like any dictionary object and not worry about having to parse and escape all the HTML stuff.

Brad

unread,
Apr 30, 2013, 1:20:24 AM4/30/13
to seleniu...@googlegroups.com
Hi Krishnan,

I had a look at the link provided below and it seems that link suggest to use Ant for JUnit report. But it seems that there is a bug (https://bugs.eclipse.org/bugs/show_bug.cgi?id=384757) associated with building a project using "Ant build" which is happening to me as well.

Here are my quick questions..

1. To customize the Junit report, I think we we need to build the Junit report right? 
   Kindly confirm if my understanding is correct. 
2. If I'm correct with my first question, then is there any other way to build Junit report without using Ant?
3. Can the customized Junit report be attributed to produce Test step results besides overll Test case status results

Kindly let me know your thoughts about this..

Thanks,
Brad



On Tuesday, 30 April 2013 11:13:12 UTC+10, Krishnan wrote:
Brad,
Please take a look here : http://stackoverflow.com/questions/1727616/custom-junit-report

On Tuesday, April 30, 2013, Brad wrote:
Hi David Lai,

My aim is to create HTML & Excel report for the Test cases executed (displaying step level results).

But if creating a report in an XML report is feasible and beneficial, may be I can take it forward to my management. But if can you Pls let me know the highlights of this, that'll help me to decide.

Thanks,
Brad




On Tuesday, 30 April 2013 01:38:36 UTC+10, David Lai wrote:
Feels kinda weird to me to build a report in the dom.  I think it might be easier to create a report in an XML object, then open it using an XLST template.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/A7Q_6axi-SgJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Krishnan Mahadevan

unread,
Apr 30, 2013, 1:22:57 AM4/30/13
to seleniu...@googlegroups.com
Brad,

Am more of a TestNG guy and my knowledge on JUnit is close to zilch :)

But if you were to move to TestNG, I can tell you that this is as simple as writing up your own reporting listener and then plugging it into your test suite. 
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/h_YeNROmaCQJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Brad

unread,
Apr 30, 2013, 1:23:34 AM4/30/13
to seleniu...@googlegroups.com
Hi David Lai,

I tried to explore the 2nd option since i'm not using Maven.. 

And the link suggest to use Ant for JUnit report. But it seems that there is a bug (https://bugs.eclipse.org/bugs/show_bug.cgi?id=384757) associated with building a project using "Ant build" which is happening to me as well. 

Kindly let me know how to proceed on this..

Thanks,
Brad

Barani

unread,
Apr 30, 2013, 1:57:22 AM4/30/13
to seleniu...@googlegroups.com
Hi Krishnan,

Just tell me this, is it possible to bring Test step results using TestNG. Pls confirm. If so, Pls provide me the reference link if you find any, so that i can look into it.

Thanks,
Brad


You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/hmT42DSh8HQ/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

David

unread,
Apr 30, 2013, 4:54:02 PM4/30/13
to seleniu...@googlegroups.com
Brad,

As others suggested, probably good to use the reporting facilities of existing frameworks like JUnit, TestNG, Maven, or to use XSLT and XML to transform the content to your desired output (HTML, etc.).

But as you've mentioned about building from scratch w/o any real framework, and using Java, if I was going with simplest approach this is what I'd do:

use Java's file I/O classes to write text to file, and instead of writing text, I'd simply write HTML. And instead of document.write() or any javascript calls (because we're creating HTML outside of a browser), we simply using file write/output methods. There is no need to involve javascript, you can do this all in Java alone. You'll only need javascript if your report HTML page somehow has dynamic features that render with javascript etc. But even in that case, you'd simply be writing javascript as text to a file.

If we were writing to the terminal/command prompt rather than file, then this would be an example:

System.out.println("<html><head>"); 
 System.out.println("<title>"); 
 System.out.println("Your report page HTML title here");
 System.out.println("</title></head><body>");  
 System.out.println("Print the Test values in html format. Your content goes here as multiple lines, etc."); 
 System.out.println("</body></html>"); 
//if above was written to a file output stream instead of system out, once you close the file stream, you now have the file saved to disk as filename you specified when opening the file output stream. open file in browser and you should see the HTML content.

I would not recommend use of Selenium and external tools (AutoIt, Sikuli) for this at all. Selenium should only be used for testing web apps or websites, no report generation at all.

On Monday, April 29, 2013 5:09:14 PM UTC-7, Brad wrote:

Brad

unread,
Apr 30, 2013, 11:42:04 PM4/30/13
to seleniu...@googlegroups.com
Hi David,

Yeah..I did what you have suggested using File I/O. It worked good.

Thank you..

Thanks everyone for your valuable inputs..much helpful..

Cheers,
Brad
Reply all
Reply to author
Forward
0 new messages