How to implement code re-usability in Selenium Automation Framework
In this post, you will learn 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 page (action) methods which in general contain actions which we are going to perform 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:
You can also place these action methods in some other class like Common.java. And if you want to re-use any of the methods in your Selenium script, just create the object Common class and call that method. Like .,
// Create Object
Common commonObj = new Common();
//Call method
commonObj.openURL("https://www.techlistic.com/p/selenium-tutorials.html");
Happy Learning! :)
Top 25 Must to Know Selenium Commands << Previous || Next >> 10+ Selenium Webdriver Practice Assignments
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 Re-usability
- Better maintainability of code
You can also place these action methods in some other class like Common.java. And if you want to re-use any of the methods in your Selenium script, just create the object Common class and call that method. Like .,
// Create Object
Common commonObj = new Common();
//Call method
commonObj.openURL("https://www.techlistic.com/p/selenium-tutorials.html");
Happy Learning! :)
Top 25 Must to Know Selenium Commands << Previous || Next >> 10+ Selenium Webdriver Practice Assignments
Follow Us
Feel free to ask queries or share your thoughts in comments or email us.
Comments
Post a Comment