MainMenu

Home Java Overview Maven Tutorials

Sunday, 30 July 2017

How to scroll in appium



For Video Tutorial : Move on Youtube Channel


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


Hello Friends,
In this tutorial, we will discuss how to scroll down the application in appium.
As we know that ScrollTo("") does not work in new release of appium, so here is new method
The method is simple just use the Dimension class.
Get the size of screen & define the start & end of scroll.
Below is sample code, which will open the whatsapp & scroll it.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
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.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
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 io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
public class GetwhatsappContacts
{
AndroidDriver driver;
List list;
File src;
XSSFWorkbook wb;
XSSFSheet sheet;
XSSFRow row1;
String gn;
@BeforeTest
public void g() 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.whatsapp");
capabilities.setCapability("appActivity", "com.whatsapp.Main");
File file = new File("C:\\Users\\cchauhan\\Downloads\\New Appium\\src\\apk file\\base.apk");
capabilities.setCapability("apk", file.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(2000);
}
@Test
public void j() throws InterruptedException
{
Thread.sleep(4000);
Dimension dimensions = driver.manage().window().getSize();
Double screenHeightStart = dimensions.getHeight() * 0.99;
int scrollStart = screenHeightStart.intValue();
Double screenHeightEnd = dimensions.getHeight() * 0.2;
int scrollEnd = screenHeightEnd.intValue();
driver.swipe(0,scrollStart,0,scrollEnd,5000);
Thread.sleep(1000);
}
}


Thanks :)

No comments:

Post a Comment