Hands-On Automation Testing with Java for Beginners
eBook - ePub

Hands-On Automation Testing with Java for Beginners

Build automation testing frameworks from scratch with Java

Rahul Shetty

  1. 156 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Hands-On Automation Testing with Java for Beginners

Build automation testing frameworks from scratch with Java

Rahul Shetty

Book details
Book preview
Table of contents
Citations

About This Book

Learn Java programming concepts to design automation testing frameworks

Key Features

  • Learn to use Java program logic in application testing
  • Understand various test-driven development concepts with Java tools
  • Master Java with lots of programming examples

Book Description

Java is one of the most commonly-used software languages by programmers and developers. Are you from a non-technical background and looking to master Java for your automation needs? Then Hands-On Automation Testing with Java for Beginners is for you.

This book provides you with efficient techniques to effectively handle Java-related automation projects. You will learn how to handle strings and their functions in Java. As you make your way through the book, you will get to grips with classes and objects, along with their uses. In the concluding chapters, you will learn about the importance of inheritance and exceptions with practical examples.

By the end of this book, you will have gained comprehensive knowledge of Java.

What you will learn

  • Understand the practical usage of Java conditions and loops
  • Write any Java program logic with strategies, tips, and tricks
  • Leverage advanced topics in Java collections to solve Java-related problems
  • Understand and use objects, classes, methods, and functions in Java
  • Build Java automation frameworks from scratch
  • Obtain knowledge of Java object-oriented programming (OOP) concepts with practical implementations

Who this book is for

Hands-On Automation Testing with Java for Beginners is for software developers who want to step into the world of software quality assurance and perform automation testing using various testing frameworks. Prior experience of writing tests in Java is assumed.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Hands-On Automation Testing with Java for Beginners an online PDF/ePUB?
Yes, you can access Hands-On Automation Testing with Java for Beginners by Rahul Shetty in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation en Java. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781789539769

Building Blocks for Java Programs – Loops and Conditions

Loops and conditions are the building blocks of Java programs. This chapter will help us understand the important loops and conditions through examples. Learning these loops and conditions in Java will make writing code easier.
In this chapter, we will cover the following topics:
  • The for loop
  • The if...else condition
  • The while loop
  • Nested loops

The for loop

Let's see how the for loop works. The for loop is one of the most commonly used loops in Java programs, and it it is very important to understand how it works internally. So, let's say we want to print the numbers from 1 to 100 using the forloop. For the syntax to execute the numbers from 1 to 100 in a sequence and to write that in a for loop, we will simply write:
// 1 to 100

/* for(initialization;condition;increment)
{
} */
for (int i=0;i<100;i++)
{
system.out.println(i);
}
}

Since we want to print 0, 1, 2, 3, we use i++. This means for every loop, it increments only by 1. And while looping, each time, it also checks whether the preceding condition is satisfied. So, if 1 is less than 100, it goes inside; if 2 is less than 100, it goes inside. Until this condition is satisfied, it will keep on looping. When the value of i reaches 100, 100 is less than 100, which is false. At that time, it terminates the loop and comes out of it. We will use a basic example here:
for (int i=0;i<5;i++)
{
system.out.println(i);
}
To run test cases in debug mode in the IDE, double-click at the location shown in the following screenshot:
Line from which the debugging begins
When you see the blue icon, run that in the debug mode by clicking the insects-like symbol. It will ask you to launch in debug mode. Just click on Save to do so:
Debug icon at the top of the editor
You will see all the variable values here. Step by step, we'll go inside the loop, and will execute the next step of the program:
Variable value while debugging
Finally, when it reaches the value 4, and is incremented by 1 again, it is 5. Note that it comes out of the loop without going inside that after the value becomes 5. So, that means the condition is no longer satisfied and the loop will run five times. The output is shown in the following screenshot:
Final output as per the code
So, that's how the for loop works.
Now, if we set the condition to the following, it will not go inside the for loop, even for the first time since, the condition is false.:
for (int i=5;i<3;i++)
On running the preceding condition in in the debug mode, the complete loop is skipped,and nothing is seen in the output.
Let's see another example:
for (int i=0;i<10;i+2 )
The output will be:
0
2
4
6
8
This is how the for loop works internally.
In the next section, we will learn about the if...else and do...while loops.

if...else condition

Before we learn the while and do...while loops, we will discuss the if condition in this section. In a Java program, when the if conditional statement is used, the statement in the if block is executed only if the condition is satisfied. Otherwise the statement from else block is run. Also this execution is just takes place once. In a for loop, a variable is initiated and the loop runs till the condition is satisfied.
However, in the if case, it will not keep on looping. It will just go inside the loop once the if condition is satisfied; otherwise, it will go into the else block. So, control will execute the statements present in this else block, as shown in the following screenshot:
Output of the if...else condition as per the code
But all this happens only once, unlike the for loop, where a condition is satisfied until it goes back and executes.
Let's take a look at the following example:
 if(5>2)
{
System.out.println("success");
}
else
{
System.out.println("fail");
}
The following screenshot displays those errors:
Quick fixes drop down with suggestions to correct the code error
The first error is to remove the including condition, which can be ignored. On running the preceding program, you will see the output as success because the condition 5 greater than 2 that went inside is true:
Output displays success as per the code
If we change the condition and make 5 less than 2, making the condition false, it will skip to the else block and execute the statement present in else.
code to receive fail as the output
This time the output should be fail, as shown in the following screenshot:
Output displays success as per the code
This is how the if condition works.
Note...

Table of contents

Citation styles for Hands-On Automation Testing with Java for Beginners

APA 6 Citation

Shetty, R. (2018). Hands-On Automation Testing with Java for Beginners (1st ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/825768/handson-automation-testing-with-java-for-beginners-build-automation-testing-frameworks-from-scratch-with-java-pdf (Original work published 2018)

Chicago Citation

Shetty, Rahul. (2018) 2018. Hands-On Automation Testing with Java for Beginners. 1st ed. Packt Publishing. https://www.perlego.com/book/825768/handson-automation-testing-with-java-for-beginners-build-automation-testing-frameworks-from-scratch-with-java-pdf.

Harvard Citation

Shetty, R. (2018) Hands-On Automation Testing with Java for Beginners. 1st edn. Packt Publishing. Available at: https://www.perlego.com/book/825768/handson-automation-testing-with-java-for-beginners-build-automation-testing-frameworks-from-scratch-with-java-pdf (Accessed: 14 October 2022).

MLA 7 Citation

Shetty, Rahul. Hands-On Automation Testing with Java for Beginners. 1st ed. Packt Publishing, 2018. Web. 14 Oct. 2022.