how to scrollTo and swipe with java client 3.2.0 and appium 1.4.13 ?
created
Nov '15
last reply
Oct '17
- 14
replies
- 11.1k
views
- 6
users
- 2
likes
- 2
links
how to scrollTo and swipe with java client 3.2.0 and appium 1.4.13 ?
private IOSDriver<WebElement> driver;
private ScreenRecorder screenRecorder;
@Test
public void f() {
}
@BeforeMethod
public void setUp() throws Exception {
// set up appium
// JSONObject obj = new JSONObject(" .... ");
// String pageName = obj.getJSONObject("pageInfo").getString("pageName");
//
// JSONArray arr = obj.getJSONArray("posts");
// for (int i = 0; i < arr.length(); i++)
// {
// String post_id = arr.getJSONObject(i).getString("post_id");
// }
DesiredCapabilities capabilities = new DesiredCapabilities();
//real device
// capabilities.setCapability("deviceName", "iPad");
// capabilities.setCapability("udid","c0ff732e91bae98e61a11ce056dd727f30f5a2ae");
// capabilities.setCapability("bundleid", "com.anghami.anghami");
// capabilities.setCapability("ipa", "/Users/MacBookair2014/Desktop/Anghami.ipa");
//simulator
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "8.4");
capabilities.setCapability("deviceName", "iPhone 5");
capabilities.setCapability("app", "/Users/MacBookair2014/Desktop/Anghami.app");
driver = new IOSDriver<WebElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
JavascriptExecutor js = (JavascriptExecutor)driver;
startRecording();
driver.findElement(By.name("Let's start!")).click();
driver.findElement(By.name("Email Login")).click();
// System.out.println(driver.findElementByIosUIAutomation("applications()[1].windows()[1].textFields()[1]").getAttribute("value"));
driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]").sendKeys("roygeagea@gmail.com");
driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]")).sendKeys("royanghami");
driver.findElement(By.name("Login")).click();
// if(driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[8]")) != null)
// {
// driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[8]")).click();
// }
Thread.sleep(15000);
// js.executeScript("mobile: scrollTo", new HashMap() {{ put("element", driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[2]/UIATableCell[5]")).getId()); }});
// driver.findElement(By.name("Menu Menu")).click();
// driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[5]")).click();
//not functional on sim and real
// HashMap scrollObject = new HashMap();
// scrollObject.put("direction", "down");
// js.executeScript("mobile: scroll", scrollObject);
//not functional on sim and real
driver.swipe(100,500,100,100,900);
//not functional on sim and real
// HashMap swipeObject = new HashMap ();
// swipeObject.put("startX", 172);
// swipeObject.put("startY", 502);
// swipeObject.put("endX", 172);
// swipeObject.put("endY", 170);
// swipeObject.put("duration", 2000);
// js.executeScript("mobile: swipe", swipeObject);
//not functional on sim and real
// HashMap swipeObject = new HashMap();
// swipeObject.put("element", "Editors' Choice");
// js.executeScript("mobile: scrollTo", swipeObject);
driver.scrollTo("Editors' Choice");
stopRecording();
driver.close();
System.out.println("App launched");
The signature for AppiumDriver swipe is:
public void swipe(int startx, int starty, int endx, int endy, int duration)
You can try directly with TouchAction also or use swipe method in MobileElement.java. Go to https://github.com/appium/java-client/405 and search for the terms you want.
Finally you also have selenium swipe.
@Telmo_Cardoso Swipe gesture is not broken anymore in simulator with Xcode 7. It works perfectly on my machine
Hi Kishore
Here is the JAVA API documentation for Appium TouchAction class.
http://appium.github.io/java-client/432
Thanks
Ravi
hi i am unable call.
driver.Swipe(); method …please help me on this
public void scroll() throws InterruptedException
{
Dimension dimensions = d.manage().window().getSize();
for(int i=1; i>4; i++)
{
Double screenHeightStart = dimensions.getHeight() * 0.5;
int scrollStart = screenHeightStart.intValue();
Double screenHeightEnd = dimensions.getHeight() * 0.2;
int scrollEnd = screenHeightEnd.intValue();
**d.swipe**(0, scrollStart, 0, scrollEnd, 2000);
}
}
unable use swipe method