Automation testing using Selenium

Mercy Kinoti
Crispytest
Published in
2 min readJul 3, 2020

Automation testing is the process of writing scripts to run test cases. When it comes to regression testing, this is the most efficient way to manage it.

Regression testing is testing the major functionalities of the application anytime there is a change in the code base, as a result of bug fixes, new feature or integration.

Why Automate

  1. Accuracy: Automation testing is more accurate than manual testing. It has less room for errors.
  2. Saves cost on human resource: it doesn’t require as many people as manual testing.
  3. Faster: it’s more faster to run tests through Automation than manual testing.
  4. Frequent execution: You can run the scripts at any time without much effort.

Selenium is a suite of software tools, web browsers tool for functionality and automation testing.

My language of choice is ruby and there are libraries that support it.

The set up

Prerequisite: ruby installation

https://www.ruby-lang.org/en/documentation/installation/

Install selenium webdriver and test-unit gems

gem install selenium-webdriver

gem install test-unit

The browsers

To use chrome, you need to install chromedriver

brew cask install chromedriver

To use firefox, you need geckodriver

brew install geckodriver

To use safari, safari’s driver is launchable via the /usr/bin/safaridriver executable

First Script

Create a test.rb file

require 'selenium-webdriver'
require 'test/unit'


class Signup < Test::Unit::TestCase
def setup
@driver = Selenium::WebDriver.for :chrome
@driver.get 'https://crispytest.netlify.app/'
@driver.manage.window.maximize
end

def teardown
@driver.quit()
end

def test_signup
@driver.find_element(:id, 'schedule_test').click
sleep 2

@driver.find_element(:id, 'email').send_keys 'jhan@rancenylt.ga'
@driver.find_element(:name, 'password').send_keys 'BeGreat@2020'
@driver.find_element(:name, 'username').send_keys 'Crispytest'

sleep 2

@driver.find_element(:id, 'create_company_account').click

sleep 2
end
end

Running the script

ruby test.rb

Expected Results

Opens a new chrome instance, loads this website https://crispytest.netlify.app/ and maximizes the window

Then clicks on Schedule a test button that opens this page

It enters the email, password and company name then clicks on Create Account button.

Look out for the next article on finding elements.

References:

https://www.selenium.dev/documentation/en/introduction/on_test_automation/

Java setup — https://www.guru99.com/installing-selenium-webdriver.html

--

--