I was using AppiumStudio tool to run some tests on an Android Applicative that I’ve created. The tool auto generates a Java Code and I took that code to test on Eclipse. But when I pasted the code, Java doesn’t recognize driver.swipe(); even with all imports done. Here is the code that the tool generated
package Appium;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.PerformsTouchActions;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
import java.time.Duration;
//import org.openqa.selenium.support.ui.Duration;
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.openqa.selenium.Dimension;
import org.junit.*;
import java.net.URL;
import java.net.MalformedURLException;
public class Teste {
private String reportDirectory = "reports";
private String reportFormat = "xml";
private String testName = "Cadastro_base";
protected AndroidDriver<AndroidElement> driver = null;
DesiredCapabilities dc = new DesiredCapabilities();
@Before
public void setUp() throws MalformedURLException {
dc.setCapability("reportDirectory", reportDirectory);
dc.setCapability("reportFormat", reportFormat);
dc.setCapability("testName", testName);
dc.setCapability(MobileCapabilityType.UDID, "5210ce98fa7eb4b3");
driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
}
@SuppressWarnings({ "rawtypes", "deprecation" })
@Test
public void testCadastro_base() throws InterruptedException {
driver.findElement(By.xpath("//*[@id='emailView']")).sendKeys("raikathekiller@mailinator.com");
Thread.sleep(3000);
new TouchAction(driver).press(point(500, 596)).waitAction(waitOptions(Duration.ofMillis(1000))).
moveTo(point(518, 478)).release().perform();
new TouchAction(driver).press(point(434, 468)).waitAction(waitOptions(Duration.ofMillis(1000))).moveTo(point(471, 312)).release().perform();
Thread.sleep(3000);
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@id='password_view']")).sendKeys("Smart2000");
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='confirm_password_view']")));
driver.findElement(By.xpath("//*[@id='confirm_password_view']")).sendKeys("Smart2000");
driver.findElement(By.xpath("//*[@id='name_and_surname_view']")).sendKeys("TED USP");
driver.findElement(By.xpath("//*[@id='cpfView']")).sendKeys("41801452865");
new TouchAction(driver).press(point(531, 465)).waitAction(waitOptions(Duration.ofMillis(1000))).moveTo(point(637, 175)).release().perform();
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@id='dobView']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@text='2018']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@text='2020']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@contentDescription='13 fevereiro 2020']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@text='OK']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@id='phoneView']")).sendKeys("13982133161");
driver.findElement(By.xpath("//*[@id='generView']")).click();
driver.findElement(By.xpath("//*[@text='Feminino']")).click();
TouchAction tAction=new TouchAction(driver);
new TouchAction(driver).moveTo(584, 1013);
driver.findElement(By.xpath("//*[@text='Cadastrar']")).click();
//driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"com.consul.android.smartbeer.staging:id/register_button\")").click();
Thread.sleep(8000);
}
private WaitOptions waitOptions(java.time.Duration duration) {
// TODO Auto-generated method stub
return null;
}
private PointOption point(int i, int j) {
// TODO Auto-generated method stub
return null;
}
// @After
// public void tearDown() {
// Thread.sleep(8000);
// }
}
My question is: To run the test correctly I need to Swipe between fields on the screen. How can I convert the command driver.swipe to a TouchAction or a working command that will do the touch and move action?