This directory contains example scripts and dependencies for running automated Selenium tests on Sauce Labs using Ruby. You can use these scripts to test your Sauce Labs authentication credentials, the setup of your automated testing environment, and try out Sauce Labs features, like cross-browser testing. Feel free to copy these files or clone the entire directory to your local environment to experiment with creating your own automated Selenium tests!
The code in these scripts is provided on an "AS-IS” basis without warranty of any kind, either express or implied, including without limitation any implied warranties of condition, uninterrupted use, merchantability, fitness for a particular purpose, or non-infringement. These scripts are provided for educational and demonstration purposes only, and should not be used in production. Issues regarding these scripts should be submitted through GitHub. These scripts are maintained by the Technical Services team at Sauce Labs.
These procedures will show you to set up a Selenium environment for NodeJS. The scripts in this repository allow you run a simple automated test to validate your Selenium environment and your saucelabs.com account credentials.
In order to complete these exercises you must complete the following prerequisite installation and configuration steps:
- Install Git
- Install
rbenv
andruby
- Install an IDE (RubyMine, RadRails etc.)
- Configure
Gemfile
- Setup Project
Git is a version control system that lets you check out code from a repository, work with that code on your own branch, and then merge that code with any changes that have been made by other developers. Git is an essential tool for distributed development teams, and is a critical component of the continuous integration/continuous development toolchain.
- Go to https://git-scm.com/downloads.
- Under Downloads, click Mac OS X.
- When the download completes, double-click the
.dmg
file open the installer package. - Double-click the installer package to begin the installation.
Security Warning
You may see a warning message that the package can't be opened because it's not from a recognized developer. If this happens, go to System Preferences > Security and Privacy Settings, and click Open Anyway.
- Click Continue for the installation, and enter your local password to authorize the installation.
- Go to https://git-scm.com/downloads
- Under Downloads, click on Windows.
- When the dialog opens asking if you want to allow the app to make changes to your device, click Yes.
- Follow the steps in the setup wizard to complete the installation. You should accept all the default settings.
For Unix/Linux systems we use rbenv. rbenv
is a tool that lets you install, run, and manage multiple versions of ruby
environments on your system.
-
Using
brew
installrbenv
:$ brew install rbenv
-
Setup
rbenv
in your currentbash
shell:$ rbenv init
-
Close and restart your terminal, or run the following command so changes take effect:
$ source ~/.bashrc
-
Verify that
rbenv
is configured correctly, and running on your system:$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash Checking for `rbenv' in PATH: /usr/local/bin/rbenv Checking for rbenv shims in PATH: OK Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20170523) Counting installed Ruby versions: none There aren't any Ruby versions installed under `~/.rbenv/versions'. You can install Ruby versions like so: rbenv install 2.2.4 Checking RubyGems settings: OK Auditing installed plugins: OK
-
Install a version of Ruby using
rbenv
, here are list of the available versions:$ rbenv install <ruby_version>
-
The
ruby
versions are generally stored in the following directory:~/.rbenv/versions
-
Under RubyInstallers, choose the latest version of Ruby+DevKit.
-
Download the package and extract it on you system.
-
Open the executable and follow the prompts to complete installation.
-
To upgrade Ruby, use
ridk install
command.This installer configures Ruby as a native Windows application, to learn more about RubyInstaller refer to the this link
It's recommended to install and Integrated Developer Environment, or a text editor, to help manage package dependencies, interperters, and overall code execution. There are several options available, some of them are free and some require payment:
- Aptana Studio free, IDE developed by GitHub. There are versions for MacOSX, Windows, and Linux.
- RubyMine free trial, paid after 30 days, developed by JetBrains.
- Komodo Edit, free, text editor, stripped down version of Komodo IDE (paid version).
- NetBeans free, open source IDE developed by Apache. Contains source binaries that you must download and compile.
-
Create a Project Directory:
- Create a directory on your filesystem to store the project files. You can create the directory using the IDE toolbar or the command line. Below is an example of using the command line to create your project directory:
$ mkdir ruby_tests
-
Setup
Gemfile
:- Install
bundler
so that we can easily update and resolve dependencies:
$ gem install bundler
- Create a
Gemfile
and enter the followinggems
:
$ bundle init
source 'https://rubygems.org' gem 'rspec' gem 'selenium-webdriver' gem 'sauce_whisk' gem 'rubocop'
- Install
-
Execute the
bundle
Command:-
Use the following to install the required
gems
:$ bundle install --path .bundle
-
-
Setup the
spec
Directory:-
Tests written in
RSpec
(the testing framework used in this example), are called "specs" (short for specifications). -
Create a
spec
directory where we will store our tests:$ mkdir spec
-
Create a
.rb
file calledinstant_sauce_rspec_test1.rb
, and copy and paste the contents from https://github.com/saucelabs-training/demo-ruby/blob/master/spec/instant_sauce_test1_spec.rb
-
-
Run the Test Script
-
In order to run the test on www.saucelabs.com, change the values of
SAUCE_USERNAME
andSAUCE_ACCESS_KEY
in the following url:https://SAUCE_USERNAME:SAUCE_ACCESS_KEY@ondemand.saucelabs.com:443/wd/hub'
To retrieve this information, login to your saucelabs.com account and navigate to User Settings; there it displays your username and access key.
-
Run the following command to have
rspec
search and executes 'specs' in your project directories:$ bundle exec rspec Finished in 0.00068 seconds (files took 0.30099 seconds to load) 0 examples, 0 failures
-
You may also use 'Run Configurations' in your IDE. For directions on how to setup Run/Debug Configurations refer to Documentation:
-