在高版本的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 版本更新后的方法变化更新收集 ---持续更新的更多相关文章

  1. 关于苹果macOS更新到Catalina后出现的各种问题(持续更新)

    一.Mac系统更新后 Git 不能用,提示 missing xcrun at:xxx xcrun: error: invalid active developer path (/Library/Dev ...

  2. iPadOS 更新日志 - 持续更新中

    本文只是为了简单记录一下每个正式版本发布时间和更新内容,只有这个初衷,从2019年9月25日开始,将会持续更新. iPadOS 13.1 - 2019年9月25日 经全新命名的 iPadOS 是一款强 ...

  3. iOS 更新日志 - 持续更新中

    本文只是为了简单记录一下每个正式版本发布时间和更新内容,只有这个初衷,从2019年9月25日开始,将会持续更新. iOS 13.1 - 2019年9月25日 iOS 13.1 iOS 13.1 包括错 ...

  4. appium 测试过程中遇到的几个问题 ---持续更新!

    一. appium自带的Chromedriver版本和设备Android System Webview版本不一致的问题 报错信息: io.appium.java_client.NoSuchContex ...

  5. 程序员使用IDEA这些插件后,办公效率提升100%(持续更新中)

    IDEA一些不错的插件分享 目录 IDEA一些不错的插件分享 插件集合 CamelCase Translation LiveEdit MarkDown Navigator Jrebel CheckSt ...

  6. IIS发布站点错误收集(持续更新)

    本文主要收集IIS在发布站点过程中遇到的错误,并提供解决办法.并亲测可行.如果您也在使用IIS发布站点的过程中遇到了一些问题,欢迎留言提问. (1.) HTTP错误500.21-Internal Se ...

  7. 2017.3.27 集成modeler后的一些主要路径(持续更新)

    1.设计器访问路径 项目名:wfs_web edtor-app和modeler.html的存放位置:webapp/designer/editor-app app-cfg.js中根路径设置:'conte ...

  8. Java中时间方法大全01(持续更新)

    下面这些方法都可以封装到一个工具类中 /** * 获取当前时间的时间戳 */ public static int getCurrentTimeIntValue() { return (int) (Sy ...

  9. 【mysql】 操作 收集持续更新

    一个字段可能对应多条数据,用mysql实现将多行数据合并成一行数据 GROUP_CONCAT(Name SEPARATOR ',') 需注意: 1.GROUP_CONCAT()中的值为你要合并的数据的 ...

随机推荐

  1. 1、redis 基础

    1.1 导言 如果你从来没使用过 Redis 数据库,那你肯定会问,为什么我们要学 Redis数据库,我只使用 MySQL 或 Oracle 就够了.其实 Redis 虽叫数据库,可又不是传统意义上的 ...

  2. windows2012 IIS部署GeoTrust证书踩过的坑。 视频测试可用 IIS 证书导入

    证书导入方式 https://wenku.baidu.com/view/3504f29a55270722192ef78a.html https://www.cnblogs.com/jackrebel/ ...

  3. golang 结构体中的匿名接口

    golang 结构体中的匿名接口 代码示例 golang 中,可以给结构体增加匿名field,可参考 unknwon 大神的书. 匿名字段和内嵌结构体 但,golang同时也可以给结构体定义一个匿名i ...

  4. RIDE创建工程和测试套件和用例--书本介绍的入门方法,自己整理实践下

    1.选择File->New Project 2.弹出的New Project对话框,在Name文本框输入一个名词,如“TestProject-0805”,右侧选中“Directory”,选中建立 ...

  5. vb程序安装时需要在客户端安装MSSOAP30.dll,但注册不上,请问怎么处理

    現在想打包发布,在客戶沒有這個控件時,注冊一下,主要是不想在客户机器上安装SoapToolkit30.EXE文件 ?? 推荐解决方案 如果使用 InstallShield 工具来打包,安装完MSSOA ...

  6. 起源-C的故事

    ———C语言的起源故事(简史)——— C语言在70年代问世的,1978年由美国电话公司(AT&T)贝尔实验室正式发表.B.W.Kernighan和D.M.Ritchit合著了著名的" ...

  7. Angular CLI: 全局脚本

    全局脚本 有的时候,我们需要加载全局脚本,例如 jQuery 脚本库,第三方的控件库等等.比如 jQuery 可以直接加载到 window 对象上,这就需要我们使用 Angular 中的全局脚本来处理 ...

  8. php的运行流程

    1.Zend引擎:Zend整体用纯C实现,是PHP的内核部分,他将PHP代码翻译(词法.语法解析等一系列编译过程)为可执行opcode的处理并实现相应的处理方法.实现了基本的数据结构(如:hashta ...

  9. Spring NoSuchBeanDefinitionException原因分析

    摘要:摘要:本文译自EugenParaschiv文章SpringNoSuchBeanDefinitionException原文链接:/2014th7cj/d/file/p/20161012/dv5o0 ...

  10. LeetCode 144. Binary Tree Preorder Traversal 二叉树的前序遍历 C++

    Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [,,] \ / Ou ...