AndroidDragAndDrop.java
以下代码使用ApiDemos-debug.apk进行测试
package com.saucelabs.appium; import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File;
import java.net.URL; /**
* Created by saikrisv on 26/04/16.
*/
public class AndroidDragAndDrop {
private AppiumDriver<WebElement> driver; @Before
public void setUp() throws Exception {
//File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File("E:/package");
File app = new File(appDir, "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","XiaoMiShouJi");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity", ".ApiDemos");
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} @After
public void tearDown() throws Exception {
driver.quit();
} @Test
public void testDragAndDrop() throws InterruptedException {
driver.findElementByXPath(".//*[@text='Views']").click();
driver.findElementByXPath(".//*[@text='Drag and Drop']").click();
MobileElement calc = (MobileElement) driver.findElementById("io.appium.android.apis:id/drag_dot_1");
TouchAction touchAction = new TouchAction(driver);
touchAction.press(calc).perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
touchAction.moveTo(driver.findElementById("io.appium.android.apis:id/drag_dot_2")).release().perform();
Thread.sleep(5000);
Assert.assertEquals(driver.findElementById("io.appium.android.apis:id/drag_result_text").getText(),"Dropped!");
}
}
上面的代码运行报错,根据appium的问题单Cant perform drag'n'drop using appium#3104得知:drag-and-drop过程中,不能有wait操作,所以去掉这里的sleep。更改后代码如下:可以正常运行。
package com.saucelabs.appium; import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File;
import java.net.URL; /**
* Created by saikrisv on 26/04/16.
*/
public class AndroidDragAndDrop {
private AppiumDriver<WebElement> driver; @Before
public void setUp() throws Exception {
//File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File("E:/package");
File app = new File(appDir, "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","XiaoMiShouJi");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity", ".ApiDemos");
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} @After
public void tearDown() throws Exception {
driver.quit();
} @Test
public void testDragAndDrop() throws InterruptedException {
driver.findElementByXPath(".//*[@text='Views']").click();
driver.findElementByXPath(".//*[@text='Drag and Drop']").click();
MobileElement calc = (MobileElement) driver.findElementById("io.appium.android.apis:id/drag_dot_1");
MobileElement target = (MobileElement) driver.findElementById("io.appium.android.apis:id/drag_dot_2");
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(calc,5000).moveTo(target).release().perform();
Thread.sleep(5000);
Assert.assertEquals(driver.findElementById("io.appium.android.apis:id/drag_result_text").getText(),"Dropped!");
}
}
用到的定位方式:
Xpath: driver.findElementByXPath(".//*[@text='Views']").click();
ID: MobileElement calc = (MobileElement) driver.findElementById("io.appium.android.apis:id/drag_dot_1");
用到的操作:
click: driver.findElementByXPath(".//*[@text='Drag and Drop']").click();
drag-and-drop: touchAction.longPress(calc,5000).moveTo(target).release().perform();
AndroidDragAndDrop.java的更多相关文章
- Spark案例分析
一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...
- 故障重现(内存篇2),JAVA内存不足导致频繁回收和swap引起的性能问题
背景起因: 记起以前的另一次也是关于内存的调优分享下 有个系统平时运行非常稳定运行(没经历过大并发考验),然而在一次活动后,人数并发一上来后,系统开始卡. 我按经验开始调优,在每个关键步骤的加入如 ...
- Elasticsearch之java的基本操作一
摘要 接触ElasticSearch已经有一段了.在这期间,遇到很多问题,但在最后自己的不断探索下解决了这些问题.看到网上或多或少的都有一些介绍ElasticSearch相关知识的文档,但个人觉得 ...
- 论:开发者信仰之“天下IT是一家“(Java .NET篇)
比尔盖茨公认的IT界领军人物,打造了辉煌一时的PC时代. 2008年,史蒂夫鲍尔默接替了盖茨的工作,成为微软公司的总裁. 2013年他与微软做了最后的道别. 2013年以后,我才真正看到了微软的变化. ...
- 故障重现, JAVA进程内存不够时突然挂掉模拟
背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...
- 死磕内存篇 --- JAVA进程和linux内存间的大小关系
运行个JAVA 用sleep去hold住 package org.hjb.test; public class TestOnly { public static void main(String[] ...
- 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用
有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...
- Java多线程基础学习(二)
9. 线程安全/共享变量——同步 当多个线程用到同一个变量时,在修改值时存在同时修改的可能性,而此时该变量只能被赋值一次.这就会导致出现“线程安全”问题,这个被多个线程共用的变量称之为“共享变量”. ...
- Java多线程基础学习(一)
1. 创建线程 1.1 通过构造函数:public Thread(Runnable target, String name){} 或:public Thread(Runnable target ...
随机推荐
- LibieOJ 6170 字母树 (Trie)
题目链接 字母树 (以每个点为根遍历,插入到trie中,统计答案即可)——SamZhang #include <bits/stdc++.h> using namespace std; #d ...
- GPP加密破解工具gpp-decrypt
GPP加密破解工具gpp-decrypt GPP是Group Policy Preferences(组策略首选项)的缩写,这是一个组策略实施工具.通过该工具,网络管理员可以实现更多的网络管理,如驱 ...
- 浅析PropertySource 基本使用
目录 一.PropertySource 简介 二.@PropertySource与Environment读取配置文件 三.@PropertySource与@Value读取配置文件 四.@Propert ...
- Ubuntu 16.04下安装WineHQ
说明: 1.Wine和WIneHQ没什么区别,新版和旧版的问题. 2.安装了深度的Wine包也可以和WineHQ一起兼容,因为深度的应用名已经加了deepin前缀,所以不冲突. 3.安装了Wine之后 ...
- XmlNode与XmlElement的区别总结
原文链接:http://www.cnblogs.com/oilsun/archive/2012/07/07/2580427.html 今 天在做ASP.NET操作XML文档的过程中,发现了两个类:Xm ...
- iterm2 配色
http://blog.csdn.net/sanwuhai/article/details/48729561
- 数据库历险记(三) | 缓存框架的连环炮 数据库历险记(二) | Redis 和 Mecached 到底哪个好? 数据库历险记(一) | MySQL这么好,为什么还有人用Oracle? 面对海量请求,缓存设计还应该考虑哪些问题?
数据库历险记(三) | 缓存框架的连环炮 文章首发于微信公众号「陈树义」,专注于 Java 技术分享的社区.点击链接扫描二维码,与500位小伙伴一起共同进步.微信公众号二维码 http://p3n ...
- 内核顶层Makefile相关1
http://www.groad.net/bbs/simple/?f104.htm $(Q) 变量 内核 Makefile 文件 238 行到 259 行的注释中知道,$(Q) 变量的作用是决定是否在 ...
- 实习日记)select option 选择不同的option时, 页面发生不同的变化
怎么在下拉框的选择不同的option时, 页面发生响应的变化 因为option是没有点击事件什么的, 只有select才有, 所以不能通过option的点击事件来完成, 所以开始的尝试都失败了(之前 ...
- open-source Julius speech-recognition engine
http://julius.osdn.jp/en_index.php?q=index-en.html Open-Source Large Vocabulary CSR Engine Julius ht ...