MainMenu

Home Core Java Overview Maven Tutorials

Wednesday, 5 July 2017

Data Driven Framework in Appium for android



For Video Tutorial : Move on Youtube Channel


Note : Select the playlist as per your need & move with number sequence


Data Driven Framework in Appium:

For Video : CLICK HERE For Part1




Hello Friends,
In this tutorial we will discuss how to create Data Driven Framework in appium for Android.

It is very similar as we created in Selenium for any web application.

Click Here

for selenium data driven framework.

Suppose we have below scenarios/Task to automate on Android to add multiple contacts in android :-

Our Scenarios will be as below :
1).Open Android dialer
2).Click on contacts
3).Click on create contacts
4).Enter Name
5).Enter Mobile Number
6).Click save button
7).Click on home Button


We will write the code in eclipse to achieve the objective.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.apache.poi.ss.usermodel.DataFormatter;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;
import io.appium.java_client.remote.MobileCapabilityType;
public class Newtest2
{
static AndroidDriver driver;
XSSFWorkbook wb;
static XSSFSheet sheet;
FileInputStream fis;
@BeforeTest
public void g() throws IOException
{
File src = new File("D:\\study material\\Selenium Final complete\\Appium software\\contactsdata\\contact_data.xlsx");
fis = new FileInputStream(src);
wb = new XSSFWorkbook(fis);
sheet = wb.getSheetAt(0);
}
@Test
public void main() throws MalformedURLException, InterruptedException
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "LYF");
capabilities.setCapability(MobileCapabilityType.VERSION, "6.0.1");
capabilities.setCapability(MobileCapabilityType.PLATFORM, Platform.ANDROID);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Andriod");
capabilities.setCapability("appPackage", "com.android.dialer");
capabilities.setCapability("appActivity", "com.android.dialer.DialtactsActivity");
File file = new File("C:\\Users\\cchauhan\\Downloads\\New Appium\\src\\apk file\\.apk");
capabilities.setCapability("apk", file.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
for(int i =121 ; i<131; i++)
{
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.id("Contacts")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.id("Create new contact")).click();
List list = driver.findElementsByClassName("android.widget.EditText");
String data = sheet.getRow(i).getCell(0).getStringCellValue();
list.get(0).sendKeys(data);
//WebElement Name = driver.findElement(By.name("Name"));
//Name.sendKeys("csc");
driver.pressKeyCode(AndroidKeyCode.ENTER);
Thread.sleep(3000);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
DataFormatter formatter = new DataFormatter();
String val = formatter.formatCellValue(sheet.getRow(i).getCell(1));
list.get(1).sendKeys(val);
//WebElement number = driver.findElement(By.name("Phone"));
//number.sendKeys("9718632008");
driver.findElement(By.id("Save")).click();
Thread.sleep(5000);
driver.pressKeyCode(AndroidKeyCode.HOME);
Thread.sleep(3000);
driver.manage().timeouts().implicitlyWait(7, TimeUnit.SECONDS);
List list2 = driver.findElements(By.className("android.widget.TextView"));
list2.get(5).click();
}
}
}



Tags :-

Data driven framework in appium,

How to create data driven framework in appium

Code for data driven framework in appium,

Example of data driven framework in appium

No comments:

Post a Comment