Java Basics for Selenium

Software Testing is very essential process of Software development life cycle. Basically there are two types of software testing conducts on any software, first is Manual software testing and second is Automation software testing. Automation testing is useful to accelerate the Testing process and for automation we use various tools like Selenium, Apache Jmeter, Sikuli, QTP, Appium, Selendroid etc. Selenium is a most famous and open source tool to automate the web applications but to use this tool we need to know some java basics for selenium, so that we can implement the automation scripts to execute the test cases.

Java Basics for Selenium

Java is most famous scripting language to use in selenium for implementing the automation script. It is an object oriented programming language which has multiple data types like: int, double, float, char, string, array etc.

Methods or Functions:

In programming, blocks or group of statements is known as Methods or Functions.

  • These methods or functions are reusable.
  • We can declare the method with unique name.
  • We can call the method within the method also.
  • We can declare the methods in two formats
  • (i) Non-Static (ii) Static

For example:

  1. Non-Static Method

Syntax: public void Method_Name1() {

              }

  1. Static Method

Syntax: public static void Method_Name2() {

              }

 

String:

It is a class data type where we can store multiple characters. We can declare the string in two ways:

  1. Locally
  2. Globally

1. Local Declaration:

  • If we declare the string within any method or block, then we will call it as local declaration.
  • The scope of local variables is limited to that specific method only.
  • We can’t use those variables outside of the method.

For example:

public void sample1() {

string str;    // Local declaration

str = ”Rajesh”    // Assigning the value

system.out.println (“Welcome” +str);

}

If you are planning to use the variables (reference objects) in multiple classes & multiple methods then we need to declare it globally.

 

2. Global Declaration:

To access the objects (data type, methods & instances) in multiple methods and classes, then we need to declare the objects globally by using the access modifiers like: private, public, protected, & default.

Private: These objects can be used within the class only.

Public: These objects can be used in multiple classes & multiple packages. (Public objects can be used within the project)

For example:

private string str;   // Global declaration

public string s1;    // Global declaration

protected string s2;    // Global declaration

 

Parameterization:

Parameterization means a value or data type. We can pass or send the parameter to the method from the main method is known as parameterization. It is to Reuse the methods.

For example:

public void sample4(string str3) {

system.out.println (“Welcome” +str3);

}

public static void main(string [] args) {

Basics b = new Basics();   // Instance or object

sample4(“Vinod”);

sample4(“Deepak”);

}

Please click here to read Automation Script Implementation in Webdriver

Please click here to read Browser Launch in Selenium Webdriver

Please click here to read Features of Selenium Webdriver

7 Thoughts on Java Basics for Selenium

Leave a Comment