Scroll script using testng

0

I’m writing script to scroll mobile application up and down but Appium studio code with testng framework not working in Eclipse.

I’m new with this kind of script and testing please help to fix it.

I tried Appium studio code. but it need to fix to run script.

//package <set your test package>;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.TouchAction;
import java.time.Duration;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.testng.annotations.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.logging.Level;

public class scrollandsave {
    private String reportDirectory = "reports";
    private String reportFormat = "xml";
    private String testName = "scrollandsave";
    protected AndroidDriver<AndroidElement> driver = null;

    DesiredCapabilities dc = new DesiredCapabilities();

    @BeforeMethod
    public void setUp() throws MalformedURLException {
        dc.setCapability("reportDirectory", reportDirectory);
        dc.setCapability("reportFormat", reportFormat);
        dc.setCapability("testName", testName);
        dc.setCapability(MobileCapabilityType.UDID, "330033acecf394bd");
        driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
        driver.setLogLevel(Level.INFO);
    }

    @Test
    public void testscrollandsave() {
        new TouchAction(driver).press(480, 1348).waitAction(Duration.ofMillis(624)).moveTo(338, 312).release().perform();
        new TouchAction(driver).press(591, 1376).waitAction(Duration.ofMillis(592)).moveTo(421, 138).release().perform();
        driver.findElement(By.xpath("(//*[@id='listAllImgByCat']/*/*/*/*[@id='icPlayVideo'])[1]")).click();
        new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text='EDIT']")));
        driver.findElement(By.xpath("//*[@text='EDIT']")).click();
        new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text='SAVE']")));
        driver.findElement(By.xpath("//*[@text='SAVE']")).click();
        driver.findElement(By.xpath("//*[@text='Export as GIF']")).click();
        driver.findElement(By.xpath("//*[@id='btnHome']")).click();
    }

    @AfterMethod
    public void tearDown() {
        driver.quit();
    }
}