Selenium with JAVA...
In last post, we learnt that Selenium is an excellent automation tool used for functional and regression testing. Selenium offers us great flexibility to work with many programming languages like Java, Python, Ruby, C# etc. but as we all know Java is the most popular and widely used programming language used in the industry, we will start our selenium journey with writing Java scripts.
To write selenium scripts in Java, it is imperative to learn some basic Java concepts and syntax to efficiently write our script. Java is basically Object Oriented Programming (OOP) language. Here, we manipulate objects with data and methods to get desired output or results. so, we need to learn some basic OOPs concepts first. Some core OOPs concepts are:
- Class
- Object
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
- Class: Basically, class is a group of similar entities. In terms of coding, it is a logical component not physical one. For example, if you have a class called 'Bank', it could have objects like SBI, Axis, HSBC etc. It's properties(data) can be customer id, account number, customer name etc. and it can have methods or functions like deposit, withdraw, Open FD etc.
- Object: It is defined as an instance of the class and there can be multiple instances of the class just like we saw above, for 'Bank' class, there can be multiple objects. object can contain both data and methods, we perform different methods on our objects. In general, we can say that class is a blueprint for our object. We always create objects in the main method of our program.( Hang on for time being, you will get more clear idea once we start actual coding in eclipse.)
Sample program for Class and Object:
public class Bank {
//defining instance variables (data)
int accountNumber;
String customerName;
//defining one function called info to retrieve account number and customer name
void info(){ // void is a return type here as we are only printing and not returning any value, info is a method name
accountNumber=123;
customerName="Raj"
System.out.println("Account Number is: "+accountNumber+" Customer Name is: "+customerName);
}
//defining one main method where we create objects of the class
public static void main(String args[]){
Bank SBI = new Bank(); // object creation syntax
SBI.info(); // calling info method for SBI object
}
}
Here, one must note few points:
- Java always follows camel casing to declare variables.(first letter in small followed by first capital letter)
- System.out.println is a print statement in Java.
- It is always preferable to create objects in main method and we call methods on our object from main method.
Bravo ! our first Java sample program is ready, just run it in eclipse and observe the result !!
In next post, we will see more about Java in good detail and will explore new topics like constructor besides other OOPs concepts.

Great work bro!keep it up!
ReplyDeleteThanks bro !
ReplyDeleteInformative!!
ReplyDeleteThanks for sharing
Thank you 😊
ReplyDeleteMuch informative!!
ReplyDeleteThank you 😊
ReplyDeleteGreat Work Bro
ReplyDeleteThanks bro !!
ReplyDeleteGreat work.. Keep up your hard work....👍
ReplyDeleteGreat work !! I really appreciate your effort and knowledge...
ReplyDeleteKeep it up ...
Thank you 😊
ReplyDeleteThank you 😊
ReplyDelete[…] that is used to initialize objects of the class,for more info on class and object, please visit Selenium with JAVA… . Specifically, it is one special type of method to pass the value to the object at the time of […]
ReplyDelete