Anda di halaman 1dari 23

TESTING

www.thetestingworld.com Call/Whatsapp - 874391 3121


WORLD

SoapUI Video : https://www.udemy.com/soapui-with-groovy-with-realtime-


projects/?couponCode=NI

Jmeter Video: https://www.udemy.com/basic-to-expert-jmeter/?couponCode=MyTT

Unix & Shell Scripting for Testers : https://www.udemy.com/unixfortesters/?couponCode=15d

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

Advantage of Selenium over QTP

1 Free (No license fees is required)


2 Support large number of browser(QTP support only 3)
3 Support large number of programming language(C#, Java, Python, Perl etc), QTP support only VB script
4 With the help of grid we can execute multiple test cases in parallel, ultimately we are saving lot of execution
time, this kind of feature not available in QTP

Advantage of QTP over Selenium

1 User Friendly, Easy to work on


2 Can develop test cases in much faster way as compared to Selenium
3 Support all type of application(client-server, window , web)
4 Limited programming skills are required

Difference between Selenium IDE, RC and WebDriver

Selenium IDE Selenium RC Selenium WebDriver


It only works in Mozilla It supports with all browsers It supports with all browsers
browser. like Firefox, IE, Chrome, Safari, like Firefox, IE, Chrome, Safari,
Opera etc. Opera etc.
It supports Record and It doesnt supports Record and It doesnt supports Record and
playback playback playback
Doesnt required to start server Required to start server before Doesnt required to start server
before executing the test script. executing the test script. before executing the test script.
It is a GUI Plug-in It is standalone java program It actual core API which has
which allow you to run Html binding in a range of languages.
test suites.
Core engine is Javascript based Core engine is Javascript based Interacts natively with browser
application
Very simple to use as it is It is easy and small API As compared to RC, it is bit
record & playback. complex and large API.
It is not object oriented APIs are less Object oriented APIs are entirely Object
oriented
It doesnt supports of moving It doesnt supports of moving It supports of moving mouse
mouse cursors. mouse cursors. cursors.
Need to append full xpath with Need to append full xpath with No need to append full xpath
xpath=\\ syntax xpath=\\ syntax with xpath=\\ syntax
It does not support to test It does not support to test It support to test
iphone/Android applications iphone/Android applications iphone/Android applications

Commands to Create Webdriver object for different browsers


www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

Firefox
FirefoxDriver driver = new FirefoxDriver();

Chrome Driver
System.setProperty("webdriver.chrome.driver", "path of chrome driver executable");
ChromeDriver driver = new ChromeDriver();

IE Driver
System.setProperty("webdriver.ie.driver", "path of ie driver executable");
InternetExplorerDriver driver = new InternetExplorerDriver();

All Supported Element Locators in Selenium

Element Locator Supported in Webdriver Supported in RC


Id findElementById id=

Name findElementByName name=

Identifier Not Available identifier=

Link findElementByLinkText link=


findElementByPartialLinkText

CSS findElementByCssSelector css=

DOM Not Available dom=

XPATH findElementByXpath xpath=//

Class Name findElementByClassName class=

Tag Name findElementByTagName Not available

What is Annotation

Annotation can be defined as metatag, which holds information about methods which are placed next to it.
Unit Testing tool like Junit and TestNg support Annotations

Annotations in Junit

@Test
@Test (timeout=500)
@Test(expected=IllegalArgumentException.class)
www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

@Before : Will execute before every @Test Annotation


@After : Will execute after every @Test Annotation
@BeforeClass : Will execute before executing any other annotation, execute only once at the start
@AfterClass : Will execute after executing all other annotation, execute only once at the end
@Ignore : Used with @Test annotation, will skip execution of particular test method
@Parameterized : Used for running my test case with multiple data

Order of Execution
@BeforeClass @Before @Test @After @AfterClass

Annotations Supported in TestNg

@Test : Marks a class or a method as part of the test.


@BeforeSuite : The annotated method will be run before all tests in this suite have run.
@AfterSuite : The annotated method will be run after all tests in this suite have run.
@BeforeTest : The annotated method will be run before any test method belonging to the classes inside
the <test> tag is run.
@AfterTest : The annotated method will be run after all the test methods belonging to the classes
inside the <test> tag have run.
@BeforeGroups : The list of groups that this configuration method will run before. This method is
guaranteed to run before the first test method that belongs to any of these groups is invoked.
@AfterGroups : The list of groups that this configuration method will run after. This method is guaranteed
to run shortly after the last test method that belongs to any of these groups is invoked.
@BeforeClass : The annotated method will be run before the first test method in the current class is
invoked.
@AfterClass : The annotated method will be run after all the test methods in the current class have
been run.
@BeforeMethod : The annotated method will be run before each test method.
@AfterMethod : The annotated method will be run after each test method.

Order of Execution
@BeforeSuite @BeforeTest @BeforeGroup @BeforeClass --> @BeforeMethod @Test
@AfterMethod @AfterClass @AfterGroup @AfterTest @AfterSuite

Difference between Junit & TestNg

TestNg Junit
Generate html reports automatically For reports, we need to use ANT

Can generate report for test case as well as test We cant create report of 1 test case, only reports
suite for test suites can be generated

Support more annotations than Junit, make it more Support annotation


flexible

Can set order of execution of multiple test Cant set order of execution of multiple test
annotation in single class file using priority annotation in single class file

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

Can execute particular group of test cases No concept of group execution

TestNg.xml is very simple and easy to understand Build.xml is complex and difficult to understand

We have option to set threads for parallel Cant set multiple threads(parallel execution)
execution(used in Grid)

Different ways to open URL in Webdriver

get() and navigate() both are used to open URL/application in webdriver


Difference is that in case of get() method, we can just open a URL while in case of navigate() method, we can
use forward and back button of browser

Get() method Navigate() method

driver.get("http://rediff.com"); driver.navigate().to("http://rediff.com");
driver.navigate().back();
driver.navigate().forward();

Wait in Webdriver Or Ajax handling in Selenium Webdriver

1 Thread.sleep(10)
Thread is a java class, we are calling sleep method of that class
It will add a forcefully wait at particular point
This is used when we want to always pause our execution at specific point

2 ImplicitWait
Implicitly wait are mainly used when our element on page are taking some time to load
It we dont add any wait in our script, then our driver will search for element and if not found immediately
failed that step
In case of implicitly wait, our driver will wait for specified time(time mentioned in implicitly wait) for that
element to be present
This wait will be applicable for findElements commands only
This need to placed at the start of test case, will be applied on all findElements commands

FirefoxDriver driver = new FirefoxDriver();


driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

3 Explicit Wait (WebdriverWait class)


Explicitly wait (WebdriverWait class), is mainly used when we want to wait in script until a specified condition
is satisfied or max timeout we have given

FirefoxDriver driver = new FirefoxDriver();


WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.textToBePresentInElement(By.id("f_id"), "Hello"));

4 Fluent Wait
It implements Wait interface and we create object of FluentWait class
Here we can set maximum time we should wait for element to be present(withTimeout method)
Here we can set after how much time, it will check for element to be present (pollingEvery method)
Here we can ignore any exception if it comes at runtime while waiting (ignoring method)
www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)


.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);

Working with LIST AND DROPDOWN in selenium

Selenium WEBDRIVER Selenium RC

// To Work on dropdown or List we need to create object // Working with List


of Select class selenium.addSelection("ElementLocator", "Value");
Select dateselect = new
Select(driver.findElementById("f_mydata")); // Working with Dropdown
selenium.select("ElementLocator", "Value");
// Here we have 3 options to select an element
dateselect.selectByIndex(1);
dateselect.selectByValue("15");
dateselect.selectByVisibleText("MyData");

Multiple Windows handling in Webdriver Taking snapshot in Webdriver

// Creating webdriver object


FirefoxDriver driver = new FirefoxDriver(); // Creating webdriver object
driver.get("http://rediff.com"); FirefoxDriver driver = new FirefoxDriver();
driver.get("http://rediff.com");
// getWindowHandles method of driver class return //a
string // Taking screenshot in Webdriver
// this string is a unique key referencing all File outSnapshot =
//browsers/opend by our webdriver, driver.getScreenshotAs(OutputType.FILE);
//we save all values in a Set
Set<String> hs = driver.getWindowHandles(); // Use FileUtils class to copy snapshot taken in
//previous step to my disk
// Iterating to the set and picking all available values FileUtils.copyFile(outSnapshot, new
Iterator<String> iter = hs.iterator(); File("C:\\snaps.png"));

// Setting iterator to work until value exist there Difference between Assert and Verify
while(iter.hasNext())
{
// Here we can perform different actions on window' Verify: If verify got failed, it will fail that particular step
// here in code we are just moving to the windows and execution will move to next step, remaining steps
// and closing all windows opened by webdriver will execute of that test case
driver.switchTo().window((String) iter.next()).close();
}
Assert : If assert got failed, execution of that test case
will halt on that step, no more steps of that test case will
execute

How to implement object repository in Selenium OR How to manage elements in Selenium?


www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

In selenium, first we pick element locator of all elements on which we are supposed to perform our action and
place in a property file(Here property file behave as Object Repository for Selenium)
Now wherever in our test case, element locator value is required. We fetch element locator value from
properties file (this is called properties file because extension of this file is .properties)
To fetch value of element locator from property file, we need to create object of ResourceBundle class and
by that object we can use getString method.

What are Desired Capabilities?

Desired Capabilities help to set properties for the Web Driver. A typical use case would be to
set the path for the Firefox Driver if your local installation doesn't correspond to the default
settings.
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.PROXY, proxy);
How to perform Keyboard and Mouse Operations in Selenium
Or
How to Handle Page onLoad Authentication

For attachment and downloading we need to perform some keyboard or mouse operations, for that we have
few options in Selenium

1. Through ROBOT Class of JAVA 2 Through Actions class of Selenium Webdriver


To perform keyboard operation To perform keyboard operation
To perform mouse operation To perform mouse operation
Perform Right Click
Robot action = new Robot(); Perform double click
action.keyPress(KeyEvent.VK_0); Drag and Drop
action.keyRelease(KeyEvent.VK_0); Scroll Up and down the window
action.mousePress(MouseEvent.MOUSE_CLICKED);
action.mouseMove(10, 20); Actions action = new Actions(driver);
action.click();
action.doubleClick();
3 AutoIT (Page Onload authentication and Keyboard and action.dragAndDrop(By.id("sourceelementlocator"),
Mouse Operations) By.id("destinationelementlocator"));
Sometimes when you are Automating Web pages, you action.contextClick(); // Right Click
may come across Page onload Authentication window. action.keyDown(Keys.CONTROL);
This window is not java popup/div. It is windows popup.
Selenium directly cannot handle this windows popup. // Move cursor to the Other Element
WebElement mnEle =
This tool can also be used to handle windows thats comes dr.findElement(By.id("shop"));
action.moveToElement(mnEle).perform();
while attaching and downloading attachment with email.

What is POM in Selenium ? What is its advantage ?

POM refers to Page Object Model which encapsulate the internal state of a page into a single page
object. UI changes only affect to a single Page Object, not to the actual test codes.
Advantages :
Code re-use: Able to use the same page object in a variety of tests cases.
www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

Reduces the amount of duplicated code.

How can we get the font size, font color, font type used for a particular text on a webpage using
Selenium web driver?
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-size or font-colour or font-type);

How to overcome same origin policy through web driver?


DesiredCapabilities capability=new DesiredCapabilities();
capability.setCapability(CapabilityType.PROXY,"http://wpadnod.microsft.com/wpad.dat");
FirefoxDriver f = new FirefoxDriver(capability);
How to Get page title in selenium webdriver ?
driver.getTitle();

How to Get Current Page URL In Selenium WebDriver


driver.getCurrentUrl();

Check Whether Element is Enabled Or Disabled In Selenium Web driver.


boolean fname = driver.findElement(By.xpath("//input[@name='fname']")).isEnabled();
System.out.print(fname);
Above syntax will verify that element (text box) fname is enabled or not. You can use it for any input
element.

Does WebDriver support file uploads?


Yes, You can't interact with the native OS file browser dialog directly, but we do some magic so that
if you call WebElement#sendKeys("/path/to/file") on a file upload element, it does the right thing.
Make sure you don't WebElement#click() the file upload element, or the browser will probably hang.

Difference between Absolute path & Relative path.


Absolute path will start with root path (/) and Relative path will from current path (//)

How do you verify if the checkbox/radio is checked or not ?


driver.findElement(By.xpath("xpath of the checkbox/radio button")).isSelected();

How do you handle alert pop-up ?


To handle alert pop-ups, we need to 1st switch control to alert pop-ups then click on ok or cancle
then move control back to main page.
Syntax-
String mainPage = driver.getWindowHandle();
Alert alt = driver.switchTo().alert(); // to move control to alert popup
alt.accept(); // to click on ok.
alt.dismiss(); // to click on cancel.
//Then move the control back to main web page-
driver.switchTo().window(mainPage); to switch back to main page.

How to get typed text from a textbox ?


String typedText = driver.findElement(By.xpath("xpath of box")).getAttribute("value"));

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

What is WebDriverBackedSelenium ?
WebDriverBackedSelenium is a kind of class name where we can create an object for it as below:
Selenium wbdriver= new WebDriverBackedSelenium(WebDriver object name, "URL ")
The main use of this is when we want to write code using both WebDriver and Selenium RC, we
must use above created object to use selenium commands.

How to get the number of frames on a page ?


List &lt;WebElement&gt; framesList = driver.findElements(By.xpath("//iframe"));
int numOfFrames = frameList.size();

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

SoapUI Video : https://www.udemy.com/soapui-with-groovy-with-realtime-


projects/?couponCode=NI

Jmeter Video: https://www.udemy.com/basic-to-expert-jmeter/?couponCode=MyTT

Unix & Shell Scripting for Testers : https://www.udemy.com/unixfortesters/?couponCode=15d

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

Why JAVA code is machine and platform independent?

When we compile java code, it convert java file to byte code (class file) rather than machine code,
byte code is machine and platform independent (.class file). We can interpret these class file to any
machine having JVM, JVM is used to interpret class file and convert it to machine dependent code
and then execute it.

What are different types of access modifiers?-

Access modifiers are used while creating class, method or variable.


public: Any thing declared as public can be accessed from anywhere.
private: Any thing declared as private can be accessed inside class only cant be seen outside of its class.
protected: Any thing declared as protected can be accessed by classes in the same package and
subclasses in the other packages.
Default : Can be accessed only to classes in the same package.

What is Garbage Collection and how to call it explicitly?-

When an object is no longer referred to by any variable, java/JVM automatically reclaims memory used by that
object. This is known as garbage collection.
System. gc() method may be used to call it explicitly.

What do you understand by keywords String , StringBuffer and StringBuilder ?

Strings can be handled by 3 classes in Java: String, StringBuffer, StringBuilder

String StringBuffer StringBuilder


String Class is immutable StringBuffer is mutable StringBuilder is mutable
object cannot be modified (all
changes that we are
doing(uppercase, lowercase,
substring etc) on string object,
is creating a new string object objects can be modified objects can be modified
and old data still persist and
become garbage(lot of garbage
is generating, impact on
performance)
StringBuffer is thread StringBuilder is not thread
safe(synchronized) but slow safe(not synchronized) and fast

This keyword in java

This keyword can be used with variable, with the help of this keyword we can set which one is class variable
and which one is local variable(this.variable name shows , this is a class variable)

This keyword can also be used to call current class overloaded constructor.
This keyword can be used to call current class methods

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

Static keyword in Java

Static keyword in Java can be used with variable, method and nested class(class inside another class)
static variable: static variable holds single memory location independent to number of objects we have
created, all objects will access data from same memory location.
static methods: static methods are like static variable holds single memory location for all objects.

STATIC methods/variable can be called by the class name itself without creating object of the class
Static nested class object created without creating object of its outer class
Methods, variables which are not static is called instance variable/methods

Super keyword in Java

Super keyword in java is used to call parent class override method or parent class constructor
Super Class Method Calling
1--> In case child class override, parent class method. When we create child class object and call override
method it will access child class method but if we want to access parent class method, we are going to use
super keyword
Super Class Constructor Calling
2--> super keyword is used to call parent class constructor as well

Difference between :-
`

Abstract Method Concrete Method

Methods which are just declared not defined or Methods which are declared and defined as well or
method without body. method with body.

Abstract Class Concrete Class

Class with abstract & concrete methods. Having Class with concrete methods only
at least 1 abstract method

Cannot create object of abstract class Can create object of concrete class

Abstract Class Interface

Class with Abstract + Concrete methods Interface can have only abstract methods

Can have constants as well as variable Variable declared are by default final(means
constants)

We can inherit only 1 class We can inherit multiple interface(by this way java is
supporting multiple inheritance)

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

Use extends keyword for inheritance Use implements keyword for inheritance

JAVA OOPS Concepts

Polymorphism: means same name multiple use.


Overloading and Overriding concept in java implements polymorphism

2 type polymorphism: Compile Time and RunTime


Overriding is a runtime polymorphism as 2 methods are having same name and signature so at the run time it
is decided which method to call
Overloading is a compile time polymorphism, as while compiling JVM knows which method is to call by
number and type of arguments

Inheritance: With the help of inheritance, we can transfer the properties of a class to child class

Data Encapsulation: Wrapping up of data and function in a single unit is called encapsulation.
In java class implements the concept of encapsulation

Data Abstraction: Make class/ methods abstract


Abstract class and Interface implements the concept of Data Abstraction

What is method overloading and method overriding?-

Method Overloading:
When more than 1 method in a class having the same method name but different signature
(Different signature means different number and type of arguments) is said to be method overloading.

Method Overriding:
When patent and child class have same name and same signature (signature means number and type of
arguments) method, this is called method overriding.
(Method overriding exist in case of inheritance only, when we are making parent-child relationship between
classes)

Inheritance

With the help of inheritance we can transfer the properties of a class to another class
Class which is inherited is called Parent Class or Super Class
Class which inherit other class is called Child Class or Sub Class
After inheritance, child class objects can access parent class method and variables .

extends is the keyword which is used to inherit class


implements is the keyword which is used to inherit interface

Type of Inheritance
Single/Simple Multilevel Inheritance Multiple Inheritance Hybrid Inheritance
Inheritance

Supported in Java Supported in Java Not directly supported Not directly supported
(supported through (supported through
www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

interface) interface)

Constructors

Constructor can be defined as a group of code (same like method) which is used for initialization
Initialization means anything that we want to perform at start
Points to remember:-
Constructor name is always same as class name
Constructor does not return any value so we dont write void while creating constructor
Constructors are automatically called when object is created we need not to call them explicitly as we
do in methods( as constructor is automatically called when object is created so all code pasted inside
constructed is executed before we use class object to call any other methods, thats why it is called
initialization)
We can have more than 1 constructor in a class with different signature, this is called constructor
overloading

Exception handling in Java

1>> throws keyword : we can place throws keyword in front of our method definition and we can mention
classes of all exception which we want to handle or we can mention parent class Exception

2>> Try catch -- finally block


Code that can throw exception, need to be placed in try block
After getting exception, whenever the action we want to perform will be placed in catch block
If we want to perform some task at the end does not matter exception came or not we will paste that code in
finally block
We can use try block then catch block
try block then finally block(we can skip catch block)
try block then catch block then finally block
Difference between Throw and Throws in Exception handling

1--> Throws is used in Method Signature while Throw is used in Java Code (send the instance of Exception
class)
2--> Throws, we can mention multiple type of exception, separated by comma while in throw we can set only 1
exception class instance
3-->Throws keyword just throws exception need not to handle it, throw pass exception instance to caller
program

What do you understand by keywords final, finalize and finally?-

final :
final keyword can be used for class, method and variables.
A final class cannot be inherited, a final method cant be override.
A final variable becomes constant, we cant change its value

finally :
finally, keyword used in exception handling.
It is used with a block of code that will be executed after a try/catch block has completed
The finally block will execute whether or not an exception is thrown.
Means if exception is not throws then Try execute then Finally will execute, in case when exception is thrown

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

finally will execute after catch e

Example : Like we have written DB connection code in try block but exception comes
In that case connection persist with DB and no other user are allowed to create connection, So in that kind of
scenario we want whatever the condition comes, may be exception or not, my DB connection should break,
for that Ill paste connection breaking code in finally() block

finalize() : finalize() method is used to code something that we want to execute just before garbage collection
is performed by JVM

Generic Method/ Classes in Java

In java Generic can be used with Methods and Classes

Generic means we create generic method which serves our multiple purposes like we can use same method
for multiple tasks like, sorting an integer array, String array etc.

Generic Methods : We can create generic methods which can be called by different type of
arguments, methods will server request on the behalf of type of argument coming with request

Collection in Java OR List in Java OR Set in Java or MAP in Java

Collection is a interface, which gives architecture to hold multiple data by same name
In JAVA, Collection interface is implemented by Set, List and Map

SET LIST MAP


-It is used to hold multiple data -It is used to hold multiple data Map holds data in the form of key
(same or different data type) (same or different data type) value pair

-Cannot hold duplicate values - Can hold duplicate values

-Can have maximum 1 null value -Values can be accessed by index


same like Array

Difference between Array and ArrayList

Array ArrayList

Use to hold multiple data of single data type Use to hold multiple data of single/diff data type

Need to define size of array Need not to define size, size automatically increase
/decrease as we add/remove element

Can access data through index Can access data through Iterator

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

How to Iterate on HashMap?

Answer: Iterating to List and Set is very simple but in case of HashMap we have to use an extra method
"keySet" which pass hashmap object to Iterator

package mypack;
import java.util.HashMap;
import java.util.Iterator;
import org.junit.Test;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class MyClas {
public static void main(String aa[]){
HashMap hp = new HashMap();
hp.put("K1", "Val1");
hp.put("K2", "Val2");
Iterator itr= hp.keySet().iterator();
while(itr.hasNext()){
String k = itr.next().toString();
System.out.println(hp.get(k));
}}}

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

Java Programs for Selenium Interview

Interchanging Values of 2 variable without using 3rd Variable

package org.abc
public class Tst1 {
public static void main(String aa[])
{
int i,j
i=100
j=300
i=i+j // 400
j=ij//
400300
=100 Now j=100
i=ij
//400100
=300 Now i=300
// Here we can see values exchanged successfully without using 3rd variable
System.out.println(i)
System.out.println(j)
}
}

Printing * Triangle
*
**
***

package mypack
public class MyClas {
public static void main(String aa[])
{
int Num=3
int i,j,k
System.out.println("Star Triangle up to "+Num+" line is below" )
// Here First loop is created for switching line
for(i=0i<=(Num1)i++) // Taken (num1)here because we started lo0p from 0
{
// Here this loop is created for printing spaces in every line
for(j=5j>ij)
{
System.out.print(" ")
}
// Here this loop is created for printing * in every line
www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

for(k=0k<=ik++)
{
System.out.print(" * ")
}
System.out.println("") // Here we are switching to next line after printing *
}}}
Print * Triangle Printing Right angle * triangle
**** *
*** **
** ***
*

package mypack package mypack


public class MyClas { public class MyClas {
public static void main(String aa[]) public static void main(String aa[])
{ {
int i,j,k int i,j,k
// Here First loop is created for switching for(i=0i<=5i++)
line // Here First loop is created for switching
for(i=0i<=5i++) line
{ {
// Here this loop is created for for(j=0j<=2j++)
printing spaces in every line // Here this loop is created for
for(j=0j<=ij++) printing spaces in every line
{ {
System.out.print(" ") System.out.print(" ")
}// inner for loop close }// inner for loop close
// Here this loop is created for for(k=0k<=ik++)
printing * in every line // Here this loop is created for
for(k=5k>=ik) printing * in every line
{ {
System.out.print(" * ") System.out.print(" * ")
}// inner for loop close }// inner for loop close
System.out.println("") System.out.println("")
// Here we are switching to next // Here we are switching to next
line after printing * line after printing *
}// outer for loop close }// outer for loop close
}} }}
Search Integer element in Array Sorting an Array

package mypack package mypack


public class MyClas { public class MyClas {
public static void main(String aa[]) public static void main(String aa[]){
{ int datatofind=6, flag=0
int datatofind=6, flag=0 int*+ i=,2,4,6,78,6,1-
int*+ i=,2,4,6,78,6,7- for(int j=0j<(i.length)j++) ,
for(int j=0j<i.lengthj++) for(int k=j+1k<(i.length)k++ ),
if(i[j]==datatofind){ if(i[j]>i[k])
flag=1 {
System.out.println("Element i*j+=i*j++i*k+

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

exist in system at index "+ j) i*k+=i*j+i*k+


break i*j+=i*j+i*k+
}// if close }}}
if(flag==0) System.out.print("Sorted List ")
System.out.println("Element is not for(int j=0j<(i.length)j++)
found") System.out.print(i*j+ + " ")
}} }}
Fabonacci Series upto 100 Check a number is prime or not

package mypack package mypack


public class MyClas { public class MyClas {
public static void main(String aa[]) public static void main(String aa[])
{ {
// Fabonnaci series upto 100 int i=23, m
// Fabonacci Series 0,1,1,2,3,5 // Here i is the number which we want to
(next number = add of last 2 numbers) test is prime or not
int a=0,b=1,z=0 int flag=0
System.out.print(a + " , " + b ) for(int j=2j<(i/2)j++)
while (z<100) {
{ m=i%j
z=a+b if(m==0)
a= b {
b=z
if(z<=100) System.out.println("This
{ is not a prime number,
System.out.print(", "+z) divided by " +j)
} flag=1
} break
} }
} }// for loop close
if(flag==0)
All Prime Numbers upto 100 {
System.out.println("This is a
package mypack prime number")
public class MyClas { }
public static void main(String aa[]) }}
{
int flag=0 Check Palendrome
System.out.print(2 )
for(int k=3k<=100k++) package mypack
{ public class MyClas {
for(int j=2j<kj++) public static void main(String aa[])
{ {
if(k%j==0) String a="nitin"
{ String b=""
flag=1 int k = a.length()
break for(int i=(k1) i>=0i)
} b=b+a.charAt(i)
}
if(flag==0) if(a.equals(b))

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

System.out.print(" , "+ k) System.out.println("Palendrome")


else else
flag=0 System.out.println("Not palendrome")
}// for loop close }//main () close
}// main () close }// class close
}// class close

Find SubString using logic Reverse a String

package mypack Logic 1:


public class MyClas { package mypack
public static void main(String aa[]) public class MyClas {
{ public static void main(String aa[])
String a="Hello World" {
String b ="llo W" String a="Hello World"
int flag=0, lenb= b.length() int x=a.length()
try{ System.out.println(x)
for(int j=0j<(a.length()b.length())j++), // display length of string
if(a.charAt(j)==b.charAt(0)) for(int j=0j<(x)j++)
{ System.out.print(a.charAt((xj1)))
String sub1= a.substring(j,(j+lenb)) }}
if(b.equals(sub1))
{ Logic 2:
flag=1 package mypack
System.out.println("Sub String is public class MyClas {
Found") public static void main(String aa[])
break {
}// inner if close String a="Hello World"
}// outer if close String b=""
}// for loop close int x=a.length()
if(flag==0) System.out.println(x)
System.out.println("Substring not // display length of string
found") for(int j=0j<(x)j++)
}// try block close b=b+a.charAt((xj1))
catch(Exception ex){ System.out.println(b)
System.out.println(ex.getMessage()) }}
} Sorting of String Array
}}
Search Element in String Array public class Case1 {
public static void main(String aa[]) throws
public class MyClas { AWTException{
public static void main(String aa[]){ int i,j
int flag=0 String*+arrString=,"Nitin","Amit","Sumit","Kapil"-
String datatofind="is" for(i=0i<(arrString.length1)i++),
String*+ i=,"my","data","is","here"- for(j=(i+1)j<arrString.lengthj++),
for(int j=0j<i.lengthj++), if(arrString[i].compareTo(arrString[j])>0)
if(i[j].equals(datatofind)){ {
flag=1 String s=arrString*i+
arrString*i+=arrString*j+

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

System.out.println("Element arrString*j+=s
exist in system at index "+ j) }
break }
}} }
if(flag==0) for(i=0i<(arrString.length)i++)
System.out.println("Element is not System.out.println(arrString*i+)
found")
}} }}

SoapUI Video : https://www.udemy.com/soapui-with-groovy-with-realtime-


projects/?couponCode=NI

Jmeter Video: https://www.udemy.com/basic-to-expert-jmeter/?couponCode=MyTT

Unix & Shell Scripting for Testers : https://www.udemy.com/unixfortesters/?couponCode=15d

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

www.thetestingworld.com
TESTING
www.thetestingworld.com Call/Whatsapp - 874391 3121
WORLD

www.thetestingworld.com

Anda mungkin juga menyukai