[英]How to Pinch - Zoom in and Zoom out a image openened in android app in Appium
Here's the test scenario i'm trying to automate on the app but got stuck, 这是我试图在应用程序上自动执行但被卡住的测试场景,
Appium version: 1.4.16.1 API Level 19 Appium版本:1.4.16.1 API级别19
Below is the code snippet: 下面是代码片段:
@Test
public void openph() throws InterruptedException {
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc='Navigate up']")).click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath("//android.widget.RelativeLayout[@index='3']")).click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath("//android.widget.ImageView[@index='1']")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//android.widget.LinearLayout[@index='2']")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//android.widget.CheckedTextView[@text='Photos only']")).click();
List<WebElement> ops = driver.findElements(By.xpath("//android.widget.ImageView"));
ops.get(2).click();
driver1.zoom(25, 45);
driver1.pinch(25, 45);
driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
}
Can anyone please help me to get fix this. 谁能帮我解决这个问题。
Currently it's throwing nullpointer exception 当前它引发nullpointer异常
Is it possibly because you have two different drivers ( driver and driver1
)? 是否可能是因为您有两个不同的驱动程序(
driver and driver1
)? Appium is currently able to run one driver on one session at a time. Appium当前能够一次在一个会话上运行一个驱动程序。
Also I don't know what you are doing with these lines: driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
我也不知道你在用这些行做什么:
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
You only need to start that once per driver (it also isn't very good as it will slow down your tests a lot, it would be better to use a WebDriverWait(Driver, <defined wait time>
您只需要为每个驱动程序启动一次(这也不是很好,因为它会大大降低测试速度,因此最好使用
WebDriverWait(Driver, <defined wait time>
//Use this below the code it work fine.
import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Zoom_and_pinch {
public static void main(String[] args) throws InterruptedException, MalformedURLException {
// TODO Auto-generated method stub
File app= new File("D:\\Testing\\com.davemorrissey.labs.subscaleview.sample.apk");
//Launch app
DesiredCapabilities capabilities= new DesiredCapabilities();
//device details
capabilities.setCapability("deviceName", "GT-I9300I");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4.4");
//app details
capabilities.setCapability("app",app.getAbsolutePath());
//appium server details
AndroidDriver driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
//wait
Thread.sleep(4000);
driver.findElementById("com.davemorrissey.labs.subscaleview.sample:id/basicFeatures").click();
Thread.sleep(4000);
WebElement ele_image = driver.findElementById("com.davemorrissey.labs.subscaleview.sample:id/imageView");
int x1= ele_image.getLocation().getX();
int y1= ele_image.getLocation().getY();
System.out.println("x is "+x1+"y1 is "+y1);
int x=ele_image.getLocation().getX()+ele_image.getSize().getWidth()/2;
int y= ele_image.getLocation().getY()+ele_image.getSize().getHeight()/2;
//Zoom
TouchAction finger1= new TouchAction(driver);
finger1.press(ele_image, x, y-20).moveTo(ele_image, x, y-200);
TouchAction finger2= new TouchAction(driver);
finger2.press(ele_image, x, y+20).moveTo(ele_image, x, y+200);
MultiTouchAction action= new MultiTouchAction(driver);
action.add(finger1).add(finger2).perform();
Thread.sleep(8000);
//Pinch
TouchAction finger3= new TouchAction(driver);
finger3.press(ele_image, x, y-200).moveTo(ele_image, x, y-20);
TouchAction finger4= new TouchAction(driver);
finger4.press(ele_image, x, y+200).moveTo(ele_image, x, y+20);
MultiTouchAction action2= new MultiTouchAction(driver);
action2.add(finger3).add(finger4).perform();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.