Let's say we're debugging something, and we want to actually see what's happening in the browser.
In our advanced topics folder of TAU Capybara, let's go into the Chrome Logging folder and run a test.
The Chrome browser opened up. It went to the homepage and then checked the title, subtitle, current URL, et cetera.
What if a human being wasn't looking at the test? Would we really need to have the browser open up or could we just have the test run and checking which pass, and which fail?
Running the test that way, without the browser user interface is called a headless test.
Capybara has a method that's built in, that allows you to do that. With the Capybara
default_driver property, let's change it from Selenium Chrome to Selenium Chrome Headless.
# Capybara.default_driver = :selenium_chrome Capybara.default_driver = :selenium_chrome_headless
Now when we run our test again, all the test scenarios are executed without the browser actually opening up.
As you can see, this finished in 3.04 seconds, while with the browser-based test, it took 4.56 seconds.
:::tip Speed Matters with Testing If you're running hundreds of tests, these seconds matter. With the larger automation suites, you need to have the tests be as fast as possible. :::
The next trick we are going to look at it with Chrome is logging.
Here we have our
We're going to add to our configuration of RSpec.
What we're doing is configuring RSpec tests to run in Capybara with certain options and browser capabilities.
Before the test is run, we're going to register a driver, set up the options to be Chrome, and we're going to add the argument for window size.
We're going to be setting up capabilities for Chrome in order to get information from the logs.
For the Chrome Logging project, we created a folder called “logs”.
After the test run, we're going to collect all the browser logs and put it in a variable called “browser_errors”, and we're going to collect all the driver logs, put it in a variable called “driver_errors”, and we're going to open a log file and shove both the browser errors into a file called
logs/chrome.log and all the driver errors in
Let's run the test again.
Under “logs”, we can see that there's 2 new files: chromedriver.log, which is empty, and chrome.log, which came up with a message with a level of severe.
According to this message, it seems that the-internet is supposed to have a favorite icon.
Something that shows when it's favorited in your browser, but this resource failed to load. Responded with a 404 error. I want you to really tell Dave Haeffner this.
In the next section, we will review a new browser that team Capybara has been writing called Apparition.
:::tip Quiz The quiz for this chapter can be found in section 7.4 :::