Appium Send Send my photo album

Many app has access to the phone book, and then sending the picture. This feature is more often the test point. In general, opening the phone book, there is a thumbnail of the album. As shown below:

This thumbnail in appium not find any positioning. xpath did not. In the following cases, how to choose the picture, to send it. Solution to the problem comes from this blog
https://appiumpro.com/editions/32
appium1.7 introduced to locate the pictures based on policy elements. Incoming picture base64 encoded bits, then the introduction of opencv (open source library to match the view of the process of picture elements.
First of all we have to do is to introduce the installation opencv4nodejs library .opencv4nodejs library follows https://www.npmjs.com/package/opencv4nodejs
installation the steps in this link: https://gist.github.com/adwellj/61e7f202bcfe5b96f312293e9c812ca6
note, here are two ways to say, simply select them like a.
listed below are the main code:

获取图片的Base64编码:
public String getPictureImageB64() throws URISyntaxException,IOException{
String ImageName="picturetest02.jpg";
URL refImgUrl=getClass().getClassLoader().getResource(ImageName);
File refImgFile=Paths.get(refImgUrl.toURI()).toFile();
return Base64.getEncoder().encodeToString(Files.readAllBytes(refImgFile.toPath()));
}
将Base64编码变成对应的appium中MobileBy(MobileBy需要java-clinet7.0 以上的版本,需要更新客户端库。
By imageBy=MobileBy.image(getPictureImageB64());
这里只需要将你所要选择图片放到项目的resources文件夹即可。上述代码就可以找到。
appium定位元素位置:
public void SelectImageElement(AndroidDriver driver,By ImageBy){
WebDriverWait wait=new WebDriverWait(driver,10);
AndroidElement androidElement=null;
wait.until(ExpectedConditions.presenceOfElementLocated(ImageBy)).click();

    }
}

在appium的官方文档上,其实也谈到一个方法。
http://appium.io/docs/en/advanced-concepts/image-elements/
driver.findElementByImage(String Base64Code)。
也提到了返回的图片元素只能进行
click
isDisplayed
getSize
getLocation
getLocationInView
getElementRect
上述的操作,而不能进行别的类似sendKeys操作等。

Guess you like

Origin www.cnblogs.com/NaCl/p/11115920.html