Refactoring Custom methods of control libraries

In last two post we discussed creating custom methods for Setting values to the UI control and Getting values out from the UI control. The code we wrote was fine, but there were lot of redundant and not so necessary parameters passed in each and every methods, in this post we will try to refactor our code a little bit to to have

  • Reduced number of parameters
  • Strongly-typed parameters
  • More reusable

Here is the complete video of the above discussion

Here is the complete modified code discussed in the video

First try to create a class called PropertiesCollection and create an auto-implemented property for WebDriver as shown below

And assign the ChromeDriver to the PropertiesCollection.driver property, then instead of IWebDriver local instance variable on each method (Since those are also passed as parameters) , try to use the PropertyCollection.driver property.

Set Methods for controls like Textbox, Button, DropDownList box.

Get Methods for controls like Textbox and DropDownList box

Thanks for watching the video and reading the post!!

Please leave your comments and let me know if there is anything need to be improved in the post!!!

Thanks,
Karthik KK

6 comments

  1. Shailaja says:

    Error 1: Inconsistent accessibility: parameter type ‘UnitTestProject3.PropertyType’ is less accessible than method ‘UnitTestProject3.seleniumSetMethods.EnterText(string, string, UnitTestProject3.PropertyType)’
    this error comes when i run my task..!! Please reply for solution..

    • Karthik kk says:

      I think your enum is within the SeleniumSetMethods class, make sure you copy paste the enum out from the class and make it as public so that it can be accessible.

      Thanks,
      Karthik KK

Leave a Reply

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