1

I am wondering if there is any feature that exists in Eclipse IDE to "debug from step " "step over", "step into" while executing selenium scripts. This feature is available in "QTP" & most of the proprietary functional automation tools. I am assuming this isn't possible with Selenium due to the reason that, the written code needs to be compiled to .class file but I may be wrong. Could you please help me know if there is any other alternative? I know Debugging is possible in eclipse by enabling Break Points however I'd need to execute the code from the beginning. This doesn't serve the purpose just as Debug from step in QTP. Thank you.

nandesh kalyankar
  • 302
  • 1
  • 5
  • 23

1 Answers1

0

Setup the breakpoint at the first line of code that will be executed by double clicking on the left side blue frame.... Click on Run menu and use option 'Debug As'. If you are using junit then use run as junit test.

Eclipse will stop at this line and bring up the debug view. Then you can step in, step over or step out to your hearts content.

Grasshopper
  • 8,908
  • 2
  • 17
  • 32
  • Thank you for taking some time to review my query.I am using TestNG framework to execute scripts. Doing what you have suggested needs a rework which I am trying to avoid. Let me explain my situation. 1.The scripts launches a Browser & performs some sort of actions, further more due to syntax error, it fails. 2.After rectifying the error, I want to continue resume from where I lastly stopped. I don't want to launch a new driver & repeat the actions.Is there any way this can be achieved? – nandesh kalyankar Aug 10 '16 at 11:03
  • For running debug with TestNG you just need to select 'Debug TestNG test' instead of junit option. If you have any Java syntax error eclipse wont compile and will not let you run the program. If you have xpath or css locator errors, that is a different thing. – Grasshopper Aug 10 '16 at 11:37
  • I agree with you. For some unknown reasons there are errors at runtime due to while the script is failing. All I'd like to understand is, Is there a way to resume from last run without having to redo. – nandesh kalyankar Aug 10 '16 at 11:47
  • But once an exception is thrown by selenium your driver session is over and you cannot go back. Though there is a way of running pieces of code or modify variables in debug mode which has access to variables and environment of your program. Make sure it is at a breakpoint. Maybe you can use this to verify locators etc. In debug mode at a breakpoint goto Window menu and select 'Show View', then choose the Display option, one with the J in the icon. Window opens up in which you can type your code and execute. Results are displayed in console. – Grasshopper Aug 10 '16 at 11:52
  • What are the runtime exceptions? Is it coming from your Java code or from Selenium unable to find something, some element not visible etc etc – Grasshopper Aug 10 '16 at 11:56
  • I am looking for something likely in eclipse IDE (https://www.youtube.com/watch?v=y0BbksxWMPw) – nandesh kalyankar Aug 10 '16 at 19:03
  • I did not know this but one can put an automatic breakpoint on any exception, throwable or error in eclipse. Refer to these 2 posts. --- http://stackoverflow.com/questions/3066199/break-when-exception-is-thrown and http://stackoverflow.com/questions/3453746/breakpoint-at-exception-in-eclipse-how-to-examine-exception-object. You might need to restart eclipse for it to work. When it code at exception breaks you can write code in the display window execute. Havent tried it myself but should work. – Grasshopper Aug 11 '16 at 05:54