How can we write scrolling code in Appium with Java?
Here is what I want to do,
- Open the application.
- Scroll down to the footer.
- Scroll back up.
This is the code that I have written:
base.java ;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
public class base {
public static AndroidDriver<AndroidElement> capabilities() throws MalformedURLException
{
File f = new File("src");
File fs = new File(f, "ApiDemos-debug.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME,"oppo A5s");
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Uiautomator2");
cap.setCapability(MobileCapabilityType.VERSION, "8.1.0");
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
AndroidDriver<AndroidElement>driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
return driver ;
}
Scolling class;
import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
public class ScrolingDemo extends base {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
AndroidDriver<AndroidElement>driver=capabilities();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//android.widget.TextView[@text='Views']")).click();