Sep 3, 2015

Selenium Step by Step Videos

Selenium Step by Step Videos

Module I: Selenium Introduction


1) Overview of Test Automation

2) Overview of Selenium


3) Selenium Test Process


4) Java for Selenium (Overview)


Module II: Java Programming for Selenium


A) Java Fundamentals

1) Introducing Java

2) Java Environment Setup and Write first Java Program.

3) Java Program Structure / Java Syntax

4) Comments in Java

5) Java Data Types

6) Java Modifiers

7) Java Variables

8) Operators in Java

9) Java Conditional Statements

10) Java Loop Statements

11) String Handling in Java

12) Java Arrays

13) Java User defined Methods

14) Java Built-in Methods

15) IO operations in Java

16) File Handling in Java

17) Exception Handling in Java


B) Java Object Oriented Programming System


18) Java - Inheritance

19) Java - Polymorphism

20) Java - Abstraction

21) Java - Encapsulation

22) Java Interfaces


Module III: Selenium WebDriver

1) Overview of Selenium WebDriver

2) Selenium WebDriver Environment Setup

3) Element Locators in Selenium

4) Selenium WebDriver Methods

5) Handle Elements Part-1

6) Handle Elements Part-2

7) Write Selenium Test Cases

8) Cross Browser Testing

9) Synchronization

10) Enhancing Selenium Test cases


Module IV: TestNG for Selenium

1) Overview of TestNG

2) Install TestNG in Eclipse   

3) TestNG Annotations and Attributes       

4) Create Multiple Test cases       

5) Executing one or more Programs using XML file

6) Grouping Test Cases       

7) Data Driven Testing using DataProvider Annotation

8) Parallel Test execution


Module V: Selenium IDE


1) Overview of Selenium IDE

2) Selenium IDE Download and Install

3) Record and Run Test Cases

4) Create Test cases manually

5) Enhance Test Cases


Module VI: Selenium Grid


1) Overview of Selenium Grid   

2) Configure the Nodes   

3) Parallel Test Execution

-------------------------------------------

Aug 31, 2015

Test Automation Tutorial


Overview of Test Automation

1)    Drawbacks of Manual Testing

•    Manual Testing requires more time or more resources
    (Human resources and Environmental Resources), some times both.

•    Performance testing is impractical in manual testing
    (Organizing thousands of machines and human users is not possible).

•    Less Accuracy (Human Users may make mistakes)

•    Executing same tests again and again is time taking process as well as Tedious.

•    Verifying GUI Objects Size differences and Color combinations are not easy
     in Manual Testing.

•    Not Suitable for Large scale projects and time bounded projects.

•    Batch Testing is not possible, for each and every test execution Human
     user interaction is mandatory.

•    Manual Test Case scope is very limited (Human user can concentrate on one or
     two verification points only), if it is Automated test, scope is unlimited
    (Tool is software It can concentrate on multiple verification points at a time).

•    Comparing large amount of data is impractical (If we want compare Thousands of
     Records, it is not possible, but Test Tool can compare thousands of records).

•    Checking relevance of search of operation is difficult

•    Processing change requests during software maintenance takes more time.

2)    Advantages of Test Automation
 

a)    Fast:
Automated tests are significantly faster than human users.

Test Tools are faster in Test execution than human users, In Software Testing
two important tasks,

i)    Test Design    ii)    Test Execution  Or Test Run

In case of Test design Test Tools are not faster, for Test Design human user
interaction is mandatory. Test Tools provide IDE (Integrated Environment) for
designing Tests.

In case of Test Execution Test Tools are faster than human users, Tool can execute series of Tests quickly without user interaction.
Anyhow Test Design one time activity but Test execution multiple times, so defiantly we can save Time.

b)    Reliable
Tests perform precisely the same operations each time they are run, thereby eliminating human error.
Human Users may make mistakes, if you provide proper logic Test Tool can provide correct output every time.

c)    Repeatable
We can test how the application reacts after repeated execution of the same operations.
We can execute same operations (Data Driven Testing) using multiple sets of Test Data. If it is manual Test Testing, takes more time.
 

Why we need to execute same operations multiple times?

For positive and Negative Testing we perform Data Driven Testing.

d)    Programmable
We can program sophisticated tests that bring out hidden information.
We can apply programming features to our tests (Ex: Flow control statements, Functions etc…) We can insert multiple verification points in an Automated Test, Test Tool is software it can concentrate on multiple verification points at a time, but in Manual testing human user can concentrate on one or two verification points at a time, So  Automated Test scope is very high than Manual Test case.

e)    Comprehensive
We can build a suite of tests (Batch Testing) that covers every feature in our Application.
Software Test Tools support Batch Testing (Executing Series of Tests), we can create test batches, without human user interaction Tools can execute test batches, if it is manual testing, each and every test case execution user interaction is mandatory.

f)    Reusable
We can reuse tests on different versions of an application, even if the user interface changes.
Ex: Sanity Tests, Regression Tests

3)    Disadvantages of Test Automation
 

a) 100% test automation is impractical, generally we try to automate maximum test
 scenarios.

b) All types of testing is not possible (Ex: Usability Testing)

c) More Efforts required at initial stage of Test Automation.

d) Not suitable dynamically changing UI designs

e) Debugging issues

f) Tools may have their own defects, so we may not get desired benefits.

g)    Lack of knowledge

h)    Environment limitations (In UFT, if you want test Java Application Java Add in required, SAP Application SAP Add in required, UFT is not providing Add ins for All Environments.)
If it is manual testing no Environment limitations, irrespective of the Application Environment you can apply manual testing methods.
----------------------------------------
4) Types of Test Tools
 

a) Business classification

i) Vendor Tools
-----------------
Companies develop test tools for commercial use, license is required to use and get technical support.

HP- UFT, LoadRunner, QC/ALM etc…

IBM-Rational- Rational Robot, RFT, RPT, QA Director

Micro Focus-SilkTest, Silk Performer

ii) Open Source Tools

Source code available on NET anybody can download and use.

Ex: Selenium, Jmeter, Bugzilla, QAwebload etc…

iii) In-House Tools

Some companies develop test tools for their internal use / Private use.
---------------------------------------------------------
b) Technical Classification
----------------------------
i) Functional & Regression Test tools
QTP, RFT, Selenium etc...

ii) Performance/Load/Stress Tools

 LR, RPT,Silk Performer JMeter etc

iii) Test management Tools

QC, QA Director etc...

iv) Defect Management Tools

Bugzilla, zera, Issue Tracker, PR-Tracker etc.

v) Security Test tools

vi) Unit Test tools Etc...
------------------------------------------------
5) Overview of Functional Testing
Verifying a component or systems functionality with respect to Functional
Requirements.

Coverage of Functional Testing

a) Input Domain Coverage
Verifying weather the system (Application under Test) is accepting valid inputs
or not? And preventing invalid inputs or not?

b) Output Domain Coverage 


Verifying weather the System is providing correct Outputs or not, based on input and process

c) Database Testing
    Verifying the Data Integrity,

    Data Manipulations (Add, Edit, delete),       

    Data Processing,       

    Data Comparisons,       

    Data Back-up and Recovery Operations Etc...

d) Error handling
Verifying how the system is handling user unauthorized/invalid operations and providing error and help messages.

e) Order of functionalities
Verifying weather the System is providing correct order of functionalities or not?
------------------------------------------------------

Aug 18, 2015

Selenium Brochure

Selenium Brochure 

1) Test Automation and Selenium Basics   
 

    • Overview on Test Automation
    • ATLM (Automated Test Life Cycle Methodology)     
    • Selenium Test Process    
    • Overview on Selenium   
    • Selenium Suite of Tools     
    • Overview of Java for Selenium

2) Java for Selenium
    

    • Why Java for Selenium
    • Overview of Java
    • Java Environment Setup   
    • Comments in Java     
    • Java Data Types     
    • Java Modifiers     
    • Java Variables   
    • Java Operators   
    • String Handling in Java    
    • Java Conditional Statements     
    • Java Loop Statements     
    • Arrays in Java     
    • Java Built in Methods     
    • Java User defined Methods   
    • File and IO operations in Java   
    • Exception Handling in Java   
   
    • Inheritance   
    • Abstraction   
    • Polymorphism   
    • Encapsulation

3) Selenium WebDriver   
    

    • Selenium WebDriver Environment Setup   
    • Write 1st Selenium Test Case   
    • Element Locators in Selenium     
    • WebDriver Methods   
    • Handle Elements in WebDriver    
    • Write Test Cases   
    • Cross Browser Testing     
    • Enhancing WebDriver Test Cases 

4) Selenium IDE       
    

    • Selenium IDE Download and Install   
    • Overview of Selenium IDE
    • Drawbacks of Selenium IDE
    • Record and Run Test Cases, Execute Test suites.   
    • Enhance Test Cases

5) TestNG Framework Implementation
   

    • Overview of JUnit
    • Overview of TestNG
    • Install TestNG in Eclipse
    • TestNG Annotations
    • TestNG Attributes   
    • Create Multiple Test cases   
    • Executing one or more Programs using XML file   
    • Grouping Test Cases   
    • Data Driven Testing using DataProvider Annotation   
    • Parallel Test execution

6) Selenium Grid
   

    • Overview of Selenium Grid
    • Configure the Nodes
    • Parallel Test Execution
-----------------------------------------

Selenium Tutorials

Selenium Tutorials

Selenium Brochure
(Selenium learning objectives for Software Testers.)
-----------------------------------------------------------------
Selenium Downloads 
(Download and Install Selenium Tools and other Plug ins.)
------------------------------------------------------------------
Selenium Quick Reference
(Overview of Selenium WebDriver, Java for selenium, Selenium IDE, Selenium Grid and TestNG Framework.)
------------------------------------------------------------------
Selenium Step by Step Videos
(Selenium Video Tutorials cover Selenium IDE, Selenium Webdriver, Java for selenium and TestNG Framework Implementation.)
------------------------------------------------------------------ 
Selenium Tutorial for Beginners
(Fundamentals of Selenium: Overview of Selenium, History of selenium Project, selenium License, Selenium Vs UFT, Configure Selenium etc...
------------------------------------------------------------------  
Selenium IDE Tutorial
(Download & Install Selenium IDE, Record and Run Test Cases, Debug Test cases, Insert steps and Insert Comments.)
------------------------------------------------------------------- 
Selenium WebDriver Tutorial
(Creating and Executing Selenium Test cases using Element Locators and WebDriver methods.
--------------------------------------------------------------------
Overview of Selenium WebDriver
(Selenium WebDriver introduction and Webdriver Environment setup.)
-------------------------------------------------------------------- 
Handling Elements in Selenium WebDriver
(Handling Browser, Link, Edit box, Button, Radio button, Text Area, HTML table, Frame, Check box objects.)
--------------------------------------------------------------------
Selenium Cross Browser Testing
(Executing Test cases using Mozilla Firefox, Google Chrome and Internet Explorer Browsers.)
---------------------------------------------------------------------
Selenium WebDriver Test Case Examples
(Creating Test cases using Element Locators and WebDriver Methods.)
---------------------------------------------------------------------- 
Selenium Versus UFT (Formerly QTP)
(Differences between Selenium and HP Unified Functional Testing.)
-----------------------------------------------------------------------
TestNG Tutorial
(TestNG Framework implementation, grouping tests, Parallel test execution and generating html test reports.)
-------------------------------------------------------------------- 
Selenium Interview Questions
(Interview Questions and Answers on Selenium.)
-------------------------------------------------------------------- 
Selenium Sample Resume
-------------------------------------------------------------------- 

Aug 5, 2015

Testing Tools

Software Test Tools
 

Software Test tool is Software used to automate Software Test process.

I) Functional and Regression Test Tools


1) HP UFT (Formerly QTP)
 

> UFT - Unified Functional Test Tool from HP is used to automate Functional and Regression Test cases of Desktop and Web Applications.

> It supports MS Windows operating environment only, doesn't support UNIX operating environment.

> VBScript is used for enhancing tests in UFT.

> UFT has IDE and Programming interface to create and execute Tests.

> UFT has an integrated MS Access database engine to support Database Testing.

> UFT is an Object based Test tool, based on software objects it supports test automation, but for Database testing no front-end object is required.

> UFT has 2 types of license, one is Seat license another is Concurrent license.

> UFT can integrate with ALM/QC for Test Management.

2) Selenium
 

> Selenium is a suite of tools to automate Web browsers, supports only web based applications.

> Selenium supports Functional and Regression Test automation of Web Applications.

> It is Open source software, released under Apache 2.0 License. Anybody can download and use with free of cost.

> Selenium Supports various programming languages(Java, C#, PHP, Perl, Python and Ruby) for enhancing test cases, we can use any one of the supporting language.

> Selenium supports various browsers (IE, Mozilla Firefox, Google Chrome, Safari etc..)

> Selenium supports various Operating environments (MS Windows, UNIX and Macintosh etc...)

> Selenium supports JUnit and TestNG frameworks for gouping test cases and genarating test reports

3) IBM RFT (Rational Functional Tester)
 

> RFT provides automated testing capabilities for functional, regression, GUI, and data-driven testing.

> RFT supports a range of applications, such as web-based, .Net, Java, Siebel, SAP, terminal emulator-based applications, PowerBuilder, Ajax, Adobe Flex, Dojo Toolkit, GEF, Adobe PDF documents, zSeries, iSeries, and pSeries.

> RFT supports Windows and Linux operating environments.

> Rational Functional Tester's object-oriented technology is used to identify various objects by their internal object properties and not by their screen coordinates.

4) SilkTest
 

> SilkTest supports industry standard languages like VB.NET, C# and Java, or you can use Silk Test’s own 4Test.

> SilkTest supports Visual Studio and Eclipse IDEs and is easy to integrate with unit testing and acceptance testing tools.

> SilkTest supports cross browser testing.

> SilkTest was originally developed by Segue Software which was acquired by Borland in 2006. Borland was acquired by Micro Focus International in 2009.

5) TestComplete
 

> TestComplete is a functional automated testing tool developed by SmartBear.

> TestComplete supports Python, VBScript, JScript, DelphiScript, C++Script, and C#Script to create tests.

> TestComplete supports Desktop, Web and Mobile applications test automation.

> TestComplete supports Distributed Testing, It can run several automated tests across separate workstations or virtual machines.

II) Performance Test Tools


1) HP LoadRunner
 

> HP LoadRunner is Performance Test tool and supports MS Windows and Linux (Load Generator only) operating environments.

> LoadRunner is a Protocol based test tool.


2) JMeter
> JMeter is an Open Source testing software.

> JMeter is a Java desktop application with a graphical interface, It can run on any environment that accepts a Java virtual machine, for example − Windows, Linux, Mac, etc.

3) SilkPerformer
> SilkPerformer is a software performance testing tool across web, mobile and enterprise applications.


III) Test Management Tools

1) HP ALM 

> HP ALM (Application Life Cycle Management Tool) supports various phases of the software development life cycle.

> ALM is a web based tool used to manage the application life cycle right from project planning, requirements gathering, until testing and deployment.

> ALM doesn't have any programming interface, It is only for documentation and generating reports.

> ALM can be used for all types of Software applications.

> HP ALM can be integrated with UFT (formerly QTP) and LoadRunner.

> ALM can be accessed by all Developers, Testers,  Business Analysts, Project Managers, and Product Owners.


2) Jira 

> Jira is a project management and issue tracking tool by Atlassian, Inc., and It is platform independent.

> Jira is written in Java, and It is Open source software.

> We can access JIRA cloud site via a mobile device. You have to just use the URL of the JIRA cloud site in your mobile web browser.

IV) Defect Management Tools


1) Bugzilla

> Bugzilla is a Web based defect management tool.

> Bugzilla is an open source bug tracking system, It is written in Perl and uses MYSQL database.

2) Mantis
 

> Mantis defect / issue tracking system is written in PHP, and works on various databases including MySQL, MS SQL, PostgreSQL.

Jul 31, 2015

Java Tutorial for Selenium


Java Programming for Selenium
 

A) Java Fundamentals 

(Comments, Data Types, Variables, Modifiers, Operators, Conditional statements, Loop statements, Arrays, Methods (Built in and User defined), File and IO operations and Exception Handling)

B) Java OOPS Concepts 


(Inheritance, Polymorphism, Abstraction and Encapsulation)
---------------------------------------------------------------------------
Java Environment Setup and Write First Java Program
 

> Download Java (JDK) Software and Install

> set Environment Variable (Path Variable)(* If want to execute Java programs from any directory in C Drive)

How to set:

OS: Windows 7

> Select MYComputer and Right click

> Properties

> Advanced System Settings

> Environment Variables

> Select "New" in System variables

> Enter Variable as "Path"

> Enter JDK bin directory path ("C:\Program Files\Java\jdk1.8.0_45\bin") in value field

> OK > OK > Ok
----------------------------------------
Verify the Environment setup:
> Launch Command Prompt

> Type java (It provides details)
-------------------------------------
Three steps to write and execute Java Programs

i) Write Java Program in Notepad (Editor)

ii) Compile the Program (It creates Class file)

Command prompt > Change to Program file Directory

> Type javac Programname.java (java is extension of Java program, javac command for compilation)

iii) Run /Execute the Java Program

> Type java programName
(It provides Output on the console)
-----------------------------------------------------
Use Eclipse IDE to write and execute Java programs.

Eclipse IDE (Integrated Development Environment)

It is a platform to write and execute Java programs, Perl, Python, PHP, Ruby etc...

It provides Editor, context help, help for syntax errors, Auto compilation and debugging.
-----------------------------
Download Eclipse software and extract.
Steps:
----------------
> Create Java Project
    -> Create a Package
        -> Create a Class / Interface
(We can write java code in the Class file)
--------------------------------------

Ex:
public class Sample {
    public static void main (String [] args){
        System.out.println("Hello Java and Selenium");
    }
}
-------------------------------------------------
Java Program structure / Java Syntax:
 

1) Package declaration statement
ex:

package abcd;
--------------------------------
2) Import statements
we can import Built in and User defined Libraries using import keyword.
(In order to use Existing Classes, Objects, and Methods)


Example:

import java.io.console;

(It Imports Console Class only from io package)

import java.io.*;

(It imports all classes from io package)
------------------
java - project

io - package

Console - Class
----------------------------------------------
3) Class declaration statement
ex:

public class Sample {
}

public - Access Modifier

class - Java keyword to declare a class

Sample - Name of the Class

Note: First letter of Class name should be upper case.
-------------------------------------------------
4) Comments section
// This is a Sample Java Program
-----------------------------------
5) Main Method (Java program execution starts from main method.)
(Main method is mandatory in every Java program)

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

public - Access Modifier

static - use main method without invoking any object.

void - returns nothing

main - method name
-------------------------------------------
6) Declarations
We can declare variables and constants
-----------------------------
Normal statements

Conditional blocks

Loop blocks

Method declarations
Etc...
------------------------------------------
A Sample Java Program:
package abcd;

import java.io.Console;
import java.lang.*;

public class Sample2 {
    // This is a Sample Java Program
    public static void main (String [] args){
        int a = 50, b, c; // Declaration of Variables
        b= 20; // Initialization
        System.out.println(a + b); // 70
        System.out.println("Addition of a, b is: "+ (a+b));
        final int MONEY = 100; // Declaration of Constant
       
        if (a > b) {
            System.out.println("A is a Big Number");
        }
        else
        {
            System.out.println("B is a Big Number");
        }   
       
        for (c = 1; c <= 10; c++){
            System.out.println(c);
        }
        }
    }
-----------------------------------------------
I) Comments in Java
 

Comments are English words, can be used for code documentation.

Purpose of Comments:
a) To make the code Readable

b) To make the code disable form execution

Comments Syntax in Java:
Use // for single line Comment or partial line as comment

Use /* statements
----------
-----------
----------
*/ for multiple lines comment

Or
In Eclipse

Select statements
Source menu -> Add Block Comment

Uncomment:
Select Comment block
Source menu -> Remove comment block
-------------------------------------
Usage of Comments in Test Automation
a) To write Test case headers

b) To write Method headers

c) To explain complex logic

d) To explain resource usage
------------------------------
Example:
public class Comments {

    public static void main (String [] args){
        int a = 10, b, c; // Declaration of Variables
        // It is a Sample Program
        System.out.println(a);// 10
        b = 50;
        c = 2;
        /*if (a > b) {
            System.out.println("A is a Big Number");
        }
        else {
            System.out.println("B is a Big Number");
        }*/
    }
}
---------------------------------------
II) Data Types in Java
 

Data type is a classification of the type of data that a variable or object can hold in Computer programming.

Example:

Character, Integer, String, float etc...

Java supports explicit declaration of Data types.
(We need to specify the data type before declaration of variables.)

Syntax:

dataType VariableName

Example:

int a;
or
int a = 100;
-------------------------------------
In Java we have two types of Data types.
i) Primitive Data types

ii) Non -primitive Data types
------------------------------
i) Primitive Data types (8)
Integer Data types
1) byte (8 bits)

Example:

byte a = 10;

2) short (16 bits)

Ex:

short b = 10000;

3) int (32 bits)

int c = 100000;

4) long (64 bits)

Ex:

long d = 100000L
-----------------------------
Rational Data types (Numbers with decimal places)

5) float (32 bits)

Ex:

float a = 1.2;

6) double (64 bits)

Ex:

double b = 19.234567;
----------
Characters

7) char (16 bits)

Ex:

char a = 'Z'
-------------------
Conditional

8) Boolean

Ex:

boolean a = true;
--------------------------------
ii) Non -primitive Data types

Non -primitive Data types in Java are objects and Arrays.

Ex:

Button = new Button("OK")
--------------------------------------------
III) Java Modifiers
 

Modifiers are keywords that we add to those definitions to change their meanings.

Two types of modifiers in Java:
i) Access Modifiers

ii) Non Access Modifiers
-------------------------------
i) Access Modifiers
We use Access modifiers to define Access control for classes, methods and variables.

There are 4 types of Access modifiers in Java

1) Private

The private access modifier is accessible only within class.

Ex:

class Abc {
private int a = 100;
.
.
.
}
--------------------------
2) default

If we don't use any modifier then it is treated as default, this can be accessible only within package.

Ex:
class Sample{
int a = 10;
.
.
}
-----------------------------------
3) protected

The protected access modifier is accessible within package and out side of the package but
through Inheritance only.
-----------------------------
4) public

public access modifier is accessible everywhere.

Ex:

public class Abc{
.
.
}
--------------------------------------------------
Modifier Within class    within package    outside of the package(by sub class) Outside of the package
----------------------------------------------------------------------------------------
private      Y        N        N                    N
------------------------------------------------------------------------------------
default   Y        Y        N                    N
-----------------------------------------------------------------------------------
protected Y        Y        Y                    N
----------------------------------------------------------------------------------
public    Y        Y        Y                    Y
---------------------------------------------------------------------------------
ii) Non Access modifiers

1) static

static modifiers are used to create class variable and class methods which can be accessed without instance of a class.

Ex:

class A {
static String name = "Selenium";
}
---------------------
2 final

final modifier for finalizing the implementation of classes, methods and variables.

class A {
int a = 10;
final int b = 20;
.
.
a = 30;
b = 50;//Incorrect
}
--------------------
3) abstract

abstract modifier is to create abstract classes and abstract methods.

Ex:

abstract sample {
Statements
--------
---------
------
}
--------------------------------
IV) Variables in Java
1) What is Variable?

A named memory location to store or hold the data.

Two types of memory in computer environment:

i) Primary memory - RAM

ii) Secondary memory -ROM

Ex: CD, DVD, HDD, USB drive etc...
---------------------
2) Declaration of Variables

Syntax:

dataType variableName;

Ex:

int a;
-----------------
dataType varaible1, variable2, varaible3;

ex:

int a, b, c;
----------------------
dataType variableName = value;

Ex:

int a = 100;
--------------------------
3) Assigning values to variables

i) Initialization

Ex:
int a;
a = 100;

ii) Reading
    using input devices
    from files (text, excel)
    from databases
    from Application objects
--------------------------------
4) Types of Variables

In Java we have 3 types of variables.

i) Instance variables
A variable that is declared inside the class but outside the method.

ii) Local variables
A variable that is declared inside the Method.

iii) Static / class variables
A variable that is declared as static, It cannot be local.
------------------------------
5) Naming Restrictions

i) Java variables are case sensitive, monkey is not the as MONKEY or Monkey.

ii) Java variable name must start with a letter or $ or _
Embedded periods can't be used.

Ex:

myvar
MYVAR
$myvar
_myvar
myvar1
myvar_1
-----------
my var
my.var
1myvar
*myvar
my-var
-----------------------
iii) Variable names cannot be equal to Java reserved words.

Ex:
int
for
import
-------------------
iv) Must be unique in the scope of declaration.
--------------------------------------------
Variables example:
---------------------
public static void main (String [] args){
        // Variable Declaration
        int a;
        a = 10; // Initialization
        // Declaration of multiple variables in a statement
        int b, c, d;
        b = 20;
        c = 30;
        d = 40;
        // Declaration of multiple variable and Assigning values.
        int e = 50, f=60, g = 70;
        char x ='A';
        double y = 2.345;
        String z = "Selenium123";
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        System.out.println(e);
        System.out.println(f);
        System.out.println(g);
        System.out.println(x);
        System.out.println(y);
        System.out.println(z);
    }
}
-----------------------------------------------
V) Java Operators
 

Operators are used to perform mathematical, Comparison and Logical operations.

Important categories of Operators:

i) Assignment Operators

ii) Arithmetic operators

iii) Relational operators

iv) Logical Operators
etc...
-------------------------------------
i) Assignment Operators

1) Assignment operator =

a = 10;

2) Add and Assign Operator +=

a = 10;

a += 20;

3) Subtract and Assign -=

a = 10;

a -= 5;

4) Multiply and Assign *=

a = 10

a *= 5;
--------------------------------------
Example:
public static void main (String [] args){
    int a = 10;
    System.out.println(a);// 10
    a += 10;
    System.out.println(a);//20
    a -= 10;
    System.out.println(a);//10
    a *= 5;
    System.out.println(a);//50
}
}
--------------------------------------
ii) Arithmetic Operators

Arithmetic Operators return value based Result.

1) Addition +  (for Addition and String concatenation)

2) Subtraction - (for Subtraction and negation)

3) Multiplication *

4) Division /

5) Modules %

6) Increment ++

7) Decrement --
-------------------------------
Example:

public static void main (String [] args){
    int a = 10, b = 5;
    String c = "Selenium", d = " Testing";
   
System.out.println("Addition of a, b is: "  + (a + b)); // Addition of a, b is: 15
System.out.println("Concatenation of c, d is: " + (c+d)); //Concatenation of c, d is: Selenium Testing    

System.out.println("Subtraction of a, b is: " + (a-b)); // 5
System.out.println("Multiplication of a, b is: " + (a*b)); // 50
System.out.println("Divison of a, b is: " + (a/b)); //2
System.out.println("Modulas of a, b is: " + (a%b)); //0

a = ++b;
System.out.println(a); //6
b = 5;
a = --b;
System.out.println(a);//4
b =5;
a = b+4;
System.out.println(a); //9
b = 5;
a = b-4;
System.out.println(a);//1
}
}
---------------------------------------
iii) Relational Operators

Relational operators return boolean or logical result (true or false)

1) ==

2) !=

3) >

4) >=

5) <

6) <=
------------------------------
Example:
public class OperatorsExample {
public static void main (String [] args){
    int a = 10, b = 20;
    System.out.println("a > b is " + (a>b)); //False
    System.out.println("a >= b is " + (a >= b)); //False
   
    System.out.println("a < b is " + (a<b)); //True
    System.out.println("a <= b is " + (a <= b)); //True
   
    System.out.println("a == b is " + (a == b)); //False
    System.out.println("a != b is " + (a != b)); //True
}
}
------------------------------------------
iv) Logical Operators

1) Logical Not operator !

2) Logical And Operator &&

3) Logical Or operator ||
--------------------------------
Result Criteria for Not operator

Operand 1    Operand 2    Result
----------------------------------------
true        true        false
true        false        true
false        true        true
false        false        true
-----------------------------------------
Result Criteria for Add operator

Operand 1    Operand 2    Result
----------------------------------------
true        true        true
true        false        false   
false        true        false       
false        false        false       
-----------------------------------------
Result Criteria for Or operator

Operand 1    Operand 2    Result
----------------------------------------
true        true        true
true        false        true       
false        true        true           
false        false        false               
-----------------------------------------
Example 1:

public class OperatorsExample {
public static void main (String [] args){
    boolean a = true, b = false;
    System.out.println(! (a && b)); // true
    System.out.println((a && b)); //false
    System.out.println((a || b));//true
}
}
----------------------------------
Example 2:

public class OperatorsExample {
public static void main (String [] args){
    int a = 100, b = 500, c = 700;
    if ((a > b) && (a > c)) {
        System.out.println("A is a Big Number");
    }
    else
    {
    System.out.println("A is Not a Big Number");
    }
}
}
-----------------------------------------
public static void main (String [] args){
    int a = 100, b = 500, c = 700;
    if (!(a > b) && !(a > c))  {
        System.out.println("A is a Big Number");
    }
    else
    {
    System.out.println("A is Not a Big Number");
    }
}
---------------------------
public static void main (String [] args){
    int a = 100, b = 50;
    if (! (a > b))  {
    System.out.println("A is a Big Number");
    }
    else
    {
    System.out.println("B is a Big Number");
    }
}
------------------------------------------------
Java Flow Control statements
    Conditional statements
    Loop statements
-------------------------------------
VI) Java Conditional Statements
 

a) Types of Conditional statements

i) if statement

ii) switch statement
-----------------------------
b) Types of Conditions

i) Single Condition

Ex:

if (a > b) {
Statements
-------
--------
.
.

ii) Compound Condition

Ex:

if ((a > b) && or || (a < c)) {
---------
----------
.
.
iii) Nested Condition

if (a > b) {
 if (a < c) {
  if (a < d) {
---------
------
}
}
}
-------------------
c) Usage of Conditional statements in Selenium Test Automation

i) To insert Verification points

ii) For Error handling
-------------------------------
d) Usage of Conditional statements

i) Execute a block of statements when condition is True.

if (condition) {
Statements
--------
------
-------
}
One way (Positive) Condition
Example:

public static void main (String [] args){
        int a, b;
        a = 10; b= 50;
       
        if (a > b) {
            System.out.println("A is a Big Number");
        }
    }
}
---------------------------------------
One way (Negative) Condition

public static void main (String [] args){
        int a, b;
        a = 10; b= 5;
       
        if (! (b > a)) {
            System.out.println("A is a Big Number");
        }
    }
}
-----------------------------------------
ii) Execute a block of statements when condition is true; otherwise execute another block of statements.

Syntax:

if (condition) {
Statements
---------
-------
------
}
else
{
Statements
---------
--------
---------
}

Example:

public static void main (String [] args){
        int a, b;
        a = 10; b= 10;
       
        if (a > b) {
            System.out.println("A is a Big Number");
        }
        else {
            System.out.println("B is a Big Number");
        }
    }
}
--------------------------------------------
3) Execute a block of statements when a Compound condition is true.

Syntax:

if ((condition1) && or || (condition2)) {
Statements
----------
----------
----------
}

Example:

public static void main (String [] args){
        int a, b, c;
        a = 10; b= 7; c = 5;
       
        if ((a > b) && (a > c)) {
            System.out.println("A is a Big Number");
        }
    }
--------------------------------
public static void main (String [] args){
        int a, b, c;
        a = 10; b= 7; c = 15;
       
        if ((a > b) || (a > c)) {
            System.out.println("A is a Big Number");
        }
    }
------------------------------------
4) Decide among several alternates (else if)

Syntax:

if (condition) {
Statements
---------
---------
--------
}
else if (condition) {
Statements
---------
---------
--------
}
else if (condition) {
Statements
---------
---------
--------
}
else {
Statements
----------
---------
}

Example:

Requirement:
Verify the range of a value

Conditions:
if the value is in between 1 to 100 then display value is a Small number
if the value is in between 101 to 1000 then display value is a Medium number
if the value is in between 1001 to 10000 then display value is a Big number
Otherwise display the value is either zero or negative value

Program:

    public static void main (String [] args){
        int val = -100;
    if ((val >= 1) && (val <=100)) {
        System.out.println("Value is a Small Number");
    }
    else if ((val > 100 ) && (val <=1000)) {
        System.out.println("Value is a Medium Number");
    }
    else if ((val > 1000 ) && (val <=10000)) {
        System.out.println("Value is a Big Number");
    }
    else {
        System.out.println("Value is Either Zero or Negative Number");
    }
}
--------------------------------------
v) Execute a Block of statements when more than one condition is True (Nested If)

Syntax:

if (condition) {
 if (condition) {
  if (condition {
Statements
--------
--------
}
}
}

Example:

public static void main (String [] args){
        int a = 100, b = 90, c = 70, d = 50;
   
        if (a > b){
         if (a > c){
          if (a > d) {
              System.out.println("A is a Big Number");
          }
         }
        }
}
------------------------------
public static void main (String [] args){
        int a = 100, b = 90, c = 70, d = 50;
   
        if (((a > b) && (a > c) && (a > d))) {
          System.out.println("A is a Big Number");
          }
}
----------------------------------
Difference between Compound and Nested Conditions

If it is Compound condition we can write single else part only.

If it is Nested condition we can write multiple else parts.
----------------------------------------------------
vi) Decide among several alternates (switch statement)

Syntax:

switch (expression) {

case value:
Statements
----------
----------
break;
case value:
Statements
----------
----------
break;
case value:
Statements
----------
----------
break;
default:
Statements
----------
-----
}

example:

public static void main (String [] args){
        char grade = 'Z';
       
        switch (grade){
        case 'A':
            System.out.println("Excellent");
            break;
        case 'B':
            System.out.println("Well Done");
            break;
        case 'C':
            System.out.println("Better");
            break;
        default:
            System.out.println("Invalid Grade");
        }
}
------------------------------------------------------
Java Flow Control Statements
    Conditional Statements
    Loop Statement

i) We can use conditional statements only in our programs.

ii) We can use Loop statements only in our programs.

iii) We can use Conditional statements and Loop statements together.
---------------------------------------------------------------
VII) Loop Statements
 

Whenever we want execute a block of statements multiple times then we use Loop structures.

There are four types of Loop structures in Java.

i) for loop

ii) while loop

iii) do while loop

iv) Enhanced for loop
---------------------
i) for loop

Description:

It repeats a block of statements for a specified number of times.

Syntax:

for (startvalue; endvalue; increment/Decrement){
Statements
----------
----------
----------
}

Example: Print 1 to 10 Numbers

public static void main (String [] args){
       
        for (int i = 1; i <= 10; i++){
            System.out.println(i);
        }
        }
---------------------------------------------------
Example: Print 10 to 1 Numbers

public static void main (String [] args){
       
        for (int i = 10; i >= 1; i--){
            System.out.println(i);
        }
        }
-----------------------------------
Example: Print 1 to 10 Numbers, except 4th and 7th numbers

public static void main (String [] args){
       
        for (int i = 1; i <= 10; i++){
            if ((i != 4) && (i != 7)) {
            System.out.println(i);
            }
        }
        }
-------------------------------------------------
ii) While loop

It repeats a block of statements while condition is True.

Syntax:

Initialization
while (condition) {
statements
----------
----------
----------
increment / decrement
}

Example1: Print 1 to 10 Numbers

public static void main (String [] args){
        int i = 1;
        while (i <= 10){
            System.out.println(i);
            i++;
        }
        }
---------------------------------
Example2: print 10 to 1 Numbers


public static void main (String [] args){
        int i = 10;
        while (i >= 1){
            System.out.println(i);
            i--;
        }
        }
-------------------------------------------
Example3: print every 10th Number up to 100

    public static void main (String [] args){
        int i = 10;
        while (i <= 100){
            System.out.println(i);
            i = i + 10;
        }
        }
---------------------------------------------------
Example4: Print 1 to 10 Numbers, except 4th and 7th numbers

public static void main (String [] args){
        int i = 1;
        while (i <= 10){
            if ((i != 4) && (i != 7)){
            System.out.println(i);
            }
            i++;
        }
                }
----------------------------------------------------       
iii) do while loop

It repeats a block of statements while condition is true.
It executes statements at least once irrespective of the condition.

Difference between while loop and do while loop:
---------------------------------------------
while loop first checks the condition, if condition is true then it will execute the statements.

do while loop first executes the statements then it will check the condition, if condition
is true, it will continue otherwise come out from the loop.
------------------------------------------------------
Syntax:

Initialization
do
{
Statements
----------
----------
----------
increment/decrement
} while (condition);

Example:

public static void main (String [] args){
        int i = 1;
        do
        {
        System.out.println(i);   
            i++;
        }
        while (i <= 10);
        }
---------------------------------
public static void main (String [] args){
        int i = 11;
        do
        {
        System.out.println(i);   
            i++;
        }
        while (i <= 10);
        }
--------------------------------------
iv) Enhanced for loop

It executes all elements in an Array.

Syntax:

Array declaration
for (declaration: expression/Array) {
Statements
---------
}

Example:

public static void main (String [] args){
        String [] languages = {"C", "COBOL", "Java"};
        for (String lang: languages){
            System.out.println(lang);
        }
        }
Example2:
public static void main (String [] args){
        int [] mathoperations = new int[3];
        int a = 10, b =20;
        mathoperations[0] = a+b;
        mathoperations[1] = a-b;
        mathoperations[2] = a*b;
        for (int operation: mathoperations){
            System.out.println(operation);
        }
        }
------------------------------------------------------------
VIII) String Handling in Java
 

What is String?

String is a sequence of character written double quotes.

String may have Alfa bytes, numbers and special characters.

Example:
System.out.println("Selenium Testing"); // selenium Testing
System.out.println("123 Selenium"); // 123 Selenium
System.out.println("Selenium*&123Testing");//Selenium*&123Testing

Creating strings:

String is considered Object in Java.

Ex:
public static void main (String [] args){
    String myTool = "Selenium"; // String variable
    String [] myTools =    {"UFT", "Selenium", "LoadRunner"}; //Array of Strings
   
    System.out.println(myTool);//Selenium
   
    for (String tool: myTools){
        System.out.println(tool);//Print Array of Strings
    }
}
---------------------------------
Concatenating Strings:

public static void main (String [] args){
    String str1 ="selenium";
    String str2 =" Testing";
    System.out.println(str1 + str2);//Selenium Testing
    System.out.println("Selenium" + " Testing"); // Selenium Testing
    System.out.println(1 + 1 + "Selenium");//2Selenium
    System.out.println("Selenium" + 1 + 1);//Selenium11
    }
-----------------------------------
String Comparison:
-------------------------------
i) String comparison using (==) operator.

It supports 2-way comparison (true/false)

ii) String comparison using equals() method

It supports 2-way comparison (true/false)

iii) String comparison using compareTo() method

It supports 3-way comparison (0, >1, <1)

if str1 == str2 then 0
if str1 > str2 then > 1 (Positive value)
if str1 < str2 then < 1 (Negative value)

ANSI character codes

A to Z (65 to 90)
a to z (97 to 122)
0 to 9 (48 to 57)

Example:

public static void main (String [] args){
    String str1 ="SELENIUM";
    String str2 ="selenium";
    String str3 ="SELENIUM";
    String str4 ="zselenium";
   
    //String comparison using == Relational operator
    System.out.println(str1 == str2);//false
    System.out.println(str1 == str3);//true
   
    // String comparison using equal() method
    System.out.println(str1.equals(str2));//false
    System.out.println(str1.equals(str3)); // true
   
    // String comparison using compareTo() method
    System.out.println(str1.compareTo(str3)); //0
    System.out.println(str2.compareTo(str1)); //Positive value
    System.out.println(str1.compareTo(str4)); //Negative value
        }
--------------------------------------------------
IX) Java Arrays
 

i) Introduction

> Java Array is an Object that holds a fixed number of values of a single data type.

> The length of an Array is established when the Array is created.

> Array length is fixed, Java Array has Zero based index.
------------------------------------
ii) Declaration of Arrays
--------------------------
1st method:

int abc []; // Creating Array
    abc = new int [4]; // Define Size
    abc[0] = 10; // Assign Values
    abc[1] = 20;
    System.out.println(abc[0] + abc[1]);//30
------------------
int abc []; // Creating Array
    abc = new int [4]; // Define Size
    abc[0] = 10; // Assign Values
    abc[1] = 20;
    abc[4] = 40; //Error
    System.out.println(abc[0] + abc[1]);//30
--------------------------------------
2nd Method

int [] abc = new int [5]; // Creating an Array with Size
    abc[0] = 10;
    abc[1] = 20;
    System.out.println(abc[1] + abc[2]); //20
------------------------------------------------
3rd Method

int [] abc = {10, 20, 30, 40, 50};
    System.out.println(abc[1] + abc[2]); //50   
--------------------------------------
iii) Creating diffiernt types of Arrays

char [] abc = {'A', 'B', 'c'}; //Array of Characters
    int [] xyz = {10, 20, 30, 40}; //Array of Integers
    String [] a = {"Selenium", "UFT", "LoadRunner"}; //Array of Strings
    boolean [] b = {true, false, false, true}; // Array of Boolean values
   
    System.out.println(abc[1]); //B
    System.out.println(xyz[0]);//10
    System.out.println(a[1]);//UFT
    System.out.println(b[2]);//false
---------------------------------------------
iv) Copy values an Array into another Array

int [] array1 = {1, 2, 3, 4, 5};
    int [] array2 = array1;
    System.out.println(array2[2]); //3
    for (int i = 0; i < array2.length; i++){
        System.out.println(array2[i]);
    }
-----------------------------------
v) Types of Arrays

i) Single Dimensional Array

ii) Multi Dimensional Array

int [] array1 = {1, 2, 3, 4, 5};
    int [] [] array2 = {{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}; //Multi dimensional Array
    System.out.println((array2[0][0]));//1
    System.out.println((array2[1][0]));//2
    System.out.println((array2[0][4]));//9
    System.out.println((array2[1][3]));//8
    System.out.println((array2[1][4]));//10
    System.out.println((array2[0][2]));//5
    System.out.println((array2[1][2]));//6
--------------------------------
Assignment

Print multi dimensional Array values using nested for loop
--------------------------------------------------------
vi) Advantages & Disadvantages of Arrays

Advantages:

i) Using Arrays we can optimize the code, data can be retrieved easily.

ii) We can get required data using index position.

Disadvantages

i) We can store fixed number of elements only.

ii) It doesn't change its size during execution.
----------------------------------------------
X) Java Methods
i) Introduction

What is Method?

A set of statements to perform an Operation.

Methods also known as Procedures or Functions.

In Structure programming we use Functions (Built in and User defined)

In Object Oriented programming we use Methods (Built in and User defined)

Functions Vs. Methods
-----------------------
Functions are standalone things can be used individually.

Methods are generally associated with objects, but without object also we can call methods in Java.

Types of Methods:

Basically we have two types of Methods

i) Built in Methods

ii) User defined Methods.
------------------------------------
i) Built in Methods

> Java has a library of classes and methods, organized in packages.

Ex:

import java.io.Console;
import java.io.*;

> In order to use built in methods we need to import packages or particular classes.

> java.lang package is automatically imported in any Java program.

> using import keyword we can import packages/classes.
-------------------------------------
Categories of Built in Methods

i) String methods

ii) Character methods

iii) Number methods

iv) Array methods
etc...
------------------------------------
User defined Methods
Two types of User defined methods

i) Method without returning any value

ii) Method with returning a value
----------------------------------------
Writing methods (with returning value)

a) Syntax for creating a method and calling the method without invoking any object:


accessmodifier nonaccessModifier returnType methodName(parameters){
Statements
----------
----------
----------
}

b) Syntax for Creating a method and calling the method with invoking object:

accessModifier returnType methodName(Parameter){
Statements
---------
---------
----------
}
---------------------------

Example:
public static int add (int a, int b){ // Creating a Method
        int result;
        result =  a +  b;
        return result;
    }
------------------------
Calling a Method with Returning a Value

Syntax:
dataType variableName = methodName(values);

example:

int xyz = add(123, 456); // Calling a Method
-----------------------------------------------
public static int multiply (int a, int b, int c){
        int result;
        result = a * b * c;
        return result;
}
public static void main (String [] args){
int a = multiply(2, 4, 6);
System.out.println(a);
}
-------------------------------------
Creating and Calling Methods using Object

Creating Objects

Synatx:

className objectName = new className();

Example:

JavaArrays obj = new JavaArrays();
----------------------------------
public int multiply (int a, int b, int c){
        int result;
        result = a * b * c;
        return result;
}
public static void main (String [] args){

    JavaArrays obj = new JavaArrays();
    int a = obj.multiply(2, 4, 6);
    System.out.println(a);
}
-----------------------------------------
ii) Method without returning any Value

a) Syntax for Creating a method and calling the method without invoking any object:

acessModifier nonaccessModifier retrunType nothing methodname(parameters){
Statements
---------
-----------
------------
}
Example:
public static void studentRank (int marks){
        if (marks >= 600) {
            System.out.println("Rank A");
        }
        else if (marks >= 500){
            System.out.println("Rank B");
        }
        else
            System.out.println("Rank C");
        }

public static void main (String [] args){
    studentRank(450);
    }
       
}
-----------------------------------
b) Syntax for Creating a method and calling the method with invoking object:

accessModifier retrunType nothing methodName(parameters){
Statements
------------
-----------
----------
}

Example:

public  void studentRank (int marks){
        if (marks >= 600) {
            System.out.println("Rank A");
        }
        else if (marks >= 500){
            System.out.println("Rank B");
        }
        else
            System.out.println("Rank C");
        }

public static void main (String [] args){
    JavaArrays xyz = new JavaArrays();
    xyz.studentRank(450);
    }
-------------------------------
// Calling a method from another class

public static void main(String [] args){
        JavaArrays abc = new JavaArrays();
        abc.studentRank(650);
    }
------------------------
public static void main(String [] args){
        studentRank(650);
    }
--------------------------------------------
Creating User defined methods

    i) Creating a Method with returning a value

    ii) Creating a Method without returning any value
------------------------------------
Calling User defined methods

    i) Calling a method with returning a value and without invoking object
    ii) Calling a method with returning a value and with invoking object
    iii) Calling a method without returning any value and without invoking object
    iv) Calling a method without returning any value and with invoking object
    v) Calling an external method without invoking object
    vi) Calling an external method with invoking object
----------------------------------------
Method Overloading
------------------
Two or more methods with same name, but with different parameters
(different number of parameters or different data types)

i) by changing different number of parameters

a) int add (int a, int b)

b) int add (int a, int b, int c)

Example:

public static int add (int a, int b){
        int result;
        result = a+b;
        return result;
    }
public static int add (int a, int b, int c){
    int result;
    result = a + b + c;
    return result;
}
public static void main (String [] args){
    int a = add (10, 20);
    int b = add (10, 20, 30);
    System.out.println(a);//30
    System.out.println(b);//60
}
----------------------------------------
ii) by changing data types

public static int add (int a, int b){
        int result;
        result = a+b;
        return result;
    }
public static double add (double a, double b){
    double result;
    result = a + b;
    return result;
}
public static void main (String [] args){
    int a = add (10, 20);
    double b = add (1.234, 2.4567);
    System.out.println(a);//30
    System.out.println(b);//
}
--------------------------------------
Method Overriding

if two methods with same name and same number of arguments available in super class
and sub class, then we call those two methods are overridden.

Example:

Super class

int a = 10, b = 20;
public int add (){
    int result;
    result = a+b;
    return result;
    }

Sub Class

    int a = 100, b = 200;
    public int add (){
        int result;
        result = a+b;
        return result;
    }
   public static void main(String [] args){
       MethodOverloading2 xyz = new MethodOverloading2();
       int x = xyz.add();
       System.out.println(x); // 300
      
       MethodOverloading abc = new MethodOverloading();
       int y = abc.add();
       System.out.println(y);//30
   }
---------------------------------------
XI) Java Built in Methods
Categories of Built in Methods

i) String methods

ii) Number methods

iii) Character methods

iv) Array methods etc...
--------------------------------
i) String methods

1) compareTo() method (It compares two strings) - 3 way comparison

if str1 = str2 then 0
if str1 > str2 then positive value
if str1 < str2 then negative value

Ex:

 public static void main(String [] args){
String str1 = "SELENIUM";
String str2 = "selenium";
String str3 = "seleniuma";
String str4 = "selenium";

System.out.println(str1.compareTo(str2));
System.out.println(str3.compareTo(str2));
System.out.println(str2.compareTo(str4)); //0
   }

2) equals() method (It compares two strings) - 2 way comparison

 public static void main(String [] args){
String str1 = "SELENIUM";
String str2 = "selenium";
String str3 = "selenium";

System.out.println(str1.equals(str2)); //false
System.out.println(str2.equals(str3)); //true
 }
------------------------------------------------------
3) concat() Method (It concatenates / joins two strings)

 public static void main(String [] args){
String str1 = "Selnium";
String str2 = " Testing";

System.out.println(str1.concat(str2)); //Selenium Testing
 }
------------------------------------------
4) charAt() Method (Returns a character by position)

Example:

 public static void main(String [] args){
String str1 = "Selnium";

System.out.println(str1.charAt(1)); //e
 }
--------------------------------
5) equalsIgnorecase() method

Examples:

 public static void main(String [] args){
String str1 = "SELENIUM";
String str2 = "selenium";
String str3 = "UFT";

System.out.println(str1.equalsIgnoreCase(str2)); //true
System.out.println(str1.equalsIgnoreCase(str3)); //false
System.out.println(str1.equals(str2)); //false
 }
----------------------------------------
6) toUppercase() method (Converts values to Upper case)

Example:

public static void main(String [] args){
String str1 = "slenium";
String str2 = "SELEnium";
String str3 = "SELENIUM";
String str4 = "selenium123";

System.out.println(str1.toUpperCase()); //SELENIUM
System.out.println(str2.toUpperCase()); //SELENIUM
System.out.println(str3.toUpperCase()); //SELENIUM
System.out.println(str4.toUpperCase()); //SELENIUM123
}
------------------------------
7) toLowercase() Method (Converts values to Lower case)

Example:

public static void main(String [] args){
String str1 = "slenium";
String str2 = "SELEnium";
String str3 = "SELENIUM";
String str4 = "selenium123";

System.out.println(str1.toLowerCase()); //selenium
System.out.println(str2.toLowerCase()); //selenium
System.out.println(str3.toLowerCase()); //selenium
System.out.println(str4.toLowerCase()); //selenium123
}
-------------------------------------
8) trim() method (Removes spaces from both sides of a string)

Example:
public static void main(String [] args){
String str1 = "            Selenium               ";

System.out.println(str1);
System.out.println(str1.trim());
}
----------------------------------
9) substring method (Returns sub string)

Example:

public static void main (String [] args) {
        String str = "Welcome to Selenium Testing";
        System.out.println(str.substring(11));//Selenium Testing
        System.out.println(str.substring(20));//Testing
        System.out.println(str.substring(11, 19));//selenium
   
    }
------------------------
10) endswith (ends with specified suffix)

Example:
public static void main (String [] args) {
    String str = "Welcome to Selenium Testing";
    System.out.println(str.endsWith("Selenium Testing"));//true
    System.out.println(str.endsWith("Selenium"));//false
    System.out.println(str.endsWith("Testing"));//true
    System.out.println(str.endsWith("ing"));//true
    }
----------------------------------------------------
In Computer Programming we have 3 types of Results

a) Value based Result, ex: 3 + 5 = 8

b) Boolean or Logical Result, ex: true/false

c) Constant based Result, ex: 0, 1, -1
-------------------------------------

ii) Number Methods

1) compareTo() method

Result Criteria:

if the integer is equal to the Argument then 0
if the integer is less than the Argument then -1
if the integer is greater than the Argument then 1
-------------------------------------------------
Example:
public static void main (String [] args) {
    Integer a = 5;
    System.out.println(a.compareTo(8));//-1
    System.out.println(a.compareTo(5));//0
    System.out.println(a.compareTo(4));//1
    }
----------------------------------
2) equals Method

public static void main (String [] args) {
    Integer a = 5;
    System.out.println(a.compareTo(8));//-1
    System.out.println(a.compareTo(5));//0
    System.out.println(a.compareTo(4));//1
    }
----------------------------------
3) abs (Returns absolute value)

double a = 10.234;
double b = -10.678;
    System.out.println(Math.abs(a));//10.234
    System.out.println(Math.abs(b));//10.676
-----------------------------------
4) round (Rounds the value to nearest integer)

ex:

double a = 10.234;
double b = -10.678;
    System.out.println(Math.round(a));//10
    System.out.println(Math.round(b));//-11
---------------------------------------
5) min (Returns minimum value between two numbers)

Example:

public static void main (String [] args) {
    int a = 10, b = 20;
    double c = 2.345, d = 2.3451;
    System.out.println(Math.min(a, b));//10
    System.out.println(Math.min(c, d));//2.345
    System.out.println(Math.min(5, 7));//5
    System.out.println(Math.min(1, 1));//1
    }
---------------------------------------
6) max (Returns maximum value between two numbers)

public static void main (String [] args) {
    int a = 10, b = 20;
    double c = 2.345, d = 2.3451;
    System.out.println(Math.max(a, b));//20
    System.out.println(Math.max(c, d));//2.3451
    System.out.println(Math.max(5, 7));//7
    System.out.println(Math.max(1, 1));//1
    }
--------------------------------
7) random (Generates random Number)

example:

public static void main (String [] args) {
   
    System.out.println(Math.random());//
    System.out.println(Math.random());//
    }
---------------------------------------
iii) Character methods

i) isLetter (Checks weather the value is Alfa byte or not?)

public static void main (String [] args) {
    char a ='1';
    char b ='A';
    System.out.println(Character.isLetter(a));//false
    System.out.println(Character.isLetter(b));//true
    System.out.println(Character.isLetter('Z'));//true
    System.out.println(Character.isLetter('z'));//true
    }

---------------------------------
ii) isDigit (Returns weather the value is Number or not?)

public static void main (String [] args) {
    char a ='1';
    char b ='A';
    System.out.println(Character.isDigit(a));//true
    System.out.println(Character.isDigit(b));//false
    System.out.println(Character.isDigit('5'));//true
    System.out.println(Character.isDigit('z'));//false
    System.out.println(Character.isDigit('*'));//false
}
------------------------------------
iii) isUppercase (Checks weather the value is Upper case or not?)

public static void main (String [] args) {
       
    System.out.println(Character.isUpperCase('A'));//true
    System.out.println(Character.isUpperCase('a'));//false
        }       
--------------------------------
iv) isLowecase (Checks weather the value is Lower case or not?)

public static void main (String [] args) {
       
    System.out.println(Character.isLowerCase('A'));//false
    System.out.println(Character.isLowerCase('a'));//true
        }
-----------------------------------
iv) Array Methods

i) length

public static void main (String [] args) {
    int [] array1 = {10, 20, 30, 40, 50};
    System.out.println(array1.length);//5
        }

----------------------------------
toString() (print Array)

public static void main (String [] args) {
    String [] array1 = {"Selenium", "UFT", "RFT", "LoadRunner"};
    String str = Arrays.toString(array1);
    System.out.println(str);
        }
----------------------------
contains() (Checks if the Array contains certain value or not?)

Ex:

public static void main (String [] args) {
    String [] array1 = {"Selenium", "UFT", "RFT", "LoadRunner"};
    boolean a = Arrays.asList(array1).contains("UFT");
    boolean b = Arrays.asList(array1).contains("QTP");
        System.out.println(a);//true
        System.out.println(b);//false
            }
----------------------------------
XII) Exception Handling in Java
 

> An exceptions is an event, which occurs during execution of a program

> Exception handling is mechanism to handle exceptions

Common Scenarios where exceptions may occur
-------------------------------------------
1) Scenario where ArithemeticException occurs.

If we divide any number by zero then ArithemeticException occurs.

Ex:

int a = 10/0;

2) Scenario where NullPointerException occurs.

If we have null value in any variable, performing any operation by the variable.

Ex:

String s = null;
System.out.println(s.length()); //NullPointerException

3) Scenario where NumberFormatException occurs.

Ex:

String s ="123";
int y = Integer.parseInt(s);
System.out.println(y); //NumberFormatException

4) Scenario Where ArrayIndexOutofBounds exception occurs.

If we are assigning any value in the wrong index.

Ex:

int [] a =  new int [5];

a[10] = 100;
System.out.println(a[10)); //ArrayIndexOutofBounds exception
-------------------------------------------------------------
Ex:
public static void main (String [] args) {
    int a = 10;
    int b = 0;
    int result;
   
    result = a/b;
    System.out.println(result);
    System.out.println("Hello Java");
    System.out.println("hello Selenium");
    }
--------------------------------------
Use try block

Syntax:

try {
Statements
----------
-----------
---------
}
catch (exception e) {
Exception handling code
}
---------------------------------------
public static void main (String [] args) {
    int a = 10;
    int b = 0;
    int result;
   
    try {
    result = a/b;
    System.out.println(result);
    }
    catch (ArithmeticException e) {
        System.out.println("Divided by Zeo Error");
    }
    System.out.println("Hello Java");
    System.out.println("Hello Selenium");
    }
------------------------------------------
Multiple try blocks for handling multiple exceptions

public static void main (String [] args) {
    int a = 10;
    int b = 0;
    int result;
    int [] array = new int [4];
   
    try {
    result = a/b;
    System.out.println(result);
    }
    catch (ArithmeticException e) {
        System.out.println("Divided by Zeo Error");
    }
    System.out.println("Hello Java");
   
    try {
    array[10] = 100;
    System.out.println(array[10]);
    }
    catch (ArrayIndexOutOfBoundsException e){
        System.out.println("Array Out of bound Error");
    }
    System.out.println("Hello Selenium");
    }
------------------------------------------------------
IO Operations in Java
 

Output on the Console

System.out.println ();

System.out.println(a); //100
System.out.println("Selenium Testing");//Selenium Testing
System.out.println("Selenium Testing " + a);
System.out.println("Selenium Testing " + " Java programming");
---------------------------------
Input

There are 3 ways available for reading input.

i) Scanner

ii) DataInputStream

iii) BufferedReader
--------------------------
using java.util.Scanner is the easier and includes methods to check the input data.

public static void main (String [] args) {
     Scanner scan = new Scanner(System.in);
    
     System.out.println("Enter Your Name");
     String s1 = scan.nextLine();
     System.out.println("Your name is: " + s1);
   
     System.out.println("Enter Your City");
     String s2 = scan.next();
     System.out.println("Your City is: " + s2);
   
     System.out.println("Enter a Number");
     int i = scan.nextInt();
      System.out.println("Value is: " + i);
     
     System.out.println("Enter Your Phone Number");
     long s3 = scan.nextLong();
     System.out.println("Your City is: " + s3);
    
     System.out.println("Read a Value");  
     double b = scan.nextDouble();
     System.out.println("Value is "+ b);
    
     scan.close();
         }
---------------------------------
File Handling in Java
 

Using File class we can perform File operations

Examples:

1) Create a Folder

public static void main (String [] args) {
    File abc = new File ("C:/Users/gcreddy/Desktop/Selenium");
    abc.mkdir();
    }
--------------------------
2) Check the existence of Selenium folder

public static void main (String [] args) {
    File abc = new File ("C:/Users/gcreddy/Desktop/Selenium");
    boolean a = abc.exists();
    System.out.println(a); //true
    }
----------------------------------------------
3) Delete a Folder

public static void main (String [] args) {
    File abc = new File ("C:/Users/gcreddy/Desktop/Selenium");
    abc.delete();
    boolean a = abc.exists();
   
    if (a == true){
        System.out.println("Folder exists");
    }
    else
    {
        System.out.println("Folder Not exists");   
    }
   
    }
-----------------------------------------------
4) Create a Text file

public static void main (String [] args) {
    File abc = new File ("C:/Users/gcreddy/Desktop/Selenium.txt");
    try {
        abc.createNewFile();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
-----------------------------
5) Delete a Text file

public static void main (String [] args) {
    File abc = new File ("C:/Users/gcreddy/Desktop/Selenium.txt");
    abc.delete();
}
---------------------------------------------
Java OOPS Concepts
 

OOPS - Object Oriented Programming System.

Four fundamentals of OOPS:

i) Inheritance

ii) Polymorphism

iii) Abstraction

iv) Encapsulation
----------------------------------------------
Java OOPS: Inheritance
 

> It is a process of Inheriting (reusing) the class members (Variables and Methods) from one class to another class is called Inheritance.

> Non static (Object Level) class members only can be inherited.

> The class where the class members are getting inherited is called as Super class / parent class / Base class.

> The class to which the class members are getting inherited is called Sub class / Child class / Derived class.

> The inheritance between Super class and Sub class is achieved using "extends" keyword.
------------------------------
How to create static class members?

Using static non access modifier.

How to use Static class members?

Using Class name we can access static class members.

How to use Non static class members?

Using Object/Instance we can access Non static class members.


Creating object in a class

Syntax:

ClassName InstanceVariable = new ClassName();

example for accessing static and non static class members:
----------------
static int a = 10, b = 20; // Static variables
    int c = 30, d = 40; // Non static variables
   
    public static void add() { //static Method
        System.out.println("Addition of a, b is: " + (a+b));
    }
   
    public void add2() { //Non static method
        System.out.println("Addition of c, d is: " + (c+d));
    }
public static void main (String [] args) {
    // Access Static class members using class name
    System.out.println(FileHandling.a);//10
    FileHandling.add();//30
   
    //Access Non static class members using Object/Instance
    FileHandling obj = new FileHandling();
    System.out.println(obj.c);//30
    obj.add2();//70
}
--------------------------------------------------
Three types of Inheritance

i) Single Inheritance

Ex:

class B extends class A {
--------------------------------
ii) Multi level Inheritance

ex:

Class B extends class A {

Class C extends class B {

iii) Multiple Inheritance (* Java doesn't support)

Ex:

Class B extends Class A {

Class B extends Class D {
----------------------------
Class 1:

public class A {
int a = 10;
int b = 20;
public void addition() {
    System.out.println("Addition of a, b is: " + (a+b));
}
public void subtraction() {
    System.out.println("Subtraction of a, b is: " + (a-b));
}
public static void main (String [] args){
    A myObject = new A();
    System.out.println(myObject.a);//10
    myObject.addition();//30
}
}
-------------------------
Class 2

public class B extends A {
    int a = 100;
    int b = 200;
    public void addition() {
        System.out.println("Addition of a, b is: " + (a+b));
    }
public static void main (String [] args){
    A obj1 = new A ();
    obj1.addition(); //30
    obj1.subtraction();//-10
   
    B obj2 = new B();
    obj2.addition();//300
}
}
-------------------------------------
Class 3

public class C extends B {
    int a = 1;
    int b = 2;
    public void addition() {
        System.out.println("Addition of a, b is: " + (a+b));
    }
public static void main (String [] args){
    //Accessing class members from Home class
    C obj1 = new C();
    System.out.println(obj1.a); //1
    obj1.addition();//3
   
    //Accessing class members from parent class
    B obj2 = new B();
    obj2.addition();//300
   
  //Accessing class members from Grandparent class
    A obj3 = new A();
    obj3.addition(); // 30
}
}
----------------------------------------------------
Java OOPS: Polymorphism
 

Polymorphism means, existence of Object behavior in many forms

There are two types of Polymorphism

i) Compile Time Polymorphism / Static binding / Method overloading

ii) Run Time Polymorphism / Dynamic binding / Method overriding

i) Compile Time Polymorphism
If two or more methods having same name in the same class but they differ in the following ways.

i) Number of Arguments

ii) Type of Arguments

public class MethodOverloading {
    public void add(int a, int b){
        System.out.println(a+b);
    }
    public void add(int a, int b, int c){
        System.out.println(a+b+c);
    }
    public void add(double a, double b){
        System.out.println(a+b);
    }
    public void add(double a, double b, double c){
        System.out.println(a+b+c);
    }
    public static void main (String [] args){
        MethodOverloading obj = new MethodOverloading();
        obj.add(10, 20);
        obj.add(10, 20, 30);
        obj.add(1.2345, 2.3456);
        obj.add(1.2345, 2.3456, 4.45678);
    }
}
-----------------------------------------
ii) Run Time Polymorphism
If two or more methods having same name and same arguments available in the super class and sub class.

Example:

Class 1

public class A {

public void addition(int a, int b) {
    System.out.println(a+b);
}
public static void main (String [] args){
    A myObject = new A();
    myObject.addition(10, 20);//30
}
}
------------------------------
Class 2

public class B extends A {
    public void addition(int a, int b) {
        System.out.println(a+b);
    }
public static void main (String [] args){
    A obj1 = new A ();
    obj1.addition(10, 20); //30
       
    B obj2 = new B();
    obj2.addition(40, 50);//90
}
}
--------------------------------------------------
Java OOPS: Abstraction
 

It is a process of hiding implementation details and showing only functionality to the user.

In java we have two types of methods

i) Concrete methods (The methods which are having body)

ex:

public void add(){
Statements
---------
--------
---------
}

ii) Abstract methods (The methods which are not having body)

Ex:

public void add();
-------------------------------------------------
if we know the method name, but don't know the method functionality,
then we go for abstract methods.

Java Class contains 100% concrete methods

Abstract Class contains one or more abstract methods.

Ex:

Class 1 (having 10 methods)

(10 methods are concrete methods)

It is a Java Class
-------------------------
Class 2 (having 10 methods)

(5 concrete Methods and 5 abstract methods)

Abstract class
--------------------------
Class 3 (having 10 methods)

(10 methods are Abstract methods)

Abstract class
----------------------------------
public class HeroHonda extends Bike {

    @Override
    public void handle() {
        System.out.println("Bikes have handle");
        }
    @Override
    public void seat() {
        System.out.println("Bikes have Seat");
    }
    public static void main (String [] args){
        HeroHonda obj = new HeroHonda();
        obj.handle();
        obj.engine();
        obj.seat();
    }
-------------------------------------------
Selenium IDE has User interface

Selenium Webdriver is a Programming Interface

UFT has IDE and Programming Interface

Java Interfaces
 

> Interface is a Java type definition block which is 100% abstract.

> All the Interface methods are by default public and abstract.

> Static and final modifiers are not allowed for interface methods.

> In Interfaces variables have to initialize at the time of declaration.

int a; // Incorrect

int a = 10; // Correct

> In interfaces variables are public static final by default.

> Interface is going to be used using "implements" keyword.
--------------------------------------------
Ex:

public class Exa3 implements Example1{

    @Override
    public void add() {
        System.out.println("Addition");
        }

    @Override
    public void sub() {
        System.out.println("Subtraction");
        }
public static void main (String [] args){
    Exa3 abc = new Exa3();
    abc.add();
    abc.sub();
}
}
--------------------------------------------------------
From Class (Concrete Class or Abstract Class) to Class we use "extends" keyword

i) From Concrete Class to Sub class - we can access Super class methods directly.

ii) From Abstract Class to Sub class - Implement all abstract methods then we can access all methods.
----------------------------------------------
From Interface to Class we use "implements" keyword

From Interface to Class - Implement all methods and access.
--------------------------------------
Java OOPS: Encapsulation
 

It is a process of wrapping code and data into a single unit.

Encapsulation is the technique making the fields in a class private and providing access via public methods

> It provides us control over the data

> By providing setter and getter methods, we can make a class read only or write only.

> If we don't define setter method then read only.

Example:

Class 1:
public class Class1 {
    private String name = "Test Automation";
   
    public String getName(){
        return name;
    }
   
    public void setName (String newName){
        name = newName;
    }
}
-------------------------
Class 2:

public class Class2 extends Class1 {

    public static void main(String[] args) {
        Class1 obj = new Class1();
        //obj.setName("Selenium");
        System.out.println (obj.getName());
    }
}
----------------------------------