Search

Monday, December 21, 2015

Difference between Thread.start() and Thread.run() method in Java?

If you remember, a Thread is started in Java by calling the start() method of java.lang.Thread class, but if you learn more you will find out that start() method internally calls the run() method of Runnable interface to execute the code specified in the run() method in the separate thread. Now the question comes, why can't you just call the run() method instead of calling the start() method because anyway start() is calling the run()? This is one of the tricky multi-threading question you will find on Java interviews. The trick here is that, when you directly call the run() method than the code inside run() method will not be executed on a new thread, instead it will be executed on the same thread. On the other hand, when you call the Thread.start() method, then the code inside run() method will be executed on a new thread, which is actually created by the start() method. This is one of the fundamental of threading in Java, which is often get overlooked by Java developers unless you have read book like Java Threads By Scott Oaks, which explains every key multi-threading concept and thread basics in good detail.
Read more »

Sunday, December 20, 2015

How To Start Appium Node Server From Command Prompt

Earlier we learnt how to download and Install appium server In windows during THIS POST and THIS POST will show you how to launch appium from windows start menu and then how to start appium node server manually from appium Interface. It Is not compulsory to start appium software node server from Interface only to test android software app. You can start appium server from command prompt too. Bellow given steps will show you how to start appium node server from command prompt to automate android software app.

PREREQUISITE :
  1. Appium should be Installed In your windows system and environment should be configured. VIEW Appium environment configuration steps.
  2. Node JS should be Installed. View THIS POST.
Set Path System Variable Of Node JS
Earlier we Installed Node JS software. Installation will create nodejs folder at C:\Program Files\ Path. We need to set this path(C:\Program Files\nodejs followed by ;(semicolon)) as system path variable as shown In bellow Image. View THIS POST to learn more about how to open Environment variable dialog and set Path variable.



Start Appium Node Server From Command Prompt
If you look at path C:\Program Files, There will be folder for Appium software which Is created during appium Installation. We can start appium server using command prompt from this folder.
  • Navigate to C: -> Program Files -> Appium -> node_modules folder.
  • Press and hold Ctrl + Shift Keys of keyboard and press mouse right click. It will open context menu as shown bellow.

  • Select "Open command Window here" from context menu. It will open command prompt with navigation to given node_modules folder path.
  • Type command node appium In command prompt and press enter.

  • It will take some time to start appium server. When server get started, It will show you log  message like "Welcome to Appium v...etc " as shown in above Image.
  • You can press CTRL+C to stop appium server on test completion.
That means appium server Is running and we can use It to perform Android software app testing on mobile devices. This way we can start appium server from command prompt too.

<< PREVIOUS || NEXT >>

Wednesday, December 16, 2015

Appium - Capture Screenshot On Failure Or Pass In Android Test Automation

Earlier In previous post, We learnt how to capture screenshot of android mobile software app screen on any stage In android appium software automation test. Now supposing I wants to capture screenshot on test failure or I wants to capture screenshot on software test pass. In this case,  ITestListener Interface of TestNG can help us to capture screenshot on certain occurrence like test failure or software test pass.

ITestListener Interface
ITestListener Is an Interface of TestNG which can Invoke it's specific method on test failure or test pass or test skips, ect.. There are bellow given useful methods available In ITestListener Interface.
  • onFinish(ITestContext context) - Invoked after all the software tests have run.
  • onStart(ITestContext context) -  Invoked after the test class is instantiated.
  • onTestFailure(ITestResult result) - Invoked each time a test fails.
  • onTestSkipped(ITestResult result) - Invoked each time a test is skipped.
  • onTestStart(ITestResult result) -  Invoked each time before a test will be invoked.
  • onTestSuccess(ITestResult result) - Invoked each time a test succeeds.
You can view more detail on ITestListener Interface on THIS PAGE. Earlier we have used It In data driven framework. View THIS PAGE for more detail.

App To Use Capture Screenshot Test
We will use android mobile's calculator app In this software automation test example.

Aim to Achieve
We wants to capture screenshot on test pass or failure occurrence and store file in related folder. If test Is fail then capture screenshot and store It In Failures folder and If test Is pass then capture screenshot and store It In Pass folder under screenshots folder of your project as shown in bellow Image.


How To Do
We will create separate class file to write logic of capture screenshot on test fail or pass. Inside It, We will create separate method captureScreenShot to write logic to capture screenshot. We will use testng assertion to verify our software test is fail or pass and use ITestListener Interface to Invoke onTestFailure method on assertion failure and onTestSuccess on assertion pass and then call captureScreenShot method to take screenshot.

In test class file, We will write two test methods TestForFailure() and TestForPass(). Test method TestForFailure() Is written In such a way to fail It Intentionally.

Screenshot of TestForFailure() method will be stored Inside Failure folder and screenshot of TestForPass() method will be stored Inside Success folder.

Create And Run Test
I have created very simple example to demonstrate you how to capture screenshot on test failure or pass. You need to create two class files under Android package of your project as bellow.

ScreenshotUtility.java file contains logic to capture screenshot on test failure or pass.

ScreenshotUtility.java
package Android;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

public class ScreenshotUtility implements ITestListener {
// This method will execute before starting of Test suite.
public void onStart(ITestContext tr) {

}

// This method will execute, Once the Test suite is finished.
public void onFinish(ITestContext tr) {

}

// This method will execute only when the test is pass.
public void onTestSuccess(ITestResult tr) {
captureScreenShot(tr, "pass");
}

// This method will execute only on the event of fail test.
public void onTestFailure(ITestResult tr) {
captureScreenShot(tr, "fail");
}

// This method will execute before the main test start (@Test)
public void onTestStart(ITestResult tr) {

}

// This method will execute only if any of the main test(@Test) get skipped
public void onTestSkipped(ITestResult tr) {
}

public void onTestFailedButWithinSuccessPercentage(ITestResult tr) {
}

// Function to capture screenshot.
public void captureScreenShot(ITestResult result, String status) {
// AndroidDriver driver=ScreenshotOnPassFail.getDriver();
String destDir = "";
String passfailMethod = result.getMethod().getRealClass().getSimpleName() + "." + result.getMethod().getMethodName();
// To capture screenshot.
File scrFile = ((TakesScreenshot) ScreenshotOnPassFail.driver).getScreenshotAs(OutputType.FILE);
DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
// If status = fail then set folder name "screenshots/Failures"
if (status.equalsIgnoreCase("fail")) {
destDir = "screenshots/Failures";
}
// If status = pass then set folder name "screenshots/Success"
else if (status.equalsIgnoreCase("pass")) {
destDir = "screenshots/Success";
}

// To create folder to store screenshots
new File(destDir).mkdirs();
// Set file name with combination of test class name + date time.
String destFile = passfailMethod + " - " + dateFormat.format(new Date()) + ".png";

try {
// Store file at destination folder location
FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
} catch (IOException e) {
e.printStackTrace();
}
}
}


ScreenshotOnPassFail.java file contain android cal app test. If you see In bellow given test, We have used @Listeners annotation. It mansion that testng listeners are Implemented In ScreenshotUtility class file to listen.

ScreenshotOnPassFail.java
package Android;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners({ ScreenshotUtility.class })
public class ScreenshotOnPassFail {
static AndroidDriver driver;

@BeforeClass
public void initialize() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ZX1B32FFXF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}

// Method Is written In such a way to fail It Intentionally.
// This method will fail as actual result 6 will not match with expected 7.

@Test
public void TestForFailure() throws IOException {
// Click on DELETE/CLR button to clear result text box before running test.
((WebElement) driver.findElements(By.xpath("//android.widget.Button")).get(0)).click();
// Click on 2, +, 4 and = buttons.
driver.findElement(By.name("2")).click();
driver.findElement(By.name("+")).click();
driver.findElement(By.name("4")).click();
driver.findElement(By.name("=")).click();
// Get result from calc result textbox.
String result = driver.findElement(By.className("android.widget.EditText")).getText();
// Compare actual and expected result using testng assertion and mark test pass or fail based on result.
// Assertion will fail. So It will call onTestFailure method from ScreenshotUtility.

assert result.equals("7") : "Expected value : 7 did not match with Actual value: "+ result;
}

@Test
public void TestForPass() throws IOException {
// Click on DELETE/CLR button to clear result text box before running test.
((WebElement) driver.findElements(By.xpath("//android.widget.Button")).get(0)).click();
// Click on 3, +, 4 and = buttons.
driver.findElement(By.name("3")).click();
driver.findElement(By.name("+")).click();
driver.findElement(By.name("4")).click();
driver.findElement(By.name("=")).click();
// Get result from calc result textbox.
String result = driver.findElement(By.className("android.widget.EditText")).getText();
// Compare actual and expected result using testng assertion and mark test pass or fail based on result.
// Assertion will pass. So It will call onTestSuccess method from ScreenshotUtility.

assert result.equals("7") : "Expected value : 7 did not match with Actual value: " + result;
}

@AfterClass
public void End() {
driver.quit();
}
}

Connect your device with PC and run above ScreenshotOnPassFail test using testng and appium.
  • TestForFailure() method : Here assertion will fail so onTestFailure method will be called from ScreenshotUtility.java. It will capture screenshot and store It in Failures folder under screenshots folder.
  • TestForPass() method : Here assertion will pass so onTestSuccess method will be called from ScreenshotUtility.java. It will capture screenshot and store It in Success folder under screenshots folder.
This Is the way to capture screenshot on failure or pass of any android appium software automation test.

Tuesday, December 15, 2015

Top 3 Free Struts Books for Java EE developers - Learn Online, PDF download

Jakarta Struts is one of the most popular MVC frameworks to create a Java web application. Struts 1.0 had ruled the world in early 2000 era before Spring MVC took over. Still there are lots of projects written in Struts which needs active maintenance and that's why Struts developers are still in demand. It has not become anything like COBOL, but the latest version of Struts 2.0 is a capable web MVC framework with dependency injection and has a sizable community behind it. It has close competition with Spring MVC but given the demand for Struts developer, it's still a good technology to learn if you are looking for the job in Java web development position. What is the best way to learn Struts? Well, you can start with books and who doesn't like free eBooks and I am going to share some of the good free Ebooks to learn Struts, useful for both Java and J2EE developers.
Read more »

Sunday, December 13, 2015

Appium - Capture Screenshot Android App Mobile Screen

Capturing screenshot in appium android automation Is main requirement for any software automation tool. During software automation testing process, It should allow you to capture screenshot automatically to show bug or some design Issue to development/design team. For android software application automation testing using appium, We can use TakesScreenshot Interface of WebDriver to capture screenshot of android app screen. I have prepared simple example on how to capture screenshot In android appium automation software test using TakesScreenshot Interface of WebDriver.

App To Use Capture Screenshot Test
We will use API Demos android software app for Capture Screenshot test. You can download it from HERE.

Aim to Achieve In Capture Screenshot Test
We wants to capture screenshot of android mobile screen on some stage of appium automation test. And then we will store It Inside screenshots folder under project. We will prepare file name using current date time programmatically as shown In bellow Image.


Above Image shows screenshot which Is taken during android appium automation test.

Create And Run Capture Screenshot Test
Create new file CaptureScreenShot.java file under your Android package of your project and write bellow given test script In It.

package Android;

import io.appium.java_client.android.AndroidDriver;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class CaptureScreenShot {
AndroidDriver driver;
Dimension size;
String destDir;
DateFormat dateFormat;

@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ZX1B32FFXF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity", "io.appium.android.apis.ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@Test
public void ScrollToTab() {
// Scroll till element which contains "Views" text If It Is not visible on screen.
driver.scrollTo("Views");
// Click on Views.
driver.findElement(By.name("Views")).click();
// Scroll till element which contains "Tabs" text If It Is not visible on screen.
driver.scrollTo("Tabs");
//Call takeScreenShot() function to capture screenshot of android screen.
takeScreenShot();

}

public void takeScreenShot() {
// Set folder name to store screenshots.
destDir = "screenshots";
// Capture screenshot.
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
// Set date format to set It as screenshot file name.
dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
// Create folder under project with name "screenshots" provided to destDir.
new File(destDir).mkdirs();
// Set file name using current date time.
String destFile = dateFormat.format(new Date()) + ".png";

try {
// Copy paste file at destination folder location
FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
} catch (IOException e) {
e.printStackTrace();
}
}

@AfterTest
public void End() {
driver.quit();
}
}

Test Description
Above android appium software test will navigate to Views screen and scroll down till Tabs text on API Demos android app. Then It will call takeScreenShot(); method to capture and store android app screenshot. takeScreenShot() method will,
  • Capture screenshot using TakesScreenshot Interface of webdriver.
  • Get current date and time and store It in variable.
  • Create new folder with name "screenshots" under your project.
  • Set file name using current date and time.
  • Store file In "screenshots" folder.
When you run above test, It will create screenshots folder under your project and store screenshot file In It. Refresh your project folder after test execution to see new created folder and screenshot file.

This way you can capture and store screenshot of any android app.

Wednesday, December 9, 2015

Top 30 OOPS Concept Interview Questions Answers in Java

Java is an object-oriented programming language and you will see a lot of object oriented programming concept questions on Java interviews. The classic questions like difference between interface and abstract class are always there but from the last couple of years more sophisticated questions based upon advanced design principles and patterns are also asked to check OOP knowledge of the candidate. Though, Object oriented programming questions are more popular on Java interviews for 1 to 3 years experienced programmers. It makes sense as well, as these are the programmers who must know the OOP basic like Abstraction, Inheritance, Composition, Class, Object, Interface, Encapsulation etc. If you look for Java interview questions for 2 to 4 years experienced programmer, you will find lots of questions based upon OOP fundamentals like Inheritance and Encapsulation but as you gain more experience, you will see questions based upon object oriented analysis and design e.g. code a vending design machine or implement a coffeemaker in Java. These questions are more difficult and require not only true understanding of OOP fundamental but also about SOLID design principles and patterns.
Read more »

Tuesday, December 8, 2015

Appium - Set Date And Time In Android App Test Automation

Android software apps contains date pickers. Date picker can be Inline or It can be In dialog. Just like other elements of android app software, We can automate android app's date dialog to set date and time dialog to set time In android appium software automation test. Here I have demonstrated simple example on how to set android app date and time In appium test. For your android app's date picker, Date format can be different but method to set It will remain same as described bellow.

App To Use Android App Date And Time Test
We will use same API Demos app to demonstrate how to set date and time In android appium software automation test. Download API Demos android software app from THIS PAGE.

Aim To Achieve In Set Date Time Test
We wants to set date = 25 Aug 2009 In date dialog and time = 1:25 pm In time dialog as shown In bellow Images.

Set Date In Dialog

Set Time In Dialog

Manually you can navigate to above screen from API Demos app -> Tap on Views -> Tap on Date Widgets -> Tap on 1. Dialog.

Create and Run Set Date Time Android Appium Test
Create new SetDate.java file under Android package of your project to test android software app and copy paste bellow given test script In It.

SetDate.java
package Android;

import io.appium.java_client.android.AndroidDriver;

import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class SetDate {
AndroidDriver driver;

@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ZX1B32FFXF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity","io.appium.android.apis.ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@Test
public void dateSet() {
// Scroll till element which contains "Views" text.
driver.scrollTo("Views");
// Click on Views.
driver.findElement(By.name("Views")).click();
// Scroll till element which contains "Date Widgets" text.
driver.scrollTo("Date Widgets");
// Click on element which contains "Date Widgets" text.
driver.findElement(By.name("Date Widgets")).click();
// Scroll till element which contains "1. Dialog" text.
driver.scrollTo("1. Dialog");
// Click on element which contains "1. Dialog" text.
driver.findElement(By.name("1. Dialog")).click();
// Click on button which contains "change the date" text.
driver.findElement(By.name("change the date")).click();
//Set Date = 25.
driver.findElement(By.xpath("//android.widget.NumberPicker[@index='0']")).sendKeys("25");
//Set Month = Aug.
driver.findElement(By.xpath("//android.widget.NumberPicker[@index='1']")).sendKeys("Aug");
//Set Year = 2009.
driver.findElement(By.xpath("//android.widget.NumberPicker[@index='2']")).sendKeys("2009");
//Click on Done button.
driver.findElement(By.id("android:id/button1")).click();
}


@Test
public void timeSet() {
// Click on button which contains "change the time" text.
driver.findElement(By.name("change the time")).click();
//Set Hours = 1.
driver.findElement(By.xpath("//android.widget.NumberPicker[@index='0']")).sendKeys("1");
//Set Minutes = 25.
driver.findElement(By.xpath("//android.widget.NumberPicker[@index='2']")).sendKeys("25");
//Set pm.
driver.findElement(By.xpath("//android.widget.NumberPicker[@index='1']")).sendKeys("pm");
//Click on Done button.
driver.findElement(By.id("android:id/button1")).click();
}
@AfterTest
public void End() {
driver.quit();
}
}

Test Script Description
As you can see In above test, We have created two @Test methods. 

dateSet() Method
dateSet() method will,
  • Navigate to Dialog Screen.
  • Then It will click on change the date button. It will open set date dialog.
  • Next 3 driver.findElement() method will locate date, month and year textbox and set requested date, month and year In related field.
  • Then It will click on Done button to close date dialog.
timeSet() method
  • It will click on change the time button. It will open set time dialog.
  • Next 3 driver.findElement() method will locate hour, minute and am or pm textbox and set requested hour, minute and am or pm In related field.
  • Then It will click on Done button to close date dialog.
This Is the way to set date and time in date and time dialog of android appium software automation test.

Monday, December 7, 2015

Difference between Primary and Foreign key in table - SQL

The database is a collection of tables and a table is the collection of rows or records. A primary key is the data to uniquely identify a row in the table. For example, if an Employee table has millions of rows and emp_id is a primary key then it can uniquely identify that row. You can use this primary key to retrieve (SELECT) the row, update the row and delete the row. In SQL, a table can have only one primary key but it can contain more than one columns. There are two types of primary key, a simple primary key, and a composite primary key. A simple primary key is made of just one column while a composite primary key is made of more than one columns. Primary key also enforces some constraint e.g. UNIQUE and NOT NULL, which means if you try to enter another record with the primary key already existing in the database than DBMS will reject it. Similarly, a primary key cannot be NULL, it must have some value. On the other hand, the foreign key is just the primary key of another table. In a relational database, two tables can be related to each other e.g. Employee and Department, those cases, the primary key of one table becomes the foreign key of another table. In this article, you will learn some key difference between the Primary and foreign key in a table. This is also one of the most common SQL Interview questions for 1 to 2 years experience programmers.
Read more »

Saturday, December 5, 2015

Appium - Android App Spinner Value Selection Example

Spinner Is a drop down In android software native app where you can select Item from the drop down list as per your requirement. Spinner can have scroll If list Is large and also It can have scroll If there are only few Items In drop down list. Appium software automation tool support scrollTo function to scroll at your desired Item. In this example, We will learn how to scroll down In spinner list Items of android software app and then how to select Item from spinner list using appium software automation test.

App Used For Android Spinner Test
We have to use API Demos android software app for this test and you can downloading API Demos android software app from HERE. You need to Install API Demos app In your android device.

Aim To Active In Spinner Test
We wants to scroll down In Planet spinner list and then select Item "Pluto" from the list as shown In bellow Image. Earlier we already learnt how to scroll down using scrollTo() method In THIS EXAMPLE. We will use same method here to scroll down In spinner list.


Manually you can navigate to above screen from API Demos software app -> Tap on Views -> And then tap on Spinner.

Create And Run Appium Test For Spinner
Create new test file Spinner.java under Android package of project In eclipse and write bellow given android appium test script In It.

Spinner.java
package Android;

import io.appium.java_client.android.AndroidDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Spinner {
AndroidDriver driver;

@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ZX1B32FFXF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity","io.appium.android.apis.ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@Test
public void selectPlanetValue() {
// Scroll till element which contains "Views" text.
driver.scrollTo("Views");
// Click on Views.
driver.findElement(By.name("Views")).click();
// Scroll till element which contains "Spinner" text.
driver.scrollTo("Spinner");
// Click on element which contains "Spinner" text.
driver.findElement(By.name("Spinner")).click();
//Find parent element of Planet drop down to uniquely Identify It's child drop down.
WebElement ele = driver.findElementById("io.appium.android.apis:id/spinner2");
//Click on Planet drop down to open drop down list.
ele.findElement(By.id("android:id/text1")).click();
// Scroll till element which contains "Pluto" text In drop down list.
driver.scrollTo("Pluto");
//Select "Pluto" from drop down list Items.
driver.findElementByName("Pluto").click();
}

@AfterTest
public void End() {
driver.quit();
}
}

Spinner Test Description
Spinner software automation test Is very simple and straight to understand If you have read my all previous android appium examples. When you run above test In eclipse,
  • First It will navigate to Spinners screen.
  • Then locate parent of Planet spinner.
  • Using parent reference, It will locate planet spinner and click on It.
  • Then It will scroll down In spinner list
  • And select "Pluto" from list.
This Is the way to handle spinner In android appium test.

Thursday, December 3, 2015

6 Good Websites to Learn JavaScript Online - Best of Lot

We live in the world of internet which is full of resource. You can learn whatever you want and that too without spending too much of money. If you want to learn JavaScript there are plenty of websites where you can learn JavaScript online for FREE. You don't need to pay any fees, but you must have a good internet connection to take full advantage of these online resources. Out of so many websites which offer free tutorials, articles, blog post, videos, and podcasts, I have chosen these six websites to recommend to anybody who wants to learn JavaScript. I am a Java developer, but I have learned JavaScript by following this tutorial, Why? because I usually have to work on Java based web application which uses Servlet and JSP for server side scripting, but we always use JavaScript and jQuery for client side scripting. I would be first to admit that my JavaScript skills are not as good as Java and that's why I am always in search of some good resource to keep learn and refresh whatever I have learned online on JavaScript by following video tutorials and these interactive websites.
Read more »

Wednesday, December 2, 2015

Appium - How To Handle Alert Dialog Of Android App

Alert dialog Is common element of any android software app so you must know how to handle android app alert In appium or how to click on OK button of android app alert In appium automation test . You can get alert when you click button or check the check box to get confirmation. Alert dialog contains OK and Cancel buttons and you can click on OK or cancel button. Right now, There Is not any Implementation of alert In AndroidDriver. So we need to find some alternative to handle alert In android appium software automation test. We can treat alert same as other elements In our android appium software automation test.

App To Use In Test
We will use API Demos android software app In this test. You can download API Demos software app from THIS PAGE. Install API Demos app In your android device.

Aim To Achieve In Appium Android Test
We Wants to click on OK or Cancel button of alert In this appium android software automation test as shown In bellow Image.



Manually you can navigate to above alert dialog screen from Open API Demos app -> Tap on App -> Tap on Alert Dialogs -> Tap on OK Cancel dialog with a message button.

Create And Run Appium Android Test To Handle Alert
Create new file HandleAlert.java under Android package of your project and copy paste bellow given software automation test script In It.

HandleAlert.java
package Android;

import io.appium.java_client.android.AndroidDriver;

import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class HandleAlert {
AndroidDriver driver;

@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ZX1B32FFXF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity","io.appium.android.apis.ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@Test
public void okOnAlert() {
// Scroll till element which contains "App" text.
driver.scrollTo("App");
// Click on App.
driver.findElement(By.name("App")).click();
// Scroll till element which contains "Alert Dialogs" text.
driver.scrollTo("Alert Dialogs");
// Click on Alert Dialogs.
driver.findElement(By.name("Alert Dialogs")).click();
// Click on "OK Cancel dialog with a message" button.
driver.findElement(By.name("OK Cancel dialog with a message")).click();
// Get the text from alert dialog.
String result = driver.findElementById("android:id/alertTitle").getText();
System.out.println("Alert text Is -> " + result);
// Click on OK button of alert dialog.
driver.findElement(By.name("OK")).click();
// Click on Cancel button of alert dialog.
// driver.findElement(By.name("Cancel")).click();

}

@AfterTest
public void End() {
driver.quit();
}
}

Android Appium Test Description
Comments are provided with every statement In above android appium test script. Selenium has Alert class to handle alerts of web application. But It still Alert class Is not Implemented with AndroidDriver so we can not use It In our test. Here we have located Alert text container and OK button manually. Also you can click on Cancel button of alert using last statement.

This Is the way to handle alert dialog In android appium test.

Tuesday, December 1, 2015

Java Interview Questions Answers for Freshers (1 to 4 years experienced)

I have shared many posts about Java Interview Questions but in this article, I will share Java Interview questions and answers especially for junior Java developers. This includes college graduates, who are looking for the job, Java programmers who have 1 to 2 years of experience in Java and junior developers who have 2 to 4 years of experience in Java, C++ etc. At this level, Java questions are usually not very tough. If you have good knowledge of key programming areas e.g. data structure and algorithms, and a good understanding of Java programming language and JDK API, then you are in good shape. Interviewer often looks for candidates who are willing to learn, good at learning in quick time and knows basic stuff e.g. sorting list, searching through the array, starting stopping a thread and can read existing code. In this article, you will find questions from the areas targeted by Interview for freshers and Java developers with 1 to 4 years of experience e.g. coding, arrayOOP, main methodCollections, ArrayListEnums, Threads, design patterns, JDBC, SQL, Linux and other basic concepts.
Read more »

Saturday, November 28, 2015

Pefrorm MultiTouch Action Using Appium In Android Application Automation

MultiTouch Action In android mobile software app Is one of the common action. Earlier we learn usage of TouchAction class In appium android software automation test to perform DRAG AND DROP and SWIPE ELEMENT. You also needs to automate multi touch action In your android mobile software app. Here I have demonstrated simple example on how to perform multi touch action In your android mobile softwareapp.

Install MultiTouch Tester App In Android Mobile
We will use MultiTouch Tester software App In this android appium multi touch action automation test example. So you need to download and Install MultiTouch Tester android software App In your mobile device. You can download and Install MultiTouch Tester App from Google Play Store or THIS PAGE.

Aim To Achieve In This Test
We wants to perform multi touch at 5 different points at the same time on MultiTouch Tester App's screen as shown In bellow Image.


This Is what we wants to achieve from this appium android test example.

Get X And Y Coordinates Of All Touch Points
In above Image you can see that there are 5 points where we wants to perform MultiTouch Action In appium android automation test. You can get X Y Coordinates of all 5 touch points manually using uiautomatorviewer too as described In THIS POST

In our appium test, We will calculate X and Y Coordinates of all 5 touching points pragmatically by calculating screen's width  and then will get different x and y points using size.width and size.height methods.

Create And Run Android Appium MultiTouch Action Test
Create new MultiTouch.java file under your project and copy paste bellow given test script Inside It.

package Android;

import io.appium.java_client.MobileDriver;
import io.appium.java_client.MultiTouchAction;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class MultiTouch {
AndroidDriver driver;
Dimension size;

@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ZX1B32FFXF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage","com.the511plus.MultiTouchTester");
capabilities.setCapability("appActivity","com.the511plus.MultiTouchTester.MultiTouchTester");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@Test
public void mTouchAction() throws InterruptedException {

size = driver.manage().window().getSize();
//Get X Y Coordinates for touch action 1(Top left side).
int x1 = (int) (size.width * 0.20);
int y1 = (int) (size.height * 0.20);

//Get X Y Coordinates for touch action 2(Top right side).
int x2 = (int) (size.width * 0.80);
int y2 = (int) (size.height * 0.20);

//Get X Y Coordinates for touch action 3(Bottom left side).
int x3 = (int) (size.width * 0.20);
int y3 = (int) (size.height * 0.80);

//Get X Y Coordinates for touch action 4(Bottom right side).
int x4 = (int) (size.width * 0.80);
int y4 = (int) (size.height * 0.80);

//Get X Y Coordinates for touch action 5(middle of the screen).
int x5 = size.width / 2;
int y5 = size.height / 2;

// Create object of MultiTouchAction class.
MultiTouchAction maction = new MultiTouchAction((MobileDriver) driver);

// Set touch action1 on given X Y Coordinates of screen.
TouchAction action1 = new TouchAction((MobileDriver) driver).longPress(x1, y1).waitAction(1500);
// Set touch action2 on given X Y Coordinates of screen.
TouchAction action2 = new TouchAction((MobileDriver) driver).longPress(x2, y2).waitAction(1500);
// Set touch action3 on given X Y Coordinates of screen.
TouchAction action3 = new TouchAction((MobileDriver) driver).longPress(x3, y3).waitAction(1500);
// Set touch action4 on given X Y Coordinates of screen.
TouchAction action4 = new TouchAction((MobileDriver) driver).longPress(x4, y4).waitAction(1500);
// Set touch action5 on given X Y Coordinates of screen.
TouchAction action5 = new TouchAction((MobileDriver) driver).longPress(x5, y5).waitAction(1500);

// Generate multi touch action chain using different actions and perform It.
maction.add(action1).add(action2).add(action3).add(action4).add(action5).perform();
}

@AfterTest
public void End() {
driver.quit();
}
}

MultiTouch Action Script Description
In above test you can see,
  • First of all we have collected X and Y coordinates(x1,y1, x2,y2, ..ect) for different touch point positions.
  • MultiTouchAction Is a class which provides us a facility to generate multi touch action chain using touch action chain.
  • We have created touch action chain for all 5 touch points using TouchAction class.
  • And then added all 5 touch actions In MultiTouchAction chain using .add(TouchAction action) method.
  • perform() action will perform steps given In MultiTouchAction chain.
Now you can run above test script In your android mobile device using appium and testng. It will launch MultiTouch Tester App In your android mobile device and then perform multitouch action.

Test Apps To Use In Appium Automation Tests

We will use bellow given android software apps in different appium software automation test examples. You can download android software apps directly from here to use in appium software automation test examples.
  1. MultiTouch Tester App (com.the511plus.MultiTouchTester.apk)
  2. APKinfo App (com.intelloware.apkinfo.apk)
  3. Android Calculator App(com.android.calculator2.apk)
  4. Drag-Sort Demos App(com.mobeta.android.demodslv-0.5.0-3_APKdot.com.apk)
  5. SwipeListView Demo App(SwipeListView Demo_v1.13_apkpure.com.apk)
  6. ApiDemos App(ApiDemos.apk)

8 Difference between HashMap and TreeMap with Example

HashMap and TreeMap both store key value pair in their object. Difference between HashMap and TreeMap is one of the question you must at least go through once before appearing for the java interview. I have already shared how HashMap works in java and how TreeMap works in java. In this article we will see not only the difference between HashMap and TreeMap but also the similarities between them with examples.

Read Also :  Difference between Iterator and ListIterator with Example


Difference between HashMap and TreeMap in Java 

1. Ordering : HashMap does not maintain any order. In other words , HashMap does not provide any guarantee that the element inserted first will be printed first.


import java.util.HashMap;

public class HashMapExample {

public static void main(String[] args) {

HashMap obj1 = new HashMap();
obj1.put("Alive is","Awesome");
obj1.put("Love","Yourself");
System.out.println(obj1);
}
} 
 
OUTPUT : [Alive is = Awesome, Love = Yourself]   


Just like TreeSet , TreeMap  elements are also sorted according to the natural ordering of its elements . If TreeMap objects can not be sorted in natural order than use compareTo() method to sort the elements of TreeMap object.


import java.util.TreeMap;

public class TreeMapExample {

public static void main(String[] args) {

TreeMap<String,String> obj1= new TreeMap<String,String>();
obj1.put("Alive is" , "Awesome");
obj1.put("Love" , "Yourself");
System.out.println(obj1);

}

}
 
OUTPUT : [Alive is = Awesome, Love = Yourself]   



2. Implementation : Internal HashMap implementation use Hashing.
TreeMap internally uses Red-Black tree implementation.

3. Null keys and null value : HashMap can store one null key and many  null values.
TreeMap can not contain null keys but may contain many null values.

4. Performance : HashMap  take constant time performance for the basic operations like get and put i.e O(1).
According to Oracle docs , TreeMap provides guaranteed log(n) time cost for the get and put method.

hashmap vs treemap in java with example
5. Speed :   HashMap is much faster than TreeMap, as performance time of HashMap is constant against the log time TreeMap for most operations.

6. Functionality :   Just like TreeSet , TreeMap is rich in functionality. Functions like pollFirstEntry() , pollLastEntry() , tailMap() , firstKey() , lastKey() etc. are not present in HashMap.

7.  Comparison : HashMap uses equals() method in comparison while TreeMap uses compareTo() method for maintaining ordering.

8. Interfaces implemented : HashMap implements Map interface while TreeMap implements NavigableMap interface.


Similarities between HashMap and TreeMap in Java

1. Fail-fast iterators : The iterator's returned by the both class are fail-fast . Hence , if the object is modified after the iterator is created , in any way except through the iterator's own remove() method , the iterator will throw the ConcurrentModificationException.

2. Clone() method  : Both HashMap and TreeMap uses shallow copy technique to create clone of their objects.

3. Not Thread Safe :  Both HashMap and TreeMap class are unsynchronized . In other words , multiple threads can access the same object at a given time.
Although you can externally make both the classes synchronized :

HashMap :      Map m = Collections.synchronizedMap(new HashMap (...));
TreeMap :       Map m = Collections.synchronizedSortedMap(new TreeMap (...));

4. Package :  Both classes belong to the same package java.util and both are the members of the Java Collections Framework.



When to Prefer TreeMap over HashMap 

1. Sorted elements are required instead of unordered  elements. The sorted list return by TreeMap is always in ascending order.

2. TreeMap uses Red-Black algorithm underneath  to sort out the elements . When one need to perform read/write operations frequently , then TreeMap is a good choice.



Recap: Difference between HashMap and TreeMap in Java



HashMapTreeMap
OrderingNoYes
ImplementationHashingRed-Black Tree 
Null Keys and Null valuesOne null key ,Any null valuesNot permit null keys ,but any null values
PerformanceO(1)log(n)
SpeedFastSlow in comparison
FunctionalityProvide Basic functionsProvide Rich functionality
Comparisonuses equals() methoduses compareTo() method
Interface implementedMapNavigable Map


In case you have any other query please mention in the comments .

Tuesday, November 24, 2015

Appium - How To Scroll Horizontal Tabs Using Appium In Android App

In android appium software automation test, You also needs to scroll tabs horizontally(from right to left or left to right) If there are multiple tabs In your android software app and you wants to navigate to the tab which Is displaying when you scroll tabs horizontally. Earlier In my previous post, We learnt how to scroll down In android software app using appium test. We also learnt how to swipe In android software app using driver.swipe() In THIS POST and using TouchAction class In THIS POST. Here we can use driver.swipe() method to swipe tabs from right to left. I have prepared very simple android software automation example to learn how to swipe android app's tabs In appium automation test.

Install API Demos App In Mobile Device
You can view my PREVIOUS POST to know from where to download API Demos App. Install It In your mobile device.

Aim To Achieve In This Appium Test
In this test, We wants to scroll tabs horizontally from right to left side until Tab 11 display as shown in bellow Image.


Manually you can view above given screen In your mobile device from API Demos App -> Views -> Tabs -> 5. Scrollable. You will find that top level tabs are scroll-able.

Before learning tabs scrolling In appium software automation test, I recommend you to read my previous post about vertical scrolling In appium test as we are going to use vertical scrolling in this example too.

Get Y Coordinates Of Tabs Grid Middle
To get Y Coordinates of tabs grid,
  1. Connect your mobile device with PC and open API Demos app In your device.
  2. Navigate manually to 5. Scrollable section as described above.
  3. Open uiautomatorviewer from tools folder of SDK. view THIS POST.
  4. Capture Screenshot by clicking on Capture screenshot button.
  5. Move your mouse at middle of tabs grid.
  6. Note down Y Coordinates as shown In bellow Image.

Create And Run Android Appium Tabs Scrolling Test
Create new ScrollTabs.java file under your project and copy paste bellow given test script In It.

Note : Please set your device's capabilities in bellow given test.
ScrollTabs.java
package Android;

import io.appium.java_client.android.AndroidDriver;

import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ScrollTabs {
AndroidDriver driver;
Dimension size;
@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ZX1B32FFXF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity","io.appium.android.apis.ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@Test
public void ScrollToTab() throws InterruptedException {
//Scroll till element which contains "Views" text If It Is not visible on screen.
driver.scrollTo("Views");
//Click on Views/.
driver.findElement(By.name("Views")).click();
System.out.println("Vertical scrolling has been started to find text -> Tabs.");
//Scroll till element which contains "Tabs" text.
driver.scrollTo("Tabs");
System.out.println("Tabs text has been found and now clicking on It.");
//Click on Tabs
driver.findElement(By.name("Tabs")).click();
//Click on Scrollable text element.
driver.findElement(By.name("5. Scrollable")).click();
System.out.println("Horizontal scrolling has been started to find tab -> Tab 11.");
//Used for loop to scroll tabs until Tab 11 displayed.
for(int i=0; i<=10; i++){
//Set implicit wait to 2 seconds for fast horizontal scrolling.
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
if(driver.findElements(By.name("Tab 11")).size()!= 0){
//If Tab 11 Is displayed then click on It.
System.out.println("Tab 11 has been found and now clicking on It.");
driver.findElement(By.name("Tab 11")).click();
break;
}else{
//If Tab 11 Is not displayed then scroll tabs from right to left direction by calling ScrollTabs() method.
ScrollTabs();
}
}
//Set implicit wait to 15 seconds after horizontal scrolling.
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

//Locate parent element of text area.
WebElement ele1 = (WebElement) driver.findElements(By.id("android:id/tabcontent")).get(0);
//Locate text area of Tab 11 using It's parent element.
WebElement ele2 = ele1.findElement(By.className("android.widget.TextView"));
//Get text from text area of Tab 11 and print It In console.
System.out.println("Text under selected tab is -> "+ele2.getText());
}

//To scroll tabs right to left In horizontal direction.
public void ScrollTabs() {
//Get the size of screen.
size = driver.manage().window().getSize();

//Find swipe start and end point from screen's with and height.
//Find startx point which is at right side of screen.

int startx = (int) (size.width * 0.70);
//Find endx point which is at left side of screen.
int endx = (int) (size.width * 0.30);
//Set Y Coordinates of screen where tabs display.
int YCoordinates = 150;

//Swipe tabs from Right to Left.
driver.swipe(startx, YCoordinates, endx, YCoordinates, 3000);
}

@AfterTest
public void End() {
driver.quit();
}
}

Test Script Description
In above test script, 
  • I have used for loop to continue execution until Tab 11 display on screen.
  • If condition Inside for loop will check If Tab 11 Is displayed or not.
  • If tab 11 Is displayed then click on It and break the loop.
  • Else Call ScrollTabs(); method which Is responsible for swiping tab from right to left.
  • Statements written bellow for loop will get text from  text area and print It In console.
Now I hope, You already learnt how to run appium software automation test In eclipse with testng. View my previous appium tutorials for more detail. When you run above test, It will Navigate to 5. Scrollable screen and then scroll tabs In horizontal direction until Tab 11 displayed.

This way you can scroll tabs in horizontal direction In your appium android test.

Saturday, November 21, 2015

Appium Android Example On How To Scroll Down To Text

Earlier In THIS POST, we learnt how to swipe In horizontal or vertical direction In any android software app using driver.swipe() and swiping element in horizontal direction using action chain In previous post. Most of android applications contain list view and you need to scroll down to select specific element. You can use scrollTo(String text) method of IOSElement class If you wants to scroll down till specific text in appium software automation test. Let's try to Implement It practically In android software appium automation test to know how scrollTo(String text) method works.

PREREQUISITES : All previous 21 steps of appium mobile software app automation tutorials (PART 1 and PART 2) should be completed.

Download And Install API Demos App
We will use API Demos In this example. You can download API Demos android software app from GOOGLE PLAY STORE or THIS PAGE. Install It In your mobile device.

Aim To Achieve In This Appium Test
We wants to scroll down till selected element which contains text "Tabs" as shown In bellow Image. And then we wants to tap on It("Tabs" text). Manually you can view bellow given scroll-able listing in API Demos software App from API Demos App -> Views.


So In appium test,
  1. First we will open API Demos App, 
  2. Tap on "Views".
  3. On next screen, Scroll down till element which contain text "Tabs".
  4. And tap on element which contain text "Tabs". 
Create And Run Android Appium scrollTo Text Test
Create ScrollingToText.java file under Android package of your project and copy paste bellow given test script In It.

Note : Please set your device's capabilities in bellow given test.
ScrollingToText.java
package Android;

import io.appium.java_client.android.AndroidDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ScrollingToText {
AndroidDriver driver;

@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ZX1B32FFXF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity","io.appium.android.apis.ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@Test
public void ScrollToText() throws InterruptedException {
//Scroll till element which contains "Views" text If It Is not visible on screen.
driver.scrollTo("Views");
// Click on Views/.
driver.findElement(By.name("Views")).click();
System.out.println("Scrolling has been started to find text -> Tabs.");
// Scroll till element which contains Tabs text.
driver.scrollTo("Tabs");
System.out.println("Tabs text has been found and now clicking on It.");
// Click on Tabs.
driver.findElement(By.name("Tabs")).click();
}

@AfterTest
public void End() {
driver.quit();
}
}

Test Script Description
If you look at above test example, We have used driver.scrollTo(String text) methods for scrolling. It will scroll down steps by step and look If given text Is displayed on screen or not. When text appears, It will stop scrolling.
  • First driver.scrollTo("Views"); will check if element containing test "Views" Is display on screen or not. If not display then It will scroll down down and check for text once again.
  • Same way, Second driver.scrollTo("Tabs"); will scroll down and check for text "Tabs".
To see scrollToText demo practically, Run above test using testng and appium and observe result on your android mobile screen.

This way you can scroll down vertically to find specific element and click on It.