appium 5-27屏幕旋转、
1.屏幕切换
注意:应用一定要支持横竖屏切换,否则无效果,
public void testBrowser() throws InterruptedException {
Thread.sleep(10000);
System.out.println("竖屏");
driver.rotate(ScreenOrientation.PORTRAIT);
Thread.sleep(3000);
System.out.println("横屏");
driver.rotate(ScreenOrientation.LANDSCAPE);
}
2.应用切换到后台
public void testHoutai(){
System.out.println("切换后台");
driver.runAppInBackground(Duration.ofSeconds(3));
System.out.println("返回前台");
driver.launchApp();
}
3.手机解锁
注意:手机存在解锁密码,会解锁失败。如果存在密码,可以点击电源键,点亮屏幕后再解锁
public void testLock(){
driver.lockDevice();
driver.unlockDevice();
}
4.来电和短信,仅限模拟器
public void SMS(){
//接收短信
driver.sendSMS("13854748784","hello world");
//来电
driver.makeGsmCall("13311112222",GsmCallActions.CALL);
}
5.关闭应用,启动应用
public void testStop() throws InterruptedException{
Thread.sleep(5000);
driver.closeApp();
System.out.println("closeapp");
Thread.sleep(5000);
driver.launchApp();
System.out.println("launchapp");
Thread.sleep(6000);
}
6.开启\关闭飞行模式
public void testFlyMode() throws InterruptedException {
driver.toggleAirplaneMode();
Thread.sleep(6000);
}
7.截屏
public void screenshot() throws IOException {
FileUtils.copyFile(driver.getScreenshotAs(OutputType.FILE),(new File("1.png")));
}
8.执行脚本
查看示例
更多
还是不会用,提示org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Appium server must have relaxed security flag set in order to run any shell commands
9.滑动
public void testAction() throws InterruptedException{
Thread.sleep(6000);
TouchAction action = new TouchAction(driver);
action.press(PointOption.point(500,1500)).
waitAction(WaitOptions.waitOptions(Duration.ofSeconds(3))).
moveTo(PointOption.point(500,500)).release().perform();
}
SwipeClass.java封装滑动方法
public class SwipeClass {
static Duration duration=Duration.ofSeconds(1);
public void swipeToUp(AndroidDriver driver){
int width = driver.manage().window().getSize().width;
int height = driver.manage().window().getSize().height;
TouchAction act = new TouchAction(driver).press(PointOption.point(width/2,height*3/4)).waitAction(WaitOptions.waitOptions(duration)).moveTo(PointOption.point(width/2,height/4)).release();
act.perform();
}
public void swipeToDown(AndroidDriver driver){
int width = driver.manage().window().getSize().width;
int height = driver.manage().window().getSize().height;
TouchAction act = new TouchAction(driver).press(PointOption.point(width/2,height*1/4)).waitAction(WaitOptions.waitOptions(duration)).moveTo(PointOption.point(width/2,height*3/4)).release();
act.perform();
}
public void swipeToLeft(AndroidDriver driver){
int width = driver.manage().window().getSize().width;
int height = driver.manage().window().getSize().height;
TouchAction act = new TouchAction(driver).press(PointOption.point(width*4/5,height/2)).waitAction(WaitOptions.waitOptions(duration)).moveTo(PointOption.point(width/5,height/2)).release();
act.perform();
}
public void swipeToRight(AndroidDriver driver){
int width = driver.manage().window().getSize().width;
int height = driver.manage().window().getSize().height;
TouchAction act = new TouchAction(driver).press(PointOption.point((int)width/5,(int)height/2)).waitAction(WaitOptions.waitOptions(duration)).moveTo(PointOption.point(width*4/5,height/2)).release();
act.perform();
}
}
测试代码继承滑动类,使用方法
public class TestBrowser extends SwipeClass{
public void testSwipe() throws InterruptedException{
Thread.sleep(6000);
swipeToUp(driver);
}
}
10.页面加载中,控件的位置会发生变化
public void testPositon() {
driver.findElementByXPath("//*[@text='跳过']").click();
for(int i=0;i<3;i++) {
MobileElement zixuan = (MobileElement) driver.findElementByXPath("//*[@text=\"自选\"]");
System.out.println(zixuan.getCenter());
}
}

appium 5-27屏幕旋转、的更多相关文章
- Runtime解决屏幕旋转问题
前言 大家或许在iOS程序开发中经常遇到屏幕旋转问题,比如说希望指定的页面进行不同的屏幕旋转,但由于系统提供的方法是导航控制器的全局方法,无法随意的达到这种需求.一般的解决方案是继承UINavrgat ...
- 【Android】[转] Android屏幕旋转使用OrientationEventListener的监听
说明 遇到一个奇葩的问题,我在使用onConfigChanged拦截屏幕的横竖屏旋转时,发现直接进行180度的横屏/竖屏转换居然没有反应!查找原因发现仅对landscape或者portrait状态有用 ...
- Android 屏幕旋转 处理 AsyncTask 和 ProgressDialog 的最佳方案
的最佳方案 标签: Android屏幕旋转AsyncTaskProgressDialog 2014-07-19 09:25 39227人阅读 评论(46) 收藏 举报 分类: [android 进阶之 ...
- iOS实现屏幕旋转
iOS实现屏幕旋转有两种方式 1. 应用本身支持 2. 手动旋转UIView (这种方式我没找到旋转 系统控件的方法 如:键盘.导航.UIAlertView) 如果你只是要把竖屏的播放器,做成支持横屏 ...
- Recovery和Charger模式下屏幕旋转180度
转自:http://www.etwiki.cn/android/1267.html 如何让Recovery (系统固件升级),charger(关机充电动画)时屏幕旋转180度 解决方法: 1.在boo ...
- ios实现屏幕旋转的方法
1.屏蔽AppDelegate下面的屏幕旋转方法 #pragma mark - 屏幕旋转的 //- (UIInterfaceOrientationMask)application:(UIApplica ...
- View页面内容的旋转,在某些情况下可替代屏幕旋转使用
这个是在做小秘书的体重曲线图的时候用到的,横排的时候可以多显示些内容,可是由于很多未知的冲突导至屏幕旋转起来非常麻烦,可用用旋转页面的内容来达到旋转屏幕的效果. 代码如下: //旋转90度 CGAff ...
- IOS6屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统)
转自 http://blog.csdn.net/zzfsuiye/article/details/8251060 概述: 在iOS6之前的版本中,通常使用 shouldAutorotateToInte ...
- 【转】IOS屏幕旋转与View的transform属性之间的关系,比较底层
iTouch,iPhone,iPad设置都是支持旋转的,如果我们的程序能够根据不同的方向做出不同的布局,体验会更好. 如何设置程序支持旋转呢,通常我们会在程序的info.plist中进行设置Suppo ...
- qt 屏幕旋转
qt屏幕旋转的方法 参考链接 http://mikenoodle.blog.163.com/blog/static/11333522010102754154616/ http://blog.csdn. ...
随机推荐
- 莪的拽、像省田各号①样没尽頭队——需求改进&原型设计
需求改进&原型设计 1. 需求&原型改进 经过老师的指导以及组内成员的讨论后,我们认为之前的需求分析已经比较准确完备. 根据电子宠物的形象结构特点,以及模拟屏幕的空间限制,我们设计出了 ...
- Maven中使用Jetty容器
1.在pom.xml中添加Jetty的插件 <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId ...
- hibernate中3个重要的类 Configuration SessionFactory Session
配置类Configuration 主要负责管理hibernate的配置信息以及启动hibernate,在hibernate运行时,配置文件取读底层的配置信息,基本包括数据库驱动,url.usernam ...
- PostgreSQL11.2 configure卡住 checking for DocBook XML V4.2
在PG11.2的数据库编译过程中,卡在了“checking for DocBook XML V4.2”,不动,需要安装docbook才可以. 需要安装: yum install docbook-dtd ...
- Alpha阶段敏捷冲刺---Day4
一.Daily Scrum Meeting照片 二.今天冲刺情况反馈 今天我们上完课后在禹洲楼教室外进行我们的每日立会.开会的内容主要是对昨天遇到的困难做了一些交流,并且定下今天的任务是完成排行榜界面 ...
- caffe安装编译问题-ImportError: No module named skimage.io
问题描述 >>> import caffe Traceback (most recent call last): File , in <module> File , in ...
- 【HDU5421】Victor and String(回文树)
[HDU5421]Victor and String(回文树) 题面 Vjudge 大意: 你需要支持以下操作: 动态在前端插入一个字符 动态在后端插入一个字符 回答当前本质不同的回文串个数 回答当前 ...
- sublime text 3 实用的快捷键
Ctrl+Shift+P:打开命令面板Ctrl+P:搜索项目中的文件Ctrl+G:跳转到第几行Ctrl+W:关闭当前打开文件Ctrl+Shift+W:关闭所有打开文件Ctrl+Shift+V:粘贴并格 ...
- hdu 5184 类卡特兰数+逆元
BC # 32 1003 题意:定义了括号的合法排列方式,给出一个排列的前一段,问能组成多少种合法的排列. 这道题和鹏神研究卡特兰数的推导和在这题中的结论式的推导: 首先就是如何理解从题意演变到卡特兰 ...
- 给div加滚动条
<div style="width:175px;height:100px;background:white;overflow:scroll;"> <span> ...