appium 版本更新后的方法变化更新收集 ---持续更新
在高版本的android手机(例如android 7.0 , 8.0等等),必须使用高版本的appium, 以及对应的selenium版本,那么很多的appium或者selenium方法会变得无法直接调用,这里是一个汇总收集。
本文以io.appium.java-client 3.14.0版本为例,为2018年最新版本
最新引入了
PointOption
ElementOption
WaitOptions
KeyEvent
TouchAction
The-event firing (时间与元素监听)
AppiumFunction (新的等待元素的方法)
//老版本的操作线,从元素附近的某个点移动到元素中心,新版本不允许出现: press(element,x,y)的语法
// TouchAction action0 = (new TouchAction(driver)).press(el, center.getX(), center.getY() - yOffset).moveTo(el).release();
// TouchAction action1 = (new TouchAction(driver)).press(el, center.getX(), center.getY() + yOffset).moveTo(el).release(); TouchAction action0 = (new TouchAction(driver)).press(PointOption.point(center.getX(), center.getY() - yOffset)).moveTo(ElementOption.element(el)).release();
TouchAction action1 = (new TouchAction(driver)).press(PointOption.point(center.getX(), center.getY() + yOffset)).moveTo(ElementOption.element(el)).release();
action.press(PointOption.point(x, y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500))).perform();
KeyEvent key=new KeyEvent();
key.withKey(AndroidKey.KEYCODE_ZOOM_IN);
//driver.pressKeyCode(KEYCODE_ZOOM_IN);//老版操作: 放大键
JAVA-Client 在新版里面提供了如下(等待元素)方法:
//waiting for elements
private final AppiumFunction<WebDriver, List<WebElement>> searchingFunction = input -> {
List<WebElement> result = input.findElements(By.tagName("a")); if (result.size() > 0) {
return result;
}
return null;
}; //waiting for some context using regular expression pattern
private final AppiumFunction<Pattern, WebDriver> contextFunction = input -> {
Set<String> contexts = driver.getContextHandles();
String current = driver.getContext();
contexts.forEach(context -> {
Matcher m = input.matcher(context);
if (m.find()) {
driver.context(context);
}
});
if (!current.equals(driver.getContext())) {
return driver;
}
return null;
};
等待元素可以直接使用:
//using one function as pre-condition
@Test public void tezt() {
....
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("WEBVIEW"))
.withTimeout(30, TimeUnit.SECONDS);
List<WebElement> elements = wait.until(searchingFunction.compose(contextFunction));
....
}
//using one function as post-condition
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait; @Test public void tezt() {
....
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("WEBVIEW"))
.withTimeout(30, TimeUnit.SECONDS);
List<WebElement> elements = wait.until(contextFunction.andThen(searchingFunction));
....
}
TouchAction
private final ActionSupplier<TouchAction> horizontalSwipe = () -> {
driver.findElementById("io.appium.android.apis:id/gallery");
AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery");
List<MobileElement> images = gallery
.findElementsByClassName("android.widget.ImageView");
Point location = gallery.getLocation();
Point center = gallery.getCenter();
return new TouchAction(driver).press(images.get(2), -10, center.y - location.y)
.waitAction(2000).moveTo(gallery, 10, center.y - location.y).release();
};
private final ActionSupplier<TouchAction> verticalSwiping = () ->
new TouchAction(driver).press(driver.findElementByAccessibilityId("Gallery"))
.waitAction(2000).moveTo(driver.findElementByAccessibilityId("Auto Complete")).release();
//水平与垂直的swipe
@Test public void tezt() {
...
horizontalSwipe.get().perform();
...
verticalSwiping.get().perform();
...
}
//普通的tap
import io.appium.java_client.TouchAction; ...
//tap
new TouchAction(driver)
.tap(driver
.findElementById("io.appium.android.apis:id/start")).perform();
...
//swipe
TouchAction swipe = new TouchAction(driver).press(images.get(2), -10, center.y - location.y)
.waitAction(2000).moveTo(gallery, 10, center.y - location.y).release();
swipe.perform();
...
//tap by few fingers
MultiTouchAction multiTouch = new MultiTouchAction(driver); for (int i = 0; i < fingers; i++) {
TouchAction tap = new TouchAction(driver);
multiTouch.add(tap.press(element).waitAction(duration).release());
} multiTouch.perform();
public class GestureUtils {
public static ActionSupplier<TouchAction> swipe(final AppiumDriver<?> driver, final params) {
return () -> {
new TouchAction(driver).press(params)
.waitAction(params).moveTo(params).release();
};
}
}
//可以直接使用如下方法进行swipe
public class SomeTest {
@Test public void tezt() {
...
GestureUtils.swipe(driver, params).get().perform();
...
}
}
Java-client 更新了The-event firing (新增了element/event的监听)
This feature allows end user to organize the event logging on the client side. Also this feature may be useful in a binding with standard or custom reporting frameworks.
import io.appium.java_client.events.api.general.AlertEventListener;
public class AlertListener implements AlertEventListener {
...
}
...
import io.appium.java_client.events.api.general.ElementEventListener;
public class ElementListener implements ElementEventListener {
...
}
//and so on
...
import io.appium.java_client.events.EventFiringWebDriverFactory;
import io.appium.java_client.events.api.Listener;
...
AndroidDriver driver = new AndroidDriver(parameters);
driver = EventFiringWebDriverFactory.getEventFiringWebDriver(driver, new AlertListener(),
new ElementListener());
//or
AndroidDriver driver2 = new AndroidDriver(parameters);
List<Listener> listeners = new ArrayList<>();
listeners.add(new AlertListener());
listeners.add(new ElementListener());
driver = EventFiringWebDriverFactory.getEventFiringWebDriver(driver2, listeners);
如何使用事件监听呢?
//and so on
...
import io.appium.java_client.events.EventFiringWebDriverFactory;
... AndroidDriver driver = new AndroidDriver(parameters);
driver = EventFiringWebDriverFactory.getEventFiringWebDriver(driver);
如果你自己想封装的话,可以如下操作:
import org.openqa.selenium.support.events.WebDriverEventListener;
import io.appium.java_client.events.api.general.AppiumWebDriverEventListener; public class UsersWebDriverEventListener implements WebDriverEventListener, AppiumWebDriverEventListener {
...
}
//或者如下操作 import io.appium.java_client.events.api.general.AppiumWebDriverEventListener; public class UsersWebDriverEventListener implements AppiumWebDriverEventListener {
...
}
appium 版本更新后的方法变化更新收集 ---持续更新的更多相关文章
- 关于苹果macOS更新到Catalina后出现的各种问题(持续更新)
一.Mac系统更新后 Git 不能用,提示 missing xcrun at:xxx xcrun: error: invalid active developer path (/Library/Dev ...
- iPadOS 更新日志 - 持续更新中
本文只是为了简单记录一下每个正式版本发布时间和更新内容,只有这个初衷,从2019年9月25日开始,将会持续更新. iPadOS 13.1 - 2019年9月25日 经全新命名的 iPadOS 是一款强 ...
- iOS 更新日志 - 持续更新中
本文只是为了简单记录一下每个正式版本发布时间和更新内容,只有这个初衷,从2019年9月25日开始,将会持续更新. iOS 13.1 - 2019年9月25日 iOS 13.1 iOS 13.1 包括错 ...
- appium 测试过程中遇到的几个问题 ---持续更新!
一. appium自带的Chromedriver版本和设备Android System Webview版本不一致的问题 报错信息: io.appium.java_client.NoSuchContex ...
- 程序员使用IDEA这些插件后,办公效率提升100%(持续更新中)
IDEA一些不错的插件分享 目录 IDEA一些不错的插件分享 插件集合 CamelCase Translation LiveEdit MarkDown Navigator Jrebel CheckSt ...
- IIS发布站点错误收集(持续更新)
本文主要收集IIS在发布站点过程中遇到的错误,并提供解决办法.并亲测可行.如果您也在使用IIS发布站点的过程中遇到了一些问题,欢迎留言提问. (1.) HTTP错误500.21-Internal Se ...
- 2017.3.27 集成modeler后的一些主要路径(持续更新)
1.设计器访问路径 项目名:wfs_web edtor-app和modeler.html的存放位置:webapp/designer/editor-app app-cfg.js中根路径设置:'conte ...
- Java中时间方法大全01(持续更新)
下面这些方法都可以封装到一个工具类中 /** * 获取当前时间的时间戳 */ public static int getCurrentTimeIntValue() { return (int) (Sy ...
- 【mysql】 操作 收集持续更新
一个字段可能对应多条数据,用mysql实现将多行数据合并成一行数据 GROUP_CONCAT(Name SEPARATOR ',') 需注意: 1.GROUP_CONCAT()中的值为你要合并的数据的 ...
随机推荐
- 窗口置顶 - 仿TopWind
前置学习:低级鼠标hook,获得鼠标状态. 这个在原来获得鼠标状态的基础上,加上一个事件处理即可. TopWind就是一个可以置顶窗口的文件,避免复制粘贴的时候的来回切换(大窗口与小窗口),算是一个实 ...
- 问题-python3.6找不到tkinter
问题:import tkinter失败 然后直接pip安装也不ok python3.6安装过程中会提示是否选择安装tkinter,如此只有打开原来的安装程序 勾选箭头所示
- 【BZOJ2054】疯狂的馒头(并查集)
/* 经典思路, 倒序并查集处理即可 */ #include<cstdio> #include<algorithm> #include<cstring> #incl ...
- 详解vuex
一.vuex的作用: vuex是一个专为Vue.js应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件状态,并以相应的规则保证状态以一种可预测的方式变化. 作用:组件之间的通信,大规模的逻 ...
- Linux基础(学习过程记录)
常用快捷键:Tab:使用Tab键来进行命令补全,补全目录.补全命令参数Ctrl+c键来强行终止当前程序Ctrl+d 键盘输入结束或退出终端Ctrl+s 暂停当前程序,暂停后按下任意键恢复运行Ctrl+ ...
- 使用Python+turtle绘制同心圆
问题描述:数学定义上是指:同一平面上同一圆心而半径不同的圆.简单来说就是:圆心相同半径不同的圆,如果几个圆的圆心是同一点,那么这几个圆就叫做同心圆. 本文使用turtle绘制一个类似“箭靶”的同心圆. ...
- Python第4天
主要内容: 数字(int) 字符串(replace/find/join/strip/startswith/split/upper/lower/format) 列表 append/extend/inse ...
- java面试题复习(八)
71.如何通过反射创建对象? 方法1:通过类对象调用newInstance()方法,例如:String.class.newInstance() 方法2:通过类对象的getConstructor()或 ...
- Python——Django运行问题
1.Python3.7+Django2.2操作Mysql数据库时出现如下错误:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3. ...
- Matplotlib-动画
Animation 动画 定义方程 参数设置 # Animation 动画 # 定义方程 # 使用matplotlib做动画也是可以的,我们使用其中一种方式,function animation来说说 ...