Skip to content

Instantly share code, notes, and snippets.

@ckzgraphics
Last active November 20, 2018 04:26
Show Gist options
  • Select an option

  • Save ckzgraphics/9480fff4a0dae95144310ea8010f06c5 to your computer and use it in GitHub Desktop.

Select an option

Save ckzgraphics/9480fff4a0dae95144310ea8010f06c5 to your computer and use it in GitHub Desktop.
import java.util.concurrent.TimeUnit;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.io.File;
import java.io.FileWriter;
import java.net.MalformedURLException;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Android_Native_Scroll {
public static final String userName = "<USERNAME>";
public static final String accessKey = "<ACCESS_KEY>";
public static void main(String args[]) throws MalformedURLException, InterruptedException {
AppiumDriver driver = null;
DesiredCapabilities caps = new DesiredCapabilities();
WebDriverWait wait = null;
Actions act = null;
TouchAction touch = null;
MobileElement mobile_ele = null;
JavascriptExecutor js = null;
caps.setCapability("build", "Support Automate");
caps.setCapability("name", "Test: Wiki App");
caps.setCapability("device", "Samsung Galaxy S8 Plus");
caps.setCapability("app","bs://c463fb7764df0f41ebe1f4f44b0240d75344cc83");
caps.setCapability("browserstack.debug", "true");
caps.setCapability("browserstack.deviceLogs", "true");
caps.setCapability("browserstack.appium_version", "1.9.1");
try{
driver = new AndroidDriver(new URL("http://"+userName+":"+accessKey+"@hub-usw.browserstack.com/wd/hub"), caps);
wait = new WebDriverWait(driver, 2000);
driver.manage().timeouts().implicitlyWait((long)100,TimeUnit.MILLISECONDS);
act = new Actions(driver);
js = (JavascriptExecutor)driver;
touch = new TouchAction(driver);
Thread.sleep(2000);
System.out.println("---> Current Context :: " + driver.getContext());
Set<String> context = driver.getContextHandles();
System.out.println("---> PRINTING AVAILABLE CONTEXTs");
for (String string : context) {
System.out.println("---> " + string);
}
mobile_ele = (MobileElement) wait.until(ExpectedConditions.visibilityOf(driver.findElement(MobileBy.xpath(".//android.widget.TextView[@text='Featured article']"))));
Thread.sleep(3000);
touch.press(mobile_ele).moveTo(0, 50).release().perform();
Thread.sleep(10000);
System.out.println("\n\n DONE");
} catch (Exception e){
e.printStackTrace();
} finally {
if(driver != null){
driver.quit();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment