Want to view JavaScript errors in Chrome? Or see if your Selenium WebDriver instance is throwing any errors? Check out the Logging Preference Capabilities from the Chromium project.
With this article, we will demonstrate how to get these logs set up in your Capybara-Ruby project, and what to add in the spec_helper.rb file we created.
What is Chromium?
"Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all Internet users to experience the web. This site contains design documents, architecture overviews, testing information, and more to help you learn to build and work with the Chromium source code".
What are Capabilities?
From Capabilities and Chrome Options, on the Chromium.org website:"Capabilities are options that you can use to customize and configure a ChromeDriver session. This page documents all ChromeDriver supported capabilities and how to use them.
"The WebDriver language APIs provides ways to pass capabilities to ChromeDriver. The exact mechanism differs by the language, but most languages use one or both of the following mechanisms:
"Use the ChromeOptions class. This is supported by Java, Python, etc.
- "Use the DesiredCapabilities class. This is supported by Python, Ruby, etc. While it is also available in Java, its usage in Java is deprecated.
- "Using the ChromeOptions class
Set Log Levels in Ruby Properties
For logs, we can choose from six different levels of logging:
- "OFF"
- "SEVERE"
- "WARNING"
- "INFO"
- "CONFIG"
- "FINE"
- "FINER"
- "FINEST"
- "ALL"
env/default/ruby.properties:
CHROME_LOGGING = WARNING
CHROMEDRIVER_LOGGING = SEVERE
... If there is event the slightest thing wrong displaying in the Chrome browser while my app is running, I want to know, Warnings and all!
... If there is anything with WebDriver, I only want to know the problems tagged with Severe.
Add Capabilities
Creating Capabilities and adding them to the browser in Ruby is easy (once you know how).
Instead of hardcoding the logging preferences for the browser or the webdriver, I will use what I have declared in my Ruby properties.
spec_helper.rb
CAPABILITIES = Selenium::WebDriver::Remote::Capabilities.chrome(
loggingPrefs: {
browser: ENV['CHROME_LOGGING'], # Capture JavaScript errors
driver: ENV['CHROMEDRIVER_LOGGING'] # Capture WebDriver errors
}
)
before_suite do
Capybara.register_driver(:chrome) do |app|
...
...
Capybara::Selenium::Driver.new(app, browser: :chrome,
desired_capabilities: CAPABILITIES,
options: options)
end
... What is before_suite? Gauge has before_suite and after_suite as an execution hook: https://docs.gauge.org/language.html#execution-hooks
These commands will set up the logging level for every instance of Chrome that you spin up, headless or otherwise.
If there are any JavaScript errors displaying in Chrome, or any problems in ChromeDriver, you can take a look at the logs to diagnose what is wrong.
But what do you do with the information afterwards?
Save The Logs!
After the test suite has run, we can take the browser and driver logs, put that in variables called browser_errors and driver_errors, then create and open two files, chrome.log and chromedriver.log, saving the data to the logs directory.Here is what I hacked together:
after_suite do
browser_errors = page.driver.browser.manage.logs.get(:browser)
driver_errors = page.driver.browser.manage.logs.get(:driver)
open('logs/chrome.log', 'w') do |f|
f << browser_errors
end
open('logs/chromedriver.log', 'w') do |f|
f << driver_errors
end
end
Run Tests, Examine Logs
Let's run our test suite again, and see what we find:- bundle exec gauge run specs -v
- It's blank. Hooray!
- Take a look at the chromedriver.log produced on my GitHub site.
- View chrome.log on my GitHub site
... Hrm... It looks like the Favorite icon, the icon that shows up when you Favorite or Bookmark a page, is missing. Someone should tell Dave Haeffner, the person who created The-Internet.
Last, but not least, we will be adding to our project the code review tool, Rubocop.
Happy Testing!
Basic Capybara-Gauge:
- Part One: Analyzing The-Internet
- Part Two: Setup Ruby Environment
- Part Three: Setup Capybara to Test Opening Chrome
- Part Four: Add Option For Chrome Headless
- Part Five: Add Test Steps and Spec Implementations
- Part Six: Setup Chrome and ChromeDriver Logging
- Part Seven: Rubocop Code Review
- Source Code: https://github.com/tjmaher/capybara-gauge
-T.J. Maher
Sr. QA Engineer, Software Engineer in Test
Meetup Organizer, Ministry of Testing - Boston
Twitter | YouTube | LinkedIn | Articles
22 comments:
Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.
Project Management Apps
I really appreciate you for providing such informative posts which I can firmly use for the PhD dissertation proposal help UK, most students will be able to take this for guidance.
Well, I heard about chromium for the first time through this post. Earlier I only know about chrome. After completing my academic projects using coursework writing services, I will try this logging method.
It was an amazing purchase, quick delivery & got my item in time yumove discount code So happy with the product.
Looking to Buy Argumentative Essay turnout to Master Essay Writers for all essay services at an affordable price.
The track down all relevant info and agreements on the site difference between llp and ltd.
These automotive features have made our lives so easy or I would say that every technical invention has brought quite a relief to us. One such technical invention which has benefited me a lot is the ability to buy the Best Assignment Writing Help through online platforms. I thank the innovator of this invention.
It is great to see this amazing article. I am glad to read this article and get amazing stuff from this. thesis writing help
Namaz is the essential part of a Muslim's life and it is important to keep track of the prayer times in Lucknow. The Namaz Time in Lucknow begins with the Fajr prayer at 4:43 am, followed by the Dhuhr prayer at 12:17 pm, the Asr prayer at 3:48 pm, the Maghrib prayer at 6:24 pm and the Isha prayer at 8:03 pm. It is important to note that the times may vary slightly according to the season and weather changes. It is also important to follow the local rules and regulations when performing your namaz. May Allah grant us the strength and resources to perform our namaz regularly and with sincerity.
Thanks for sharing this post.
Get expert help with Management Case Studies. Seek the best Management Case Study Help at a budget-friendly price. Assignmenttask.com provides you with 100% plagiarism free content. Our professional writers deliver assignment papers on time. We provide services such as, free Management assignment samples, editing & proofreading etc. To know more, visit us!
Nice post
Malaysiatranslators.com provides professional divorce certificate translation services in Malaysia. Whether you need to translate your divorce certificate from Malay to English or from any other language, the translators can accurately translate your document and ensure it meets the legal requirements of the Malaysian authorities.
I enjoy all of your posts. You did some excellent stuff. I appreciate the information you offer; it was quite helpful. I anticipate receiving several more entries from you. Blog is quite fascinating. If you're looking for Customized ERP Software then please visit customer relationship management in erp
Awesome blog
Seeking professional dissertation Writer Greece? Look no further than GreeceAssignmentHelp.com. Our skilled writers provide custom dissertation writing help in Greece, delivering impeccable results. Avail yourself of our dissertation proofreading and editing services Greece for a flawless research document.
Juvenile Reckless Driving Virginia Reckless driving virginia is a serious offense.
Integrating Chrome and ChromeDriver logging capabilities into the fundamental Capybara-Gauge system is a strategic move towards enhancing the debugging and monitoring aspects of web automation. This addition empowers developers to delve deeper into the intricacies of their test environments, providing valuable insights through detailed logs. By incorporating Chrome and ChromeDriver logging, developers gain a comprehensive view of the test execution process, enabling more efficient troubleshooting and optimization. This robust feature exemplifies the commitment to refining the Capybara-Gauge experience, ensuring that developers can navigate the complexities of web automation with precision and ease.
I have read your blog and also seen video on youtube. Its amazing I really like it very much. Please share more this type videos with us.
Abogado de DUI Fairfax VA
Looking for a NJ Indian divorce attorney? Speak with [Lawyer's Name] for committed legal assistance. [Lawyer's Name] has experience in Indian family law and can help you with the procedure. Speak on [Phone Number].
Indian Divorce Lawyer NJ
Protective orders in Virginia can be issued for a maximum of two years. On the other hand, they may be extended for an additional year in situations involving abuse within the family. If a protection order is broken, criminal proceedings may follow.
how long does a protective order last in virginia
Adding Chrome and ChromeDriver logging to Capybara-Gauge sounds like a smart upgrade for better tracking. Just like in writing a law research paper, having detailed logs helps identify issues and improves the quality of your work. It's great to see how logging tools can enhance both technical and academic projects.
Las reiteraciones pueden conllevar sanciones más severas y perjudicar los seguros. Es esencial acudir a un letrado para comprender las alternativas legales y reducir las repercusiones.
Conducir Sin Licencia Nueva Jersey
Integrating Chrome and ChromeDriver logging capabilities into your Capybara-Gauge framework is a game-changer for developers focused on enhancing their web automation testing. hp server distributor in dubai
Law Assignment help provides high-quality legal solutions, ensuring plagiarism-free assignments that enhance academic understanding and results.
Post a Comment