testnow
An instant WebDriver-Ruby-Cucumber or WebDriver-Ruby-RSpec framework which has ability to do cross browser testing on any of the popular browsers, Firefox, Chrome, Opera, Internet Explorer, Safari, Android Browser. It uses the selenium-webdriver to driver the browsers already installed on your box.
[NOTE] -- This gem does not provide any webdrivers or install any browsers, it is related to browser configuration and framework generation. For the tests to run, browsers should be installed and webdrivers should be present in the path variable.
Table of Contents
- Installation
- Install using gem command
- Install using bundler
- Setup
- Cross browser configuration using testnow for your existing project
- Command Line Tool -- testnow command
- Usage
- Instantly create a fresh Cucumber-WebDriver framework
- Instantly create a fresh RSpec-WebDriver framework
- Instantly create a fresh Watir-Cucumber-WebDriver framework
- Instantly create a fresh Watir-RSpec-WebDriver framework
- Variables
- BROWSER
- TEST_URL
- DEVICE
- Browsers
- Contributing
- Issues
Installation
There are multiple ways in which you can install and use testnow gem. You must have Ruby(>2.0) installed before you can install this gem.
Just use following command from you Terminal.
Usually installing testnow using gem command is always advised in cases of creating a new framework from scratch.
For existing framework, see next section (Install using bundler).
gem install testnow
You can include it in your Gemfile and run bundle install.
This is the preferred way to do it incase of adding testnow to an existing framework.
To create a new framework from scratch, there would be no Gemfile, then please install testnow using gem command (Previous section).
gem 'testnow'
then run following
bundle install
Setup
When creating a Selenium-WebDriver automation suite, if one requires cross browser testing, the biggest headache is configuring all browsers mainly because configurations for every browser is done differently. This is where TestNow gem jumps in as an Asprin to cure your headache by taking care of browser configurations for you.
Unlike some very famous Ruby-WebDriver tools which wraps up the WebDriver object and provides its own set of commands, TestNow gem returns you the driver
object as is but initialized with any browser of your choice.
In your existing automation suite, require and include the testnow gem in your config file (i.e usually env.rb for cucumber or spec_helper for rspec depending on your framework)
require 'testnow'
include TestNow # for basic webdriver framework
include TestNow::Watir # for watir webdriver framework
now as everything is required, included and ready, just put the following command in the setup method. (Setup method is where WebDriver is initialized with a certain browser and a driver object is created. i.e hooks.rb file for cucumber)
@driver = TestNow.init
TestNow gem uses the environment variable BROWSER to detect which browser to initialize. If no value is set for this variable then firefox will be initialized by default.
When you install testnow gem, it installs a command line tool which helps you to create automation frameworks with cross browser configuration in a jiffy.
This command line tool has multiple command and can be seen using help
Following are the list of commands:
Usage
testnow cucumber_now
This will run a series of commands and create a WebDriver-Ruby-Cucumber framework for you in a directory called cucumber_now. It will towards the end also ask you for gem dependency installation and it is highly recommended to say Yes. It will also create a sample scenario with a feature file and also a hooks and env file with all configurations. This scenario can be executed by simple command to see a demo of the execution.
cd cucumber_now # Navigate into the created directory
Command 1 : cucumber features # Executes using cucumber gem executable
or
Command 2 : rake testnow # Executes using cucumber rake task
Use any of the command to execute the sample scenario. A beautiful, screenshot embedded report will be created by this execution to in the reports directory. It will be in html format, please double click or open in a browser to view it.
testnow rspec_now
This will run a series of commands and create a WebDriver-Ruby-RSpec framework for you in a directory called rspec_now. It will towards the end also ask you for gem dependency installation and it is highly recommended to say Yes. It will also create a sample scenario with a spec and spec_helper file with all configuration. This scenario can be executed by simple command to see a live demo of the execution.
cd rspec_now # Navigate into the created directory
rake testnow # Executes using cucumber rake task
Use any of the command to execute the sample spec. A beautiful report will be created by this execution to in the reports directory. It will be in html format, please double click or open in a browser to view it.
testnow watir_cucumber_now
This will run a series of commands and create a WebDriver-Ruby-Cucumber framework for you in a directory called watir_cucumber_now. It will towards the end also ask you for gem dependency installation and it is highly recommended to say Yes. It will also create a sample scenario with a feature file and also a hooks and env file with all configurations. This scenario can be executed by simple command to see a demo of the execution.
cd watir_cucumber_now # Navigate into the created directory
Command 1 : cucumber features # Executes using cucumber gem executable
or
Command 2 : rake testnow # Executes using cucumber rake task
Use any of the command to execute the sample scenario. A beautiful, screenshot embedded report will be created by this execution to in the reports directory. It will be in html format, please double click or open in a browser to view it.
testnow rspec_now
This will run a series of commands and create a WebDriver-Ruby-RSpec framework for you in a directory called watir_rspec_now. It will towards the end also ask you for gem dependency installation and it is highly recommended to say Yes. It will also create a sample scenario with a spec and spec_helper file with all configuration. This scenario can be executed by simple command to see a live demo of the execution.
cd watir_rspec_now # Navigate into the created directory
rake testnow # Executes using cucumber rake task
Use any of the command to execute the sample spec. A beautiful report will be created by this execution to in the reports directory. It will be in html format, please double click or open in a browser to view it.
Variables
Using testnow for existing project or creating a fresh framework from the testnow command line tool, there an environment variable which is consumed by the execution which is called BROWSER. One can pass the browser of its choice to this variable to execute tests in different browsers. The default value is set to firefox.
For example, in above sample scenario.
rake testnow BROWSER=chrome
or
rake testnow BROWSER=opera
[NOTE: This will work provided you have webdrivers placed in PATH varibale. i.e chromedriver or operadriver]
This variable currently only works if you create a framework from testnow command line tool. This variable is called TEST_URL and it gives you the power to pass the test url as a parameter. As we know that there can be multiple test environment and not necessarily we would need to run our tests on 1 environment. So to avaoid changing the code, testnow provides exposure of test url.
For Example:
rake testnow BROWSER=chrome TEST_URL=https://github.com
This variable is only required when using Chrome Mobile emulation browser. This is a feature by Google Chrome provided for testing mobile websites how it will look on chrome browser on various devices. For eg: Google Chrome on Apple iPhone 6 Plus or Google Chrome on Samsung Galaxy Note 3. The list of devices can be found on here. Now coming back to how to use this variable. We need to pass the DEVICE name when choosing BROWSER=mobilechrome.
For example
rake testnow BROWSER=mobile_chrome DEVICE="Apple iPhone 6"
or
rake testnow BROWSER=chrome_mobile DEVICE="Samsung Galaxy Note 3"
or
rake testnow BROWSER="Mobile Chrome" DEVICE=Google_Nexus_6
Note: If certain devices are not found on your chrome then firstly update your chrome to latest version and then turn on the devices and device mode from developer tools options
Browsers
As mentioned in the above section that there is a variable exposed called BROWSER but what are the values to be passed and which OS-Browsers combinations are supported, well here is a index grid below:
👇 Browsers ↔️ OS 👉 | Linux | Mac | Windows |
---|---|---|---|
Google Chrome | Supported | Supported | Supported |
Mozilla Firefox(v47-) | Supported | Supported | Supported |
Mozilla Firefox Gecko(v48+) | Supported | Supported | Supported |
Internet Explorer 10/11 | N/A | N/A | Supported |
Microsoft Edge | N/A | N/A | Supported[3] |
Opera | Supported[1] | Supported[1] | Coming Soon!! |
PhantomJS | Supported | Supported | Supported |
Chrome Mobile Emulation[2] | Supported | Supported | Supported |
Chrome on Android Phones/Emulators[4] | Supported | Supported | Supported |
Note:
[1] Currently it is expected that the Opera webdriver binary is present inside "/usr/local/bin/operadriver, soon this path will be made customizable and exposaed as a varibale.
[2] This is not another browser, it is the mobile emulation which Google Chrome proovides through its developer tools.
[3] Please download the required Microsoft WebDriver as per your windows 10 build number. Windows 10 build can be checked with the winver
command.
[4] In this case, there should be an android phone/emulator with google chrome installed connected to system via adb.
Contributing
Ideas and suggestions are always always most welcome. Please fork this gem code and feel free to add any updates, suggestions etc and create a pull request.
Issues
If you face any problem related to syntax, usability, documentation then please raise an issues, testnow is committed to respond within 24hours...