Object oriented programming
Java, C#, Ruby, Python, and Perl follows this
Java with Selenium has more use.
What is Classes
Class -a Class is a group of objects that have common property.
Its is a template or blueprint from which objects are crated
Object
an entity that has a state and behavior is known as an object ex
Constructor in java is a special type of method because it needs to fulfill following two conditions
1) Name of the constructor should be same as that of the class.
2) It should not have a return type.
- mercedes is a car> mercedes is an object of class car
First create Package> Project>class
java
int integer -cant be name, has to be a value, always integer
int length = 201;
int breadth = 125;
int is called data types
length and breadth are called data variables-as they can store any value
to store name of car in variable
every line has to end in variable
Convention of declaring variables
Camel casing convention
If we have to declare variable
First character has to be small and first letter of second word has to be capital
so if we have to declare your car name, i.e first word of first word is small
so write
String carName = "Mercedes";
If we declare variable color
String color = "I have a mercedes of white color"
There is more data type called (to store one character) example bmw has model #360 or mercedes wide 270
>>>If one character has to be stored , we store in one variable of char and store in single quotes
if one variable has to be stored then it stored in char
String store many variables but char for one character to be stored
so we will write
char model = 'x';
(also char stored in single quotes
>>>if we have to store decible, then declare variable called
double breadth = 124.57;
difference between integer and decimal
if it involves dot then we have to use data type double
Also available float so we can also write
float breadth = 1245.56f;
If number belongs to float category, we write f after number.
float can store upto 4 digits
meaning-when we declare or write double breadth then space declared is big
float breath is declared, then space created inside memory is small
If # of digits after decible are many then we declare as double
if # of digits after decible are less then we can declare as float
what is Boolean
Boolean is something that can have only two values
true or false
like
boolean isMercedesCostly = true;
boolean canIBuyIt = false;
these are datatype that we have to deal in java
there is something like creating our own datatype
int/string/char/double/float and boolean
package demo;
public class Calculator {
public void add( int a, int b);
System.out.println(a+b);
public static void main(Static[]args){
Calculator basicCal = new Calculator;
basicCal.add(10,20);
}
}
Constructor in java is a special type of method
it need to fullfill
1) name of the constructor should be same as class
2) it should not have return type
return of multiplacation of two numbers is int
return of addition or two numbers is double
return of favourite actore type is string
what is void return type
its a void return type
that is used to initializes the object.
Java constructor is invoked at the time of object creation.
it constructs the values i.e.
provides that data for the object that is why this is called constructor
sHAPES
App consist of calculating area
back end behind to cacluate area
say 4 x 1 sent to programme to calculate area
variable at class level called as field
it outside method than called as field
every method followed by ( )
Decision making
Decision is made using IF statment
so
public demo;
public class DecisionMaking{
public static void main(String[]args){
if (mealAtHome.equals("Something Tasty")){
System.out.printlm("I ill ofer a small Pizza for snaks" );
}
else {
System.out.println("Order a main course meal");
}
int money = 25;
Press control and forward slash to get // lines
You can't compare strings and integers in same
IF integers have to be compared then wehave to use
Int money = 25
&& is and in java
and is both have to satify together
If more conditions then we use switch case statement
or is
||
switchcase
public static void main(String[]args){
String day ="Monday"
switch(day){
case "Monday":
System.out.println("I will wear white today");
break:
default statement always come at bottom
what is abstract class and interface
its a theoretical concept
this is something we wont be using in selenium but important for interview
security class was giving message that all department will get 3 messages
we discussed this in message overriding
message still remains similar
all the employees should get message that all emplyess will get 5 messages
hr will get 4
accounts will get 3
securiy will get 2
we actually going to override message in all the child classnow
it will be declatedin parent classes and also overridgen in child lasses
in this we create abrstract class
when we declere as abstract then class that declare thosuldbe declare as abstract class
so after public, write abstract class
public abstract class Management {
when we declare method as abstract, then we declaing than method will be dicussed in child class
so lets see
lets create a child class
to make extended class of child class we writ
public class IT extends Management {
@overrise
public void message () {
System.out.println(
now go to hr class
public class HR extends Management{
public void message (){
System. out.println("All the employess
now accounts
public class Accounts extends Management{
@override
now to security
public class Security extends Management{
lets create object of child classes
Ram.message(); (in this we calling message from IT class as RAMbelongs to IT class
John.message();
Sam.message();
Bob.message();
what is diff
abstract can contain abstract method
normal class can't hold abstract method
asbtract class can have normal and abstract method
message is -next month onwrds, employess get to attnd two extra day in office
this message to accounts and security dept only
how we can do this
message is similar .condition is to convey to two child classes
we don't want message to it and hr
if we put in parent class than it will be visible toitand hr
only accout and securiy dept
what we can dohere
we can't place meessage in management.
second, we can create one more parent class , which is parent to security and accounts only
butproblem, wecan't create two parent classes
multiple parents are not allowed in java
Concept of interfacein java. It gives functionally ofparent class but its not a class
its a interface
so we wont creat a another class. rather we create interaface between
diff between interface and class
interface cannot contain normal message
interface can alwAYS CONTAIN ABSCRACT MESSAGE
c WITH A IS ABSTRCT CLASS
public class Accounts extends Management implements Management2{
public class Security extends Manageemnt implements Management 2{
what is diff between abstract and interface
anwser
abstract class can have abstract and normal
interface can only have abstract method only
Interface in Selenium
Method of inheritance(
if we need to be change implementation for one class then method overriding
If we need to change implementation for all classes . In this override in all child classes.
we created this class as ABSTRACT class.
over view
we don't write just overview
interface used as this gives same option as parent class
Java says if we want to have finctional that given by parent.
Java gives option to create interface
its similar to having uncle and ant /
this interface lets you make message that can be extended to two child classes
in real life, we can have one patern but multiple uncesl
same way interface can be many
how to create interface
we have to declare message so
public void message 2();
it can let you declare create method..and these are implitely abstract
they are by default abstract
These
Called polyphormesium
One paretn clsscan be represted by more than one childclass
Selenium
how to create a class in eclipse
how to call a method
how to use if/else
howtouse for/loop
S.# Step Selenum Syntex
1. Open the browser webDriver driver= new FirefoxDrive();
first req is mozilla fire installed
If we need to negatite to web application then we must write
driver.get("http://www.facebook.com")
after website open
we need to take some action..
various things that we see that we interact
Selenium all these things on website are called webelements
how we will write write or click on boxes.
or how to interact, we need to know concept of locaters.
if you understand locaters, you understand complete selenium
Please practice so things don't skip from mind
coming to 3rd point
take action on web elements
wew ill disccuss concept of locaters
| driver.findElement(By.id("email")).sendkeys("abc@gmail.com") |
So find Element on webpage, by id, whose Id is email
Send keys emulates and writes abc@gmail.com
| driver.findElement(By.id("email")).sendkeys("abc@gmail.com") |
when id and name both not there,then we use selenenium gives option to
by putting tag.class
Collections
grouping similar things
set of rules to group similar things together is called collections
List-Set-Map
collectionFramework
We will create class called ArrayListDemo
main and enter gets you
public static main void(String[]arays}
when we created calculator, we wrote
public void add (int a, int b)
Array size is fixed
array list-size is dynamic
array list is efficient in retrieving data.
if we have to modify data in future, then linked list better
HashSet does not maintain insertion order
it does not maintain order in same order\
also if any duplicate value, hashset dont display
duplicate values not allowed in hashset
HashMap
its bit different.
Name Phone #
String Int
Key Value
Left side always Key
right side always Value
Hash Map receives value in Key format
HashMap<String, Integer> td = new HashMap<>();
td.put























