Assertion for test automation scripts with Rspec

Here I am going to discuss about how we can use assertion in our test automation scripts with rspec.

In my works I find out that we can use assertions in our automation scripts to get success or failure confirmation for our each test case behavior.

The more we break down our scripts the more we get structured report for our automation scripts execution.

Example:

Case: Successful sign in

Think like this – how we can be confirmed in our automation script after a successful sign in.

After signing in it redirects to a page where we can look for an element which always appears after a successful sign in. for example- ‘sign out’ button. So after a successful sign in we will look for an element ‘sign out’ button. If we find this element we can say the sign in action is a success otherwise the sign in action was not successful.

Example –

describe 'Admin Approval Tests' do

  describe 'Approve a pending user request for user john and Edit  user role' do

     context 'user Admin' do

       it 'should Sign in as admin user' do

         driver = Selenium::WebDriver.for :remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities => :firefox
         driver.get "server address"
         driver.manage.window.maximize
         driver.find_element(:id, 'username').clear
         driver.find_element(:id, 'username').send_keys("username")
         driver.find_element(:id, 'password').clear
         driver.find_element(:id, 'password').send_keys("password")
         driver.find_element(:xpath, '//button[@type='asd').click

         expected_value = driver.find_element(:link, 'Sign out').text
         expect(expected_value).to be == “Sign out”
         end
      end
  end
end

After signing in the driver will find the link “sign out” and get the text from it and match it with the expected text.

Now,

Scenario failure: The user name or password was wrong

Then the driver will not get the logged in page and will not find the “Sign out” link

Scenario success: The user name or password was correct

Then the driver will get the logged in page and will find the “Sign out” link

So we expect “Sign out” text after a successful sign in. So with this information we can easily get confirmation of our sign in action was a success or not.

Thus we can apply assertion in many ways in our test automation scripts to get confirmed about each execution of test cases. It’s a very simple example. You can explore different scopes for your script as you like.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: