Understanding Debugging
Lets start by understanding debugging.
But before this, let’s have a look at Capybara. So, Capybara provides developers to simulate a user on a web page as well as make assertions based on the content and environment of the page. It also offers an API to interact with the web page. Also, let’s check out DSL.
DSL
DSL stands for Digital Subscriber Line. Moreover, users get a high-speed bandwidth connection from a phone wall jack on an existing telephone network. Not to mention, it also works within the frequencies that the telephone doesn’t so you can use the Internet while making phone calls. Nonetheless, DSL utilizes telephone wires, which makes sense that the biggest providers are telephone companies.
Now, let’s understand this section. It can be useful to take a snapshot of the page as it currently is and take a look at it:
save_and_open_page
You can also retrieve the current state of the DOM as a string using page.html.
print page.html
This is mostly useful for debugging. You should avoid testing against the contents of page.html and use the more expressive finder methods instead.
Finally, in drivers that support it, you can save a screenshot:
page.save_screenshot(‘screenshot.png’)
Or have it save and automatically open:
save_and_open_screenshot
The Capybara debugging methods can be summarized as
save_and_open_page # saves current snapshot of page
print page.html # retrieve current state of DOM
save_sceenshot(‘screenshot.png’) # save screenshot
There is another method, which is more useful for debugging: the pry and pry-debugger gems. These gems will let you inspect script execution in an actual debugger, allowing you to set breakpoints, go next, step into, continue, etc. To use them, do the following:
gem install pry-debugger (automatically installs pry as well)
require ‘pry’ in your test script or spec helper
add binding.pry to the script to set a breakpoint and then, execute the test script. Execution will pause on the breakpoint. At this point, use next (to go to next line), step (to step into definition), continue (to continue execution) to debug as necessary.
For more info about these gems check:
* Pry
* Pry-debugger
Make your resume stand out and become a Certified Capybara Testing Professional. So, Try free practice tests here!
A great career is just a certification away. So, practice and validate your skills to become Certified Capybara Testing Professional