Wednesday 4 September 2013

Take screenshot in WebDriver


File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("C:\\test\\sample.png"));

Monday 5 August 2013

Appium android example program for windows using java - native app

To perform the automation using appium for the native android app just .apk file is enough. No need of developers code at all.

When we write the appium script for automation we need to specify the package name and activity name. We can get package and all activity names from the .apk file itself. For this we need to convert .apk file to java class files. See here to perform that.


I used following environments to accomplish this example program,


  • Windows7
  • Android SDK
  • JDK
  • Eclipse
  • TestNG

Install and start the appium server:


Appium server for windows platform is just a zip folder. It contains all the packages needed for appium such as node, webdriver etc. We no need to install any APIs additionally

  • Download the latest AppiumForWindows.zip from here
  • Unzip the AppiumForWindows.zip
  • Click on the appium.exe present in the unzipped appium folder. It will be opened up as below,


Appium Server For Windows

  • Now click on the 'Launch' button, It will start the server at 127.0.0.1:4723 as below,

Appium server is started

  • Then run the below program once the android emulator is ready.

Appium example program for android


package com.qa.test;

import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class androidExample {
WebDriver driver = null;
         
        @BeforeMethod
         public void setup() {
                File appDir = new File("E://AndroidApps");
File app = new File(appDir, "myApp.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.2.2");
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
                // Here we mention the app's package name, to find the package name we  have to convert .apk file into java class files
capabilities.setCapability("app-package","com.myApp.activity");
                //Here we mention the activity name, which is invoked initially as app's first page.
capabilities.setCapability("app-activity","LoginActivity");
//capabilities.setCapability("app-wait-activity","LoginActivity,NewAccountActivity");
capabilities.setCapability("app", app.getAbsolutePath());

driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

         }

       @Test
public void loginTest() throws Exception {
driver.findElement(By.xpath("//EditText[@text='Email Address']")).sendKeys("tester@gmail.com");
driver.findElement(By.xpath("//LinearLayout/EditText[2]")).sendKeys("Testerpwd");
driver.findElement(By.xpath("//CheckBox")).click();
driver.findElement(By.xpath("//Button[@text='Login']")).click();

WebDriverWait wait = new WebDriverWait(driver,80);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//Button[@text='Logout']")));
driver.findElement(By.xpath("//Button[@text='Logout']")).click();

        }

       @AfterMethod
        public void tearDown() {
               driver.quit();
        }

}

Running this program will install the app in the emulator if it is not present already. If the app is installed already it will open and perform the automation steps.

If your app is already opened with some other activity(e.g. my profile page) appium will be waiting for the specified activity (com.myApp.activity.LoginActivity) when you run the automation script. In this case automation script will fail, since the app is opened with some other activity.

So it is better to start the appium server with an option full reset. Perform the following steps in appium GUI server,
  • Check the option 'Perform Full Reset'
  • Go to File > Preferences and check the option 'Reset Application State After Each Session'
When you use these options in the GUI server, you might also need to specify the app path, package and Activity name as below,

Start server with full reset

This will uninstall the app once your tests are completed and will install the app into emulator when the test starts initially.

Note:
  • Here I used the uiautomatorviewer to find the element hierarchy and then I constructed the xpath manually. To learn about constructing the xpath, please go here
  • You should set ANDROID_HOME and path for Android SDK in environment variable
  • Emulator adb device should have API level greater than or equal to 17


Wednesday 24 July 2013

How to handle StaleElementReferenceException?


Why StatleElementReferenceException is thrown?


StatleElementReferenceException indicates that a reference to an element is stale, means that element no longer appears on the DOM of the page.

For example let we consider the following code,

                List <WebElement> alllinks = driver.findElements(By.tagName("a"));

for(WebElement link : alllinks) {
link.click(); // It may cause StatleElementReferenceException 
                         driver.navigate().back();
}

Here the reference variable 'alllinks' has the reference of all the WebElements, those has anchor(//a) tag. Coming to below, the 'for' loop clicks on the each WebElement, then navigates to its corresponding page and comes back to the original page. Due to this navigation/refresh DOM references might be changed. But the reference variable 'alllinks' holds the previous references of WebElements. Now the reference of the element becomes 'stale'. In this case the StaleElementReferenceException is thrown.

How to handle StatleElementReferenceException?



You can avoid this StatleElementReferenceException be having following style of code,

             int sizeOfAllLinks = driver.findElements(By.tagName("a")).size();

            for (int index=0; index<sizeOfAllLinks; i++ ) {
                  getElementWithIndex(By.tagName("a"), index).click();
                  driver.navigate().back();
            }


            public WebElement getElementWithIndex(By by, int index) {
                  return webDriver.findElements(by).get(index);
            }

Convert .apk to java files


1. Change the extension of your .apk file to .zip
2. Then unzip the zip file, there you will see a file, named classes.dex. This file only has all the java class files
3. Now you need to convert the classes.dex file into jar file. We can do it by Dex2Jar. Download the it from the here  and unzip it.
4. Copy your classes.dex file into the unzipped Dex2Jar folder
5. Now go to the command line and go to the path of Dex2Jar folder, then run the below command

            dex2jar.bat classes.dex  ---> This will create a jar file in the unzipped folder.
6. Now you need to convert this jar file into java classes. For the you can use java decompiler. Download that from here

Friday 19 July 2013

How to install .apk file in emulator - windows platform

Open the emulator from the command line


Open the command prompt and go into the 'tools' folder of your Android SDK installed and run the below command,

            emulator -avd devicename

For example I have created an emulator already with the name 'test'. so the command would be as below 

            E:\adt-bundle-windows-x86-20130522\sdk\tools>emulator -avd test.

Install the .apk file into the emulator


Open the new command prompt and go into the 'platform-tools' folder of your Android SDK installed and run the below command,

           adb install apkFileNameWithPath

For example, I installe the myApp.apk into the opened emulator by the below command,

           E:\adt-bundle-windows-x86-20130522\sdk\platform-tools>adb install E:\AndroidWorkspace\appiumandroid\src\Resource\myApp.apk


Friday 12 July 2013

WebDriver TestNG example


public class GmailTestCases {

  @BeforeMethod
public void launch() {
driver= new FirefoxDriver();
  driver.get("http://gmail.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}

@AfterMethod
public void quit() {
driver.quit();
}


@Test
public void verifyLoginPage() {

String actual_title = driver.getTitle();
String expected_title = "Gmail: Email from Google";
Assert.assertEquals(expected_title, actual_title);
}


@Test
public void verifyLoginWithValidCredentials() throws Exception
{
driver.findElement(By.id("Email")).sendKeys("test@gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("validpassword");
driver.findElement(By.id("signIn")).click();
Thread.sleep(10000);
String expected_username = "Test user";
String actual_username   = driver.findElement(By.id("gbi4t")).getText();
Assert.assertEquals(expected_username, actual_username);
}



@Test
public void verifyLoginWithInValidCredentials() throws InterruptedException {
driver.findElement(By.id("Email")).sendKeys("test@gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("invalidpwd");
driver.findElement(By.id("signIn")).click();
Thread.sleep(10000);
                Assert.assertTrue(driver.getPageSource().contains("The username or password you entered is incorrect"));
}

@Test
public void verifyLinks() throws InterruptedException {

List <WebElement> alllinks = driver.findElements(By.tagName("a"));

for(int i=0;i<alllinks.size();i++) {
System.out.println(alllinks.get(i).getText());
}

for(int i=0;i<alllinks.size();i++){

alllinks = driver.findElements(By.tagName("a"));
alllinks.get(i).click();
Thread.sleep(1000);
driver.navigate().to("http://gmail.com");
Thread.sleep(1000);
}
}

================================================================

XML file

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <!-- Specify the test suite name --> <suite name="Gmail_Login" verbose="1" annotations="JDK"> <!-- Specify the test name --> <test name="gmail_Login_Scenarios" preserve-order="true"> <classes> <class name="packagename.GmailTestCases"> <methods> <include name="verifyLoginPage" /> <include name="verifyLoginWithValidCredentials" /> <include name="verifyLoginWithInValidCredentials" /> <include name="verifyLinks" /> </methods> </class> </classes> </test> </suite>




Mouse hover in WebDriver

'Action' class supports for mouse hover functionality as below,


                   WebElement element = driver.findElement(By.id("menu"));
                   Actions builder = new Actions(driver);
                  builder.moveToElement(element).build().perform();





Select value from drop down list using WebDriver

WebDriver provides the class named 'Select' which is in the package 'org.openqa.selenium.support.ui' and below methods to choose the value from the drop down list.

  • selectByVisibleText("text")
  • selectByValue("value")
  • selectByIndex(index number)

Note: This is applicable only if the drop down list implemented by <select> tag  in html as below,

Let us consider the face book sign-up page, which has the dropdown lists in the Birthday field as below,



Example Program:


It chooses month for the Birthday field.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class dropDownList{
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
                driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

                driver.get("http://www.facebook.com/");
              
                driver.manage().window().maximize(); 
// Chooses Apr month
Select brtmonth = new Select(driver.findElement(By.id("birthday_month")));
brtmonth.selectByVisibleText("Apr");
}

}




Webdriver example program

Naukri Login:



import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;

public class Login {
public static void main(String args[]) throws InterruptedException {

//Launches the firefox browser
WebDriver driver = new FirefoxDriver();
                driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

                // Loads the Naukri application
driver.get("http://www.naukri.com/");

                // Maximize the browser
                driver.manage().window().maximize();
                // Prints the title of the naukri application
System.out.println(driver.getTitle());
 
                // Enters the username
driver.findElement(By.id("username")).sendKeys("tester@gmail.com");

                // Enters the username
driver.findElement(By.id("password")).sendKeys("tester");

                // Clicks on the login button
driver.findElement(By.name("Login")).click();
Thread.sleep(8000); // Using sleep() is not a good practice, we need to use explicit wait, will see about this in later post

               // Stores the username displayed in the home page into the variable 'actual'
String actual = driver.findElement(By.id("nameDisplaySpan")).getText(); 
System.out.println("actual: "+actual);

                // Clicks on the log out link
driver.findElement(By.linkText("LogOut")).click();


                // Close the browser
                driver.close();

                // Quit the driver session
driver.quit();
}

}

Friday 28 June 2013

Selenium RC example program


Selenium RC(Remote Control) was familiar automation framework, which is released to overcome the disadvantages of the selenium IDE. Since Selenium RC supports for

  • multiple browsers
  • multiple languages and 
  • multiple platforms

 it became the favorite automation tool of the automatians. Selenium is an open source tool, Obviously this is also one of the major reason to become popular.

Selenium RC supports for the following languages,

  • C#
  • Java
  • Python
  • Perl
  • PHP
  • Ruby
  • Java script


Components of Selenium RC:


  • Selenium RC Server
  • Client library


Selenium RC Server:


Selenium Server(selenium-server-standalone -<version number>.jar) receives Selenium commands from your test program, interprets them, and reports back to your program the results of running those tests.

The RC server bundles Selenium Core and automatically injects it into the browser. This occurs when your test program opens the browser (using a client library API function). Selenium-Core is a JavaScript program, actually a set of JavaScript functions which interprets and executes Selenese commands using the browser’s built-in JavaScript interpreter.

The Server receives the Selenese commands from your test program using simple HTTP GET/POST requests. This means you can use any programming language that can send HTTP requests to automate Selenium tests on the browser.

Client Library:


The client libraries provide the programming support that allows you to run Selenium commands from a program of your own design. There is a different client library for each supported language.

A Selenium client library provides a programming interface (API), i.e., a set of functions, which run Selenium commands from your own program. Within each interface, there is a programming function that supports each Selenese command.

The client library takes a Selenese command and passes it to the Selenium Server for processing a specific action or test against the application under test (AUT). The client library also receives the result of that command and passes it back to your program. Your program can receive the result and store it into a program variable and report it as a success or failure, or possibly take corrective action if it was an unexpected error.




Sample program


import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class TestNaukri {

public static void main(String[] args) throws InterruptedException {

String expected = "G.Elangovan";

Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.naukri.com");
selenium.start();
selenium.open("/");
selenium.windowMaximize();
Thread.sleep(5000);

selenium.type("id=username", "tester@gmail.com");
selenium.type("id=password", "password");
selenium.click("name=Login");

Thread.sleep(5000);
String actual = selenium.getText("id=nameDisplaySpan");

System.out.println("usernmae is: "+actual);

boolean condition = expected.equals(actual);
System.out.println(condition);

selenium.close();
selenium.stop();
}

}

How to start the selenium server:


Before we run this program we have to start to the selenium server as below,

  • Open the command prompt
  • Go to the path of the folder, where you keep selenium server
  • Enter the command 
  •         java -jar selenium-standalone-server<version-number>.jar
  • Hit the enter key
Now selenium server is started.

Now if we run the above sample program, it will run successfully.

Friday 7 June 2013

How to use Appium Inspector???....

Appium Inspector


Initially when I started to learn about appium inspector and its usage, I did not get better documentation with the steps on it. Finally I got it with the help of appium google group and some exploration. So I thought to document that here, and it would be helpful for new starters...

I used appium inspector for the following purpose,


  • To understand the element hierarchy
  • To find the xpath, name and value of the objects
  • To record the manual actions


The steps to use appium inspector are as below,



  • Initially download the appium.app from here, then add it to the Applications in your machine
  • Now Double click on the appium.app, it will open the appium server with the default IP Address 0.0.0.0 and  the port 4723 as below,
Appium Server



  • Next we have to specify the app, which we want to open in appium inspector.  
                 1. Check the check box 'App Path', Now 'Choose' button is enabled

                 2. Click on the 'Choose' button and select your .app file from your local, e.g. Recipes.app

                                 
Add the .app file in the server
                                 

  • Now click on the 'Launch' button, Once you launched the appium server, the blue color icon, which present beside the 'Launch' button is enabled.
       
Blue color icon is enabled


  • Click on the blue color icon, it will open up the appium inspector and simulator with your application as below,


Appium Inspector



  • Now you will see the element hierarchy of the application in the first column of appium inspector.
  • Choosing the particular element will display ,

             1. Its childs in the second column
             2. Highlights the object in the app.
             3. Element's xpath and its attributes at the right bottom corner.


Parts of Appium Inspector

  • And you can do actions by clicking on the action buttons Tap, Swipe etc displayed in the left bottom of the appium inspector.

  • By clicking on the 'Record' button we can create the automation script as below, you can see the recording script below the appium inspector,


Recording




Tuesday 21 May 2013

Construction of Xpath and Css selectors


Construction of Xpath and CSS selectors


As we know that webdriver supports for different types of locators to identify the web elements(objects i.e username, password etc). 

The different kinds of locators are ,
  • id
  • name
  • xpath
  • css selector
  • class name
  • tag name etc.


The priority of choosing the locator type is id/name, CSS selector and xpath.

Let see how to construct the xpath/css selector for web elements.

Xpath construction:


Let we consider the below login form. In this we will construct the xpath for user name, password text boxes, submit and reset buttons.



The HTML source code for this login page is as follows,


<html>
<title>Welcome to the application!!</title>
<body>
<form name="loginForm">
<table border="1">
<tr>
<td>User Name: </td>
<td>
<input name="username_name" id="username_id" type="text"
class="article-head"/>
</td>
</tr>
<tr>
<td>Password: </td>
<td>
<input name="password_name" id="password_id" type="password"
class="article-head"/>
</td>
</tr>
<tr>
<td>
<input name="login_name" id="login_id" label="Submit" type="button" class="article-head" onClick="submitAction()"/>
</td>
<td>
<input name="reset_name" id="reset_id" label="Reset" type="button" class="article-head" onClick="cancelAction()"/>
</td>
</tr>
</table>
</form>
</body>
</html>

Xpath for user name text field:

Absolute path: html/body/form/table/tr[1]/td[2]/input
Relative path: //input[@id='username_id']
                         //input[@name='username_name']
                         //input[1]

   Also we can use AND OR operators here, as below

                         //input[@id='username_id' and @name='username_name']

Xpath for Submit button:

Absolute path: html/body/form/table/tr[3]/td[1]/input
Relative path: //input[@id='login_id']
                         //input[@name='login_name']
                         //input[3]

   Also we can use AND OR operators here, as below

                         //input[@id='login_id' and @name='login_name']

As same as we can construct the xpath for password text field and reset button.

Xpath for dynamically changing objects:

Let we consider a situation. We want to construct the xpath for the user name text field, which has only two attributs id and type. Also the id is not a constant one, which is dynamic as below,

<input id="username_45833" type="text">

The number in the id name is changing dynamically for every build. In this case using  //input[@id='username_45833'] is not the correct idea.

To accomplish this we have to use the starts-with() function available in the xpath as below

//input[starts-with(@id, 'username_')].

Also we can use ends-with() and contains() method above. For more information about understanding the xpath read here 

Monday 20 May 2013

How to setup Selenium grid

Selenium Grid:


Selenium grid concept is used to distribute test cases and run multiple test cases at the same time in
  • The same machine - same browsers/ different browsers
  • Different machines - same browsers/ different browsers
  • Different OS etc.
While reading about selenium grid you could have seen two technical terms names hub and node mainly.

Hub is a central point, which allocates the available browsers to the nodes
Node is nothing but, it is an instance which  needs to be registered in the hub.

Grid Set up:

  1. Run tests cases in the same machine
  2. Run test cases in different machines

Run tests cases in the same machine:

I have two tests in the xml suite file. I want to run these two tests parallel in the same machine.

Step 1: Start the hub


Open the command prompt and go to the directory where the selenium-server.jar is available. Then type the following command and hit the enter.

                  java -jar selenium-server.jar -role hub

Here we are starting the selenium server with the hub role. It starts at the port 4444 as default. If you want to start the hub in different port you can use the parameter -port ( java -jar selenium-server.jar -role hub -port 6666)

Now hub is started and if you go to this link http://localhost:4444 you will see the grid details

Step 2: Create/Register node in hub


Open the command prompt and go to the directory where the selenium-server.jar is available. Then type the following command and hit the enter.

                  java -jar selenium-server.jar -role node -hub http://localhost:4444/grid/register

This will register the node with the hub. Now if you look http://localhost:4444/grid/console you will the available browsers for our test.

Also you can particularly specify the browser name, maximum instances, port and rc/webdriver etc as below,

java -jar selenium-server-.jar -role webdriver -hub http://localhost:4444/grid/register -port 5556 -browser browserName=firefox,maxInstances=10














Sample script using Appium for native iOS application

iOS automation using Appium:


Appium is an open source automation tool for native and hybrid apps. It supports for both Android and iOS platforms. Appium drives the device/emulator/simulator using the Apple's UIAutomation library or Android's UiAutomator framework using Selenium's Webdriver JSON wire protocol. So we can use the languages for scripting, which all supported by Selenium.

Requirements:

  • MAC OS X 10.7 or higher
  • Xcode and command line tools(xcode version 4.6.2 would be fine)
  • Node.js
  • Appium.app
  • Eclipse
  • TestNG

1. Prepare the application to be automated:


We need the .app file for appium automation. So download any iOS application and build the .app file.

I downloaded the iOS app named iPhoneCoreDataRecipes from the apple website. The app looks like as below,

                                                            Sample Recipe iOS application

Steps:


  • Download the application from  iPhoneCoreDataRecipes
  • Extract it and import it into the xcode.
  • Run the project, Ensure that the simulator is opened up with the application.
  • Open the terminal and go to the project folder
  • Run the following command to build the .app file

                     xcodebuild -sdk iphonesimulator6.1

It will build the app and generate the Recipe.app file in yourProjectfolder/Build/Release-iphonesimulator, which is the only one we need to give in our automation script.

Now the application is ready to be automated :)

2. Prepare the machine for iOS automation:


We need node.js to work with appium if we didn't use appium.app. Just follow the below steps,

  • Install node.js from the site http://nodejs.org/
  • Install webdriver API to the node with the below command,

                       sudo npm install wd
           here npm represents that Node.js Package Manager

  • Install Appium to the machine with the below command

                      sudo npm install appium -g

  • Now start the appium server with the below command,

                      appium &

Now appium server is started in the default port 4723 and the IP Address 0.0.0.0 (http://0.0.0.0:4723) as below,

                                                              Appium server is started


3. Prepare the automation script:


Actually I do all the scripts using java language. So I use Eclipse IDE and TestNG for scripting.

The goal of the following script is add the recipe named 'Pizza' in the recipe list and verify its presence.

package com.qa.test;

import java.io.File;
import java.net.URL;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class TestRecipe {

public WebDriver driver = null;

@BeforeMethod
public void setUp() throws Exception {
// set up appium
File appDir = new File("/Users/Elang/Documents/iPhoneApps/iPhoneCoreDataRecipes/Build/Release-iphonesimulator");
File app = new File(appDir, "Recipes.app");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
capabilities.setCapability(CapabilityType.VERSION, "6.1");
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
}

@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}


@Test
public void testAddRecipes() throws InterruptedException {

String recipeName = "Pizza";
String recipeDescription = "My lovable dish";
String preparationTime = "1 hour";

driver.findElement(By.name("Add")).click();
driver.findElement(By.xpath("//textfield[1]")).sendKeys(recipeName);
driver.findElement(By.name("Save")).click();

driver.findElement(By.name("Edit")).click();

driver.findElement(By.xpath("//tableview[1]/textfield[2]")).sendKeys(recipeDescription);
driver.findElement(By.xpath("//tableview[1]/textfield[3]")).sendKeys(preparationTime);

driver.findElement(By.name("choosePhoto")).click();
driver.findElement(By.xpath("//tableview[1]/cell[1]/text[1]")).click();
driver.findElement(By.xpath("//tableview[1]/cell[1]/image[1]")).click();
driver.findElement(By.name("Done")).click();

driver.findElement(By.xpath("//navigationBar[1]/button[1]")).click();

                // Verify the presence of added recipe.
List<WebElement> recipesDetails = driver.findElements(By.xpath("//tableview[1]/cell"));
//System.out.println("No. of Recipes: "+recipesDetails.size());
boolean result = false;
for(WebElement recipeDetails : recipesDetails) {
//System.out.println("details: "+recipeDetails.getAttribute("name"));
if(recipeDetails.getAttribute("name").equals(recipeDescription+", "+preparationTime+", "+recipeName)) {
result = true;
}
}
Assert.assertTrue(result, "Recipe is not present");
}

}

I used Appium inspector to identify the element locators. See here about how to use the appium inspector.

For the example of Android native app automation in WINDOWS platform, please look at here.


References: