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屏幕旋转、的更多相关文章

  1. Runtime解决屏幕旋转问题

    前言 大家或许在iOS程序开发中经常遇到屏幕旋转问题,比如说希望指定的页面进行不同的屏幕旋转,但由于系统提供的方法是导航控制器的全局方法,无法随意的达到这种需求.一般的解决方案是继承UINavrgat ...

  2. 【Android】[转] Android屏幕旋转使用OrientationEventListener的监听

    说明 遇到一个奇葩的问题,我在使用onConfigChanged拦截屏幕的横竖屏旋转时,发现直接进行180度的横屏/竖屏转换居然没有反应!查找原因发现仅对landscape或者portrait状态有用 ...

  3. Android 屏幕旋转 处理 AsyncTask 和 ProgressDialog 的最佳方案

    的最佳方案 标签: Android屏幕旋转AsyncTaskProgressDialog 2014-07-19 09:25 39227人阅读 评论(46) 收藏 举报 分类: [android 进阶之 ...

  4. iOS实现屏幕旋转

    iOS实现屏幕旋转有两种方式 1. 应用本身支持 2. 手动旋转UIView (这种方式我没找到旋转 系统控件的方法 如:键盘.导航.UIAlertView) 如果你只是要把竖屏的播放器,做成支持横屏 ...

  5. Recovery和Charger模式下屏幕旋转180度

    转自:http://www.etwiki.cn/android/1267.html 如何让Recovery (系统固件升级),charger(关机充电动画)时屏幕旋转180度 解决方法: 1.在boo ...

  6. ios实现屏幕旋转的方法

    1.屏蔽AppDelegate下面的屏幕旋转方法 #pragma mark - 屏幕旋转的 //- (UIInterfaceOrientationMask)application:(UIApplica ...

  7. View页面内容的旋转,在某些情况下可替代屏幕旋转使用

    这个是在做小秘书的体重曲线图的时候用到的,横排的时候可以多显示些内容,可是由于很多未知的冲突导至屏幕旋转起来非常麻烦,可用用旋转页面的内容来达到旋转屏幕的效果. 代码如下: //旋转90度 CGAff ...

  8. IOS6屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统)

    转自 http://blog.csdn.net/zzfsuiye/article/details/8251060 概述: 在iOS6之前的版本中,通常使用 shouldAutorotateToInte ...

  9. 【转】IOS屏幕旋转与View的transform属性之间的关系,比较底层

    iTouch,iPhone,iPad设置都是支持旋转的,如果我们的程序能够根据不同的方向做出不同的布局,体验会更好. 如何设置程序支持旋转呢,通常我们会在程序的info.plist中进行设置Suppo ...

  10. qt 屏幕旋转

    qt屏幕旋转的方法 参考链接 http://mikenoodle.blog.163.com/blog/static/11333522010102754154616/ http://blog.csdn. ...

随机推荐

  1. 1.5 C++ new和delete操作符

    参考:http://www.weixueyuan.net/view/6331.html 在C语言中,动态分配和释放内存的函数是malloc.calloc和free,而在C++语言中,new.new[] ...

  2. [转]TFS.VisualStudio.com TF30063: You are not authorized to access Collection

    If you are trying to connect to team foundation server online through visual studio and you get unau ...

  3. jeecms系统使用介绍——通过二次开发实现对word、pdf、txt等上传附件的全文检索

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/76912307 本文出自[我是干勾鱼的博客] 之前在文章<基于Java的门户 ...

  4. 1.1.2A+B for Input-Output Practice (II)

    A+B for Input-Output Practice (II) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768  ...

  5. [LeetCode&Python] Problem 557. Reverse Words in a String III

    Given a string, you need to reverse the order of characters in each word within a sentence while sti ...

  6. 各种CTF的WP

    http://l-team.org/archives/43.html PlaidCTF-2014-twenty/mtpox/doge_stege-Writeup http://l-team.org/a ...

  7. 《DSP using MATLAB》Problem 4.24

    Y(z)部分分式展开, 零状态响应部分分式展开, 零输入状态部分分式展开,

  8. 【vue】创建一个vue前端项目,编译,发布

    npm: Nodejs下的包管理器. webpack: 它主要的用途是通过CommonJS的语法把所有浏览器端需要发布的静态资源做相应的准备,比如资源的合并和打包. vue-cli: 用户生成Vue工 ...

  9. LG3812 【模板】线性基

    题意 给定n个整数(数字可能重复),求在这些数中选取任意个,使得他们的异或和最大. \(1≤n≤50,0≤S_i≤2^{50}\) 分析 模板题. 推荐一篇好博客 现在我来证明一下线性基的性质. 性质 ...

  10. Tomcat:Several ports are already in use问题

    Several ports (8005, 8080, 8009) required by Tomcat v6.0 Server at localhost are already in use. The ...