Step by Step automation guide – Selenium using Ruby Mini-Test framework

Setup Automation using Selenium/Ruby Mini-Test in 10 minutes (step by step) The assumption is that you are using a MAC…. (sorry PC users)

      1. Download a webdriver (in this case, I am getting a chrome driver: https://sites.google.com/a/chromium.org/chromedriver/downloads . Make sure you set the PATH which you where your webdriver was install to.
      2. get rvm (which is to set your ruby version, and get different gems (ruby libraries) https://rvm.io/rvm/install
      3. install the following gem libraries:
        1. gem install minitest (Mini Test framework for all the assert)
        2. gem install selenium-webdriver (this is pretty obvious)
      4. Now create a test_login_file.rb like the following code, then run: ruby test_login_file.rb
    require "minitest/autorun"
    require "selenium-webdriver"
    
    class TestLogin < Minitest::Test
     def setup
       @driver=Selenium::WebDriver.for :chrome
       @driver.navigate.to "http://yoursite.com/login"      
     end
    
     def test_login_correct
           @driver.find_element(:id,"login").send_keys "username" 
           @driver.find_element(:id,"password").send_keys "password"
           @driver.find_element(:id,"submit").click
           sleep (1)
           if @driver.find_elements(:id,"logins").size <= 0 
    	   assert false, "Bad Login"
           else
           	   assert_match "success",ps, "Page Failed"
           end
     end
    end
    

    Now there you go with your first automation test! easy?
    Okay, I guess I still own you some explaination

    The setup function basically tells your program to start chrome browser and go to url “yourlogin.com”.  find_element is part of the function within the webdriver class, which do different thing within your browser window (you can find all the reference here: https://gist.github.com/huangzhichong/3284966)

Each Minitest class represents 1 test case.

Leave a Reply

Your email address will not be published. Required fields are marked *