Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
1.8k views
by The go-to Tester (391 points)
When should I use interfaces instead of abstract classes with Selenium WebDriver in Java? Can you please exaplain with an example?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
we use interface for user to create their own method out of it. User can implement that interface on any of their class.

E.g. WebDriver is an interface which is implemented by classes, RemoteWebDriver, FirefoxDriver, ChromeDriver and many more. So you can easily declare a variable of type WebDriver and initiate it with any of above classes.

You use interface when you want to enforce rule/create blue print of your architecture. Also you are allowing user of the interface to implement another interface as well.

e.g. RemoteWebDriver implements all below interfaces.

HasCapabilities, HasInputDevices, FindsByClassName, FindsByCssSelector, FindsById, FindsByLinkText, FindsByName, FindsByTagName, FindsByXPath, JavascriptExecutor, SearchContext, TakesScreenshot, WebDriver

 

When you make abstract class, you make sure that user extends that class, user should not create new instence of that class. Again that will act as a blue print for you.

E.g. BaseActions, BasePageObjcts. these classes will have implementation of common reusable methods and variables

Hope that helps.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...