appium 5-27屏幕旋转、
生活随笔
收集整理的這篇文章主要介紹了
appium 5-27屏幕旋转、
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.屏幕切換
注意:應(yīng)用一定要支持橫豎屏切換,否則無效果,
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.應(yīng)用切換到后臺(tái)
public void testHoutai(){System.out.println("切換后臺(tái)");driver.runAppInBackground(Duration.ofSeconds(3));System.out.println("返回前臺(tái)");driver.launchApp();}3.手機(jī)解鎖
注意:手機(jī)存在解鎖密碼,會(huì)解鎖失敗。如果存在密碼,可以點(diǎn)擊電源鍵,點(diǎn)亮屏幕后再解鎖
public void testLock(){driver.lockDevice();driver.unlockDevice();}4.來電和短信,僅限模擬器
public void SMS(){//接收短信driver.sendSMS("13854748784","hello world");//來電driver.makeGsmCall("13311112222",GsmCallActions.CALL);}5.關(guān)閉應(yīng)用,啟動(dòng)應(yīng)用
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.開啟\關(guān)閉飛行模式
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.執(zhí)行腳本
查看示例
更多
還是不會(huì)用,提示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.滑動(dòng)
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封裝滑動(dòng)方法
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();} }測(cè)試代碼繼承滑動(dòng)類,使用方法
public class TestBrowser extends SwipeClass{public void testSwipe() throws InterruptedException{Thread.sleep(6000);swipeToUp(driver);} }10.頁面加載中,控件的位置會(huì)發(fā)生變化
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());}}轉(zhuǎn)載于:https://www.cnblogs.com/csj2018/p/9829846.html
總結(jié)
以上是生活随笔為你收集整理的appium 5-27屏幕旋转、的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转录组分析综述A survey of b
- 下一篇: 树形列(无限级联下拉列的曲线版本)