1it is process of hiding implementation details and
2only showing the functionality to the user.
3Abstraction focus on what the object does instead of how it does.
4It is achieved by using Abstract class and Interface.
5abstract methods (methods without body, cannot be static and final),
6interface must implemented and abstract classes must be extended
7by regular classes in order to achieve abstraction
8(because abstract methods can only be exist in abstract class and interface).
9A class can implement multiple interfaces,
10but it can extend only single abstract class.
11
12Ex: In my framework I have achieve abstraction by using collections or
13Map, because it’s all interface. Most of the cases I come across using List.
14If we want to access elements frequently by using index, List is a way to go.
15ArrayList provides faster access if we know index.
16If we want to store elements and want them to maintain an order,
17List is a better choice.
18
19i)List<String> webs=driver.getWindowHandles();
20=>create a list first to store web URLs in list
21
22ii)findElements evaluates multiple elements so therefore will assigned
23to List <WebElement>
24
25iii)To handle dynamic elements store it in the list and identify by index:
26List<WebElement> all=driver.findElements(By.tagname(“”)); (or other locators).
1Abstraction: Hiding the implementation details,
2concentrating on essentials things,
3without worrying about the details
4■ In java, abstraction is achieved via abstract class or interface
5■ Abstraction cannot exist without inheritance
6
73.1. Abstract class a class that's meant to be inherited
8(cannot be private or final)
9■ To create an abstract class: add keyword abstract
10before the class declaration
11■ A class that we cannot create object
12when abstract class extended by regular class:
13we MUST override all the abstract methods of super class
14when abstract class extended by abstract class:
15no need to override any abstract methods
16
17abstract class vs non-abstract class:
18NON-ABSTRACT CLASS:
19cannot have: abstract methods
20can have: constructor, instance method, static method,
21instance block, static block, instance variable, static variable
22ABSTRACT CLASS:
23can have: constructor, instance method, static method, instance block,
24static block, instance variable, static variable...
25ABSTRACT METHOD: method without implementation, meant to be override
26(cannot create object, cannot be final,static,private)
27
28FRAMEWORK EXAMPLE:
29In my framework I have achieved abstraction by using collections
30or Map, because it’s all interface. Most of the cases I come
31across using List. If we want to access elements frequently
32by using index, List is a way to go. ArrayList provides
33faster access if we know index. If we want to store elements and
34want them to maintain an order, List is a better choice.
35i) List webs = driver.getWindowHandles();
36=>create a list first to store web URLs in list
37ii)To handle dynamic elements store it in the list and identify by index
38List all = driver.findElements(By.tagname(“”));
39In my framework I follow POM and had situations where some pages
40shared similar actions that were similar but worked slightly
41different, so I was able to use abstraction to define those
42actions and implement them in each page according to what was needed
43for that webpage
1Sometimes we may come across a situation
2where we cannot provide implementation to
3all the methods in a class. We want to leave the
4implementation to a class that extends it.
5 In that case we declare a class
6as abstract by using abstract keyword on method
7signature.In my framework I have created my
8PageBase class as super
9class of the all page classes.
10I have collected all common elements
11and functions into PageBase class and
12all other page classes extent PageBase class.
13By doing so, I don't have to locate very
14common WebElements and it provides
15reusability in my framework.
16Also
171)Abstract classes cannot be instantiated
182)An abstarct classes contains abstract method,
19concrete methods or both.
203)Any class which extends abstarct class must
21 override all methods of abstract class
224)An abstarct class can contain either
23 0 or more abstract method.