On 1 June 2012 02:46, Chuck van der Linden <[email protected]> wrote: > > > On Wednesday, May 30, 2012 10:46:31 PM UTC-7, gajendra wrote: >> >> Hi All, >> >> Is there any way, we can debug the WATIR scripts step by step? >> > > As mentioned some IDE's like Rubymine provide debuggers.. useful I think > for more complicated programs. > > for most watir scripts I just use IRB. you can cut and past from your > script (to read in static variables etc) and if you try something in IRB > and it does what you need it's easy to cut and past it to your scripts. > > Often I will just open an irb session, get a browser session going, then > manually navigate the browser to where I need to be. Once there I can try > things in IRB using methods like .flash to see if I am properly identifying > an element, before attempting to read values or manipulate it in some way.. > I find this a very easy and effective way to develop scripts. Typically > I'll use two cmd sessions, one with irb going, and the other to be able to > invoke cucumber using a tag to execute the test case I'm working on > automating. If I'm working with something that uses a lot of session > cookies, I'll do something like have the IRB session controlling a chrome > browser, and cucumber setup to use firefox or IE. > >> >> I use pry and pry-nav instead of IRB. I find it to have all the power of IRB and a lot more, without added complexity.
Just install the gem pry-nav and insert these lines right where you want to put a breakpoint: require 'pry-nav' binding.pry When you run the script, those lines will drop you in a pry session in the exact context where the script was running. You can check variables, run commands, even alter your code ad hoc if you want to try something. pry-nav gives you three commands: continue, next and step. They do what you would expect from such commands in a debugger. cassiano -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. [email protected] http://groups.google.com/group/watir-general [email protected]
