February 12, 2018

Are You a Gauge Expert? How Do You Graft On a Fluent Selenium-Ruby Framework?

Are you an expert in Gauge, the BDD framework? ( See a Brief Overview of Gauge ).

I have a question: How do you work with selenium-ruby?

I was planning on working towards what Dave Haeffner has in ElementalSelenium.com creating a library of:
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. I am looking for other solutions.
To figure out this new automation framework we are using at my workplace, I ripped off code from Gauge's example project, ruby-selenium, and tried to get it to point to Dave Haeffner's site, The-Internet, so I could better attempt to understand this BDD framework I am encountering for the first time.

I created a little project that I called: gauge-selenium-ruby-first-draft. (View it on GitHub!). It contains:

env/default:

  • 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.
specs
  • 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.
step_implementations
  • 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.
step_implementation_utils
  • 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 driver.save_screenshot('/tmp/screenshot.png')
  • site_launcher: Contains the step "Navigate to the login page", which then does:
  assert_equal 'The Internet', driver.title
Examine the code I hacked together at https://github.com/tjmaher/gauge-selenium-ruby-first-draft, based on the ruby-selenium sample project.

Happy Testing!
-T.J. Maher
Sr. QA Engineer, Software Engineer in Test
Meetup Organizer, Ministry of Testing - Boston

Twitter | YouTubeLinkedIn | Articles
Post a Comment