Hey there! any question in your mind? Ask It Now!.

Popular Categories

Get console logs when selenium script is executed

0 votes
asked in Software Testing by RAMANDEEP SINGH

Hello All, Recently we logged a bug that on clicking an element for about 7 or 8 times HTTP 500 console error was observed intermittently. Now, dev's have fixed this issue and they want me to write a piece of automation code to test this. At my end, I tried using Log4j but it is creating lot of junk logs making it difficult to fetch console error from those. Have anyone of you ever encountered this issue. If yes, please help me in getting this resolved

1 Answer

0 votes
answered by tester (1,550 points)

Hi RAMANDEEP , When this 500 server error will come  you can catch this by your code like this.

 if (isPresent(driver.findElement(By.cssSelector("div#500.error"))))
        fail("500 page displayed! Failing a test, and quitting.");

Because whenever this error will come it will return a HTML which says 500 server error.

so you can catch this and maybe you can store in DB or just print in your logs.

And if 500 error is not getting printed on HTML so you can take help of 

JavascriptExecutor(import org.openqa.selenium.JavascriptExecutor) and get the header of the page which will return you the errors.

oXHR.open("GET", "http://edu.yoursfriends.com/", true);

oXHR.onreadystatechange = function (oEvent) {  
    if (oXHR.readyState === 4) {  
        if (oXHR.status === 200) {  
          console.log(oXHR.responseText)  // your can register logs here in your log file.
        } else {  
           console.log("Error", oXHR.statusText);  

// your can register logs here in your log file.


Please let me know if you did not get the point.

Related Questions

0 votes
1 answer 88 views
+2 votes
1 answer 2,549 views
+10 votes
2 answers 9,697 views
0 votes
1 answer 235 views
0 votes
1 answer 180 views
+2 votes
1 answer 216 views

Not a Member yet?

Ask to Folks Login

My Account
540 Folks are online
60 members and 480 guest online
Your feedback is highly appreciated