This document is written with the expectation that it will be a developer, and instructions are given from the perspective of a Mac OS. On other operating systems there is potential for things to vary when executing.
For this test suite I've added a few gems that I take advantage of when manipulating the browser, and making sure it acts as expected when running through the tests. Below I will outline key functions commonly used that will assist in further development of this test suite. At the end of this test suite I will also include documentation and commands if you needed to setup a test suite from scratch in use for other projects. The sites I have listed are good references if you are having trouble making a selection or manipulating the Web App/Page.
Capybara Cheat Sheet: (https://devhints.io/capybara, http://cheatrags.com/capybara)
-
click_link("ID, Name, Class, Title etc…")
-
click_button("ID, Name, Class, Title etc…")
-
page.find, _link, _by_id, _field, _button
-
visit '/'
-
check(" "), uncheck(" ") #used for checkboxes
Rspec Cheat Sheet: (http://cheatrags.com/rspec-matchers)
-
.to include (works for arrays and strings)
-
.to be true, _nil, _falsey, _truthy
-
.to start_with(' ')
-
expect(page)
Faker Cheat Sheet: (https://devhints.io/ffaker,https://gist.github.com/mikekovacevic/8919216)
-
Faker::Internet.email, .safe_email, .user_name
-
Faker::Lorem.paragraph, .paragraphs, .sentence, .sentences
-
Faker::Name.first_name, .last_name, .name
-
Faker::PhoneNumber.phone_number
For running this you will need to pull the Repo where you can access it from a command window. You will need to have Ruby either globally installed on your machine, or inside the directory once you've pulled the Repo down. The link for Ruby is here.
Another tool that you should have is Bundler. To install bundler go into the directory for the project in a command window and type: gem install bundler. After installing bundler run. Bundle install inside that same command window.
If starting a new project you would open a command window then change into the directory of that project and then can run the following commands to setup the outline.
- rails new
- rails generate rspec:init (This makes a spec_helper file instead of the rails_helper. If you are building this test suite inside a project you would use 'install' instead of 'init')
- bundle install (Run this every time you would make changes to your gemfile)
Next you need to require gems inside of your spec_helper. For the project presented I used Capybara, Faker, Rspec, Selenium-Webdriver, Capybara-screenshot, and Chromedriver-helper. You should require the necessary to run before the tests above the "RSpec.configure do |config|" portion inside of spec_helper.
Once everything is installed and you've moved into the directory of the project you will need to setup Selenium-Webdriver for chrome. To do this simply type chromedriver-helper inside the command window. This will install the chrome driver for Selenium-Webdriver, and also start the instance that you will use to host the server instance.
To run the test suite open a new command window into the directory of the project then run: bundle exec rspec. If you want to be selective of which spec file you run, you can run bundle exec rspec full_path_and_file_name.
Below is a breakdown of the different sections of the website that the framework tests. The tests run on Selenium webdriver for visibility. Ideally for future development tests would be run using a headless browser like the deprecated PhantomJS or HeadlessChrome. Failures are currently captured with screenshots saved directly into your directory. In these tests I use Capybara/Rspec because it gives me the flexibility of using gems to aide in E2E tests as well as when built into the project is easily configured for integration tests.
- Global fields
- Menu Content
- Sign in link
- Creating a new user
- Email Validation
- Form input
- New User sign in
- Home page
- Landing page
- Page Slider options w/ confirmed redirect
- Sign in
- Existing User
For continuing the test suite development. You would create it blocks either inside of one of the currently created .rb files or you would create a .rb file. It is important to note that "_spec" needs to be at the end of your file name. After creating either your new .rb file or setting up an it block inside of one that is currently created you can begin to start making selections on the Web page/app. The tests that are currently developed should pose as a good outline for selecting different components throughout the app.
If you create your own .rb file it is important to wrap your it blocks inside of a feature block, and include the require spec_helper above. Also an important note the before :each block should be included for statements you need to run at the beginning of every test. In the example I have it using visit "http://automationpractice.com/". Using the cheat sheets listed above will also help you find a wider variety of selectors and expect statements that can be used to increase coverage. It is important to include js: inside of your it blocks for Capybara to work properly.
When looking for the names of ID's, Title's, Class's etc.. you can use the "Inspect" option when right clicking on the section you are looking to select.