Thursday, September 22, 2016

Code Resuablity & Maintainablility Using Action Methods in Selenium Webdriver

In this post I'm going to share kind of coding pattern which is very helpful in maintaining our automation code. This post is written insight to help beginners. We'll learn that instead of writing a linear script, we should create action methods (functions) which in general contain actions which we are going to performing on our web software.

Let's say, we have a login functionality in our software and we have to automate it. In that case we'll create a method named login and write the commands like, entering username, password and click login in that method. Now we can use that method wherever we need it in other test cases as well. Benefits of using action methods are:

  • Code Reusability
  • Better maintainability of code
Sharing below a sample script, in which I'm entering data in a web form using action methods:




Feel free to ask queries. Happy Coding :)


@uthor 
Vaneesh Behl
vaneesh.behl@gmail.com