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());
        }
    }

1418970-20181023200945942-254992672.png

转载于:https://www.cnblogs.com/csj2018/p/9829846.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值