T.J. Maher's first attempt using Gauge.org + Selenium-Ruby, ripping off code from Gauge's example project, ruby-selenium so he can attempt to understand this BDD framework he is encountering for the first time.
T.J. Maher knows how to write Base Page Objects, Page Objects, making tests data driven, and how to add good exception handling and logging in Java, but not in Ruby. Do you know that? Maybe you can help answer a few questions.
This project focuses on understanding the Gauge framework, not selenium-ruby. Both the Ruby code and the Selenium formatting are left as minimalist and unstructured as possible, hacked together quickly to get it up and running.
Running this example
The tests are run on Headless Chrome by default.
This example requires the following softwares to run.
The System Under Test (SUT)
- We are testing against Dave Haefner's The-Internet Login page at https://the-internet.herokuapp.com/login.
Go into the gauge-selenium-ruby-first-draft and make sure you have all the dependencies. Run:
You can execute specs as
bundle exec gauge specs
Gauge specs are run with Maven.
Chrome is the default browser for specs execution. Make sure Chrome is installed in your machine and chromedriver is in PATH.
How is this project scaffolded?
What is wonderful about Gauge is that I did not have to use Yeoman.io or any other tool to scaffold this project, i.e. figure out the folder structure and code just to get things up and running. I created a new directory on my local machine, entered the directory, and entered:
gauge init ruby
Want to see what code that command produced? See the gauge_0.9.7_default_code that I stored on GitHub.
I'm only week two into working with Ruby.
Questions: Are you an expert on Gauge?
How do you work with selenium-ruby?
I was planning on working towards what Dave Haeffner has in ElementalSelenium.com creating a library of:
- Using Base Page Objects to wrap Selenium Ruby calls with proper waits.
- Using Page Objects, so that when locators inevitably change, I know where exactly to fix them.
- Making the tests data-driven
- Adding Rescue exceptions to avoid weeding through Stack traces.
- Maybe JQuery Growl for better logging, and Wrapped Selenium Tests
I am brand-new to Gauge and using Selenium-Ruby. So far I only have used Selenium-Java.
It looks like Gauge strongly advocates against page objects calling them an Anti-Pattern. Er... Um... burying a page's locators in code, as they do in the blog makes me worried. Looking for other solutions.
- default properties: Points to where the reports and logs are, chooses Chrome to be the default browser, and chooses whether or not you should overwrite reports, capture screenshots on failure, enable multithreading. You can also choose when you want the objects to be cleatred... after execution of suite, spec, or scenario.
- user properties: Points to the APP_URL, and chooses if you want the tests to be headless or not.
- UserAction.spec: Heavily ripped off of the Gauge sample project, ruby-selenium, this is the "executable specification file. This file follows markdown syntax. Every heading in this file denotes a scenario. Every bulleted point denotes a step". Contains "Login as username and ", "Check if the user is logged in" and "Log out". Also contains a data table for username and passwords.
- concepts/Authentication.cpt: Specs can refer to these concepts, "Check if the user is logged in" and "Log out", breaking them down.
- authentication.rb: Contains the selenium-ruby code that acts out the steps "Give an option to Log Out", 'Give an option to Log In' and a logout method.
- user_login: Contains the step "Login as username and ", which uses selenium-ruby to send text to the username and password textbox, and presses the Login button.
- driver.rb: Contains the setup and teardown methods, creating the driver and quitting the driver. Also sets up the driver with:
options = Selenium::WebDriver::Chrome::Options.new @@driver = Selenium::WebDriver.for :chrome, options: options options.add_argument('--headless') options.add_argument('--disable-gpu')
find_message: Any messages that you need to check for? There is this method that Gauge's ruby-selenium has, "Show a message ".
screengrabber.rb: Provides a wrapper for
site_launcher: Contains the step "Navigate to the login page", which then does:
assert_equal 'The Internet', driver.title