Android apps to use in appium android test examples


Friday, July 27, 2018

Java for Selenium Part 1

Java Environment Setup, Java Syntax together with Java plan Structure.

Java tin forcefulness out endure used inwards Selenium to write Programs (Test Scripts), Selenium supports other Programming languages besides but nearly of the Selenium Testers (nearly 77%) using Java Language.

i) Java Environment Setup

ii) Java Syntax

iii) Java Program Structure
i) Java Environment Setup


1) Download Java Software (jdk) together with Install

2) Set Environment Variable path (Path Variable)

3) Download Eclipse IDE together with Extract
Download Java from either or, together with install

After Installation you lot tin forcefulness out become Java folder inwards C:\program Files.
Set Environment Variable Path


Select myComputer together with right click
> Properties
> Advanced System Settings
> Environment Variables
> Select Path Variable from System Variables
> Edit
> Copy coffee bin directory path together with glue inwards variable value field
> OK
> OK
> OK
> Close
1) Write together with Execute a Java Program from Command prompt

2) Write together with Execute a Java Program using Eclipse IDE
1) Write together with Execute a Java Program from Command prompt

Step 1: Write a Program

Step 2: Compile the Program

Step 3: Run / Execute the Program
Step 1: Write a Program

public cast Sample {
public static void principal (String [] args) {
System.out.println ("Hello Selenium World");

Save alongside coffee extension
Step 2: Compile the Program

> Launch Command prompt
> Change to Java Program file directory
> Type javac

* It creates Java Class file
Step 3: Run / Execute the Program

> Launch Command prompt
> Type coffee ProgramFileName

Then it displays Output on the Console
Edit Java Program

Open the plan file together with Edit
> Compile the file
> Run / Execute the Program
2) Write together with Execute a Java Program using Eclipse IDE

Eclipse IDE:

Eclipse Integrated Development Environment

> Eclipse IDE is platform to write together with execute estimator programs similar Java, Perl, Python, Ruby, PHP etc...

> It provides editor for writing programs, Syntax guidance, Context Help, Auto Compilation etc...

> Eclipse IDE is an Open Source Software.
Download Eclipse IDE together with Extract 

Steps to Write together with execute a Java plan using Eclipse IDE

> Launch Eclipse IDE
> Create Java Project
> Create Java Package
> Create Java Class / Java Interface

> Write Java Program
Eclipse IDE provides Auto Compilation
> Run/Execute the Program
ii) Java Syntax Rules:

1) Java is a Case sensitive Language.

2) First alphabetic quality of Class mention should endure inwards Upper Case.

3) Method names should get-go alongside Lower illustration letter

4) Java plan file mention should just check alongside cast name.

5) Java Program execution starts from principal method, which is mandatory inwards every Java program.

6) Every Statement / Step should halt alongside Semo colon (;).

7) Code blocks (ex: Conditions, Loops, method declarations etc...) enclosed alongside {}.
iii) Java Program Structure

1) Documentation Section

2) Package annunciation statement

ex: packet javaExamples;

3) Import Statements

We import Buil-in together with User defined libraries using import keyword.


import java.lang.*;

import - It is a Java Keyword

java - Project

io - Package

Console - Class

lang.*; -  All Classes from the Package

4) Class annunciation Statement

public cast Sample {}

public - Access Modifier

class - Java Keyword / Reserved discussion to declare the Class.

Sample - Class Name 

5) principal Method

public static void principal (String [] args){}

public - Access Modifier

static - Non Access Modifier(use principal method without invoking whatever Object)

void - Returns Nothing

main - Method name

String [] args - is the parameter to the principal method.

6) Declarations

We declare Variables together with Constants.

int a;

int a = 100;

int a, b, c;
c=10, b=20, c=30;

int a=10, b=20, c=30;
char a ='A';
final int b=100; //Correct
final int c; //Incorrect

7) Normal Statements

d = a+b;
System.out.println (d);

System - Class Name
out - Object
println - Method

8) Code Blocks 

Condition blocks

Loop Blocks

Method Blocks

Constructer blocks etc...


1) Every Normal Statement should halt alongside semi colon (;).

2) Every code block should enclose alongside {}.
Syntax to Create Object
Classname objectName = novel Classname();
A Sample Java Program 

// It is a Sample Program to empathize Java plan Structure 
//and Syntax

package javaExamples;

import java.lang.*;

public cast Sample2 {
//Create a Method alongside returning a value (It is to multiply iii numbers)
public int multiply(int a, int b, int c){
int effect = a * b * c;
return result;
// Create a Method without returning whatever value
public void comparison(){
int x, y;
x=10; y=20;
if (x > y){
System.out.println("X is a Big Number");
System.out.println("Y is a Big Number");

public static void main(String[] args) {
//Create Object
Sample2 abcd = novel Sample2();
//Acess user defined methods using Object
int z = abcd.multiply(123, 987, 455);

//Variables together with Constants declaration
int a =10, b=20, c, d; //variables Declarations together with Initialization for merely about variables.
c=30; //Initialization

final int coin =100; //Constant Declaration

d= a + b + c;
System.out.println("Addition of a, b, c is: "+ d);//Addition of a, b, c is: 60

System.out.println(c); //30

//Condition Block
if (a>b){
System.out.println("A is a Big Number");
else {
System.out.println("B is a Big Number");

//Loop Block
for (int i=1; i <=10; i++){
Java for Selenium Part ii Link


No comments:

Post a Comment