Selenium WebDriver- Debugging Code (Breakpoints) - Java Debugging with Eclipse

12:55 AM 28 Comments









Most of us interested to know, how the code is getting executed. Some times, even if we write the code with out having any syntax errors also during execution we face issues which requires debugging of the code.
As Web-driver script executes fast, if we want to execute the Web-driver  code line-by-line and verify the Output can be achieved using the Debug Mode in Eclipse.
Lets start. I have written a very simple example in Selenium Webdriver to retrieve the text in Facebook as highlighted in the below image.









Facebook.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Facebook {

public static void main(String[] args) {

WebDriver driver = new FirefoxDriver();
driver.get("https://www.Facebook.com");
String actual = driver.findElement(By.xpath("//span[text()=' See photos and updates ']")).getText();
System.out.println(actual);
String expected = " See photos and updates";

if(actual.equals(expected))
{
System.out.println("Actual is equal to Expected TC - Pass");

}
else
System.out.println("Actual is not equal to Expected TC - Fail");
}

}
There are no syntax errors in the code. Please try to execute the code as shown below:








Output:
Actual is not equal to Expected TC - Fail
In the above scenario the TC should pass. But we are getting response as TC-Fail.
So, how do we identify the issue. What is the reason for failure.
We have to use Debug mode to identify the root-cause for this issue.
Debug - Step1- Insert BreakPoint
Right-click at the line number 10 and select the first option - 'Toggle Breakpoint'. It means we are inserting the Breakpoint, so we can verify the values in the variable at run time.
In our case we can verify the value stored in the 'actual'.










Step2-Run Facebook.java in Debug mode










Step3- Debug Perspective opens as shown below
Select the checkbox-'Remember by decision' and click on 'Yes' button.









The Debug perspective opens, it has three tabs Variables,Breakpoints,Expressions.








Out of three tabs- Expressions tab is required to view the values at run-time.In Debug perspective if you are unable to identify this tab. You to follow the steps as show below:






Navigate to Expression tab and click on 'Add new expression' enter 'actual' as shown below:









Click on Step-Over to move to next step. Verify the 'actual' value in the Expression tab.Also add few more expressions as shown below:
Actual String length-> actual.length()
Expected String length()->expected.length()








Click on Step-Over to move to next step. Verify all the values as shown below:







Conclusion
The length of expected String is 23.
The length of actual String is 22. 
So there is an issue in expected string. In the program we provided the String expected =" See photos and updates";
There is an unnecessary space added in the string. It should be changed to String expected ="See photos and updates";
by removing the unwanted spaces.
Once identify the issue click on terminate button as shown below.







Change the Perspective from Debug Mode to Java Mode.







Remove all the breakpoints.

Unknown

This site creates a platform to become an expert by gaining knowledge of unknown real-time issues as well.

28 comments:

Anonymous said...

This blog will get more thoughts. This is exceptionally useful for Software Testing students. Much thanks to you for sharing this great site.
Selenium Training | Selenium Classes in Chennai | Best Selenium Training in Chennai| Selenium Testing Training in Chennai

sai said...

Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this
python training in tambaram
python training in annanagar
python training in velachery

Unknown said...

All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
Blueprism training in marathahalli

Blueprism training in btm

Unknown said...

I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.

Data Science training in Chennai
Data science training in bangalore
Data science online training
Data science training in pune

Unknown said...

Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
java training in omr | oracle training in chennai

java training in annanagar | java training in chennai

Madhu Bala said...
Anjali Siva said...
Vicky Ram said...

Thank you for sharing this post.

Guest posting sites
Technology

I’m bookmarking and will be tweeting this to my followers! Wonderful blog and amazing design and style.
nebosh course in chennai

Aruna Ram said...
sathyaramesh said...

I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
RPA courses in Chennai
Robotic Process Automation Training
RPA course
Robotic Process Automation Courses
learn Robotic Process Automation
RPA Training Course

jvimala said...

Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.
fire and safety course in chennai

karthick said...

its a good post and keep posting good article.its very interesting to read.
Data Science Training in Chennai

priya said...

Awesome..You have clearly explained …Its very useful for me to know about new things..Keep on blogging..
Microsoft Azure online training
Selenium online training
Java online training
Java Script online training
Share Point online training

priya said...

https://opencvexamples.blogspot.com/p/learning-opencv-functions-step-by-step.html?showComment=1535611313888
Microsoft Azure online training
Selenium online training
Java online training
Java Script online training
Share Point online training

LindaJasmine said...
merlin said...

Nice blog,I understood the topic very clearly,And want to study more like this.Thanks for this blog, I'am very much delighted to say that this blog has helped me a lot in gain some extra knowledge.
Selenium Training in chennai | Selenium Training in anna nagar | Selenium Training in omr | Selenium Training in porur | Selenium Training in tambaram | Selenium Training in velachery

nisha said...
vivekvedha said...
sushmi reddy said...
vivekvedha said...
Revathi said...
Maneesha said...

I think this is a standout amongst the most critical data for me. What"s more, i"m happy perusing your article. Be that as it may, ought to comment on some broad things
data scientist course in hyderabad

Nice blog, thank for sharing with us.
Data Science Course with Placements in Hyderabad

Anonymous said...

This blog, in my opinion, is among the best because it has been quite beneficial to me. I appreciate you sharing this useful information.

IELTS Coaching in Ahmedabad