- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to deal with reusable components in Selenium Java?
We can deal with reusable components in Selenium Java with the help of inheritance concept. It is a parent child relationship where the child class inherits the properties and methods of the parent class.
Example
For Parent class.
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Baseclass { public void login() throws IOException { Properties prop = new Properties(); //Reading values from property file FileInputStream ips = new FileInputStream( "C:\Users\ghs6kor\eclipse- workspace\Inheritance\config.properties"); prop.load(ips); System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); driver.get(prop.getProperty("url")); } }
Example
For Child class.
import java.io.IOException; public class Child extends Baseclass { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Child c = new Child(); c.login(); c.testinheritance(); } public void testinheritance() { // parent class method used in child class login(); System.out.println("Test Inheritance"); } }
- Related Articles
- How to deal with ModalDialog using selenium webdriver?
- How to deal with security certificates using Selenium?
- How to deal with Garbage?
- How to Deal With Team Attrition
- How to deal with stubborn children?
- How to add components with a Relative X Position in Java
- How to deal with a cynical boss?
- How to Deal with Threats and Opportunities
- How to deal with a cranky baby?
- How to Deal with A Lying Spouse
- How to left align components vertically using BoxLayout with Java?
- How to add components with a relative Y position in Java?\n
- How to add components with relative X and Y Coordinates in Java?
- How do you make code reusable in C#?
- How to separate Components in a Row or Column with Box in Java

Advertisements