0% found this document useful (0 votes)
64 views3 pages

Java CheatSheet Automation Tester

This document is a Java cheat sheet tailored for automation testers, covering essential topics such as variables, data types, conditional statements, loops, arrays, string handling, methods, exception handling, OOP concepts, collections, file handling, and snippets for Java with Selenium and REST Assured. It provides code examples for each topic to assist testers in implementing Java in their automation tasks. The cheat sheet serves as a quick reference guide for common Java programming constructs and practices relevant to automation testing.

Uploaded by

mahanthesh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views3 pages

Java CheatSheet Automation Tester

This document is a Java cheat sheet tailored for automation testers, covering essential topics such as variables, data types, conditional statements, loops, arrays, string handling, methods, exception handling, OOP concepts, collections, file handling, and snippets for Java with Selenium and REST Assured. It provides code examples for each topic to assist testers in implementing Java in their automation tasks. The cheat sheet serves as a quick reference guide for common Java programming constructs and practices relevant to automation testing.

Uploaded by

mahanthesh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Cheat Sheet for Automation Testers

1. Variables and Data Types

int num = 10;

double price = 99.99;

String name = "Tester";

boolean isActive = true;

2. Conditional Statements

if (isActive) {

[Link]("Active");

} else {

[Link]("Inactive");

3. Loops (for, while)

for (int i = 0; i < 5; i++) {

[Link](i);

int j = 0;

while (j < 5) {

[Link](j);

j++;

4. Array and ArrayList

int[] numbers = {1, 2, 3};


import [Link];

ArrayList<String> list = new ArrayList<>();

[Link]("Selenium");

5. String Handling

String s = "Automation";

[Link]();

[Link]();

[Link]("Auto");

6. Methods

public int add(int a, int b) {

return a + b;

7. Exception Handling

try {

int result = 10 / 0;

} catch (ArithmeticException e) {

[Link]("Error: " + [Link]());

8. OOP Concepts

class Car {

String color;

Car(String c) { color = c; }

Car myCar = new Car("Red");

9. Collections (List, Map)


List<String> items = new ArrayList<>();

[Link]("Item1");

Map<String, Integer> map = new HashMap<>();

[Link]("key", 100);

10. File Handling

import [Link].*;

BufferedReader reader = new BufferedReader(new FileReader("[Link]"));

String line = [Link]();

11. Java + Selenium Snippet

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]([Link]("username")).sendKeys("admin");

12. Java + REST Assured Snippet

given().baseUri("[Link]

.when().get("/users")

.then().statusCode(200);

You might also like