軟件測試學習筆記丨常用的設備交互命令

2024年2月6日 19点热度 0人点赞

模擬器創建

  • 查看模擬器列表: emulator -list-avds
  • 在命令行啟動模擬器: emulator @foo or emulator -avd foo

desirecapbility配置

  • caps.setCapability(AVD,“Pixel_Android6.0”);
  • 註意自動啟動模擬器,隻能是sdk的模擬器,第三方模擬器不支持,7.0不支持

模擬電話、短信

//撥打電話(模擬器)
driver.makeGsmCall(“18390522307”, GsmCallActions.CALL);
//接聽電話(模擬器)
driver.makeGsmCall(“18390522307”, GsmCallActions.ACCEPT);
// 拒接電話/掛斷電話()
driver.makeGsmCall(“18390522307”, GsmCallActions.CANCEL);
//發送短信(模擬器)
driver.sendSMS(“18390522307”,“hello appium message”);

網絡模式

driver.toggleAirplaneMode();//飛行模式
driver.toggleWifi();//wifi模式
driver.toggleData();//數據流量模式

橫豎屏切換

//橫屏切換
driver.rotate(
ScreenOrientation.LANDSCAPE);

//切換成豎屏
driver.rotate(
ScreenOrientation.PORTRAIT);

App處理

//鎖屏
driver.lockDevice();
//截圖
File screenshotAs = driver.getScreenshotAs(OutputType.FILE);
File file = new File(System.getProperty(“user.dir”) “
/src/main/resources/demo.png”);

FileUtils.copyFile(screenshotAs,file);

//設置地理位置(僅限於模擬器)
Location location = new Location(1,2,3);
driver.setLocation(location);

錄屏

//錄屏

driver.startRecordingScreen();


driver.stopRecordingScreen();

硬件操作

-//硬件操作
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));

  • 比如 back,home,menu,power,voice up,voice down,

官網地址

qemu-system

@Test
    public void deviceTest() throws IOException {
        //撥打電話(模擬器)
        driver.makeGsmCall("18390522307", GsmCallActions.CALL);
        //接聽電話(模擬器)
        driver.makeGsmCall("18390522307", GsmCallActions.ACCEPT);
        // 拒接電話/掛斷電話()
        driver.makeGsmCall("18390522307", GsmCallActions.CANCEL);
        //發送短信(模擬器)
        driver.sendSMS("18390522307","hello appium message");
        //網絡設置
        driver.toggleAirplaneMode();//飛行模式
        driver.toggleWifi();//wifi模式
        driver.toggleData();//數據流量模式
        //橫屏切換
        driver.rotate(ScreenOrientation.LANDSCAPE);
        //切換成豎屏
        driver.rotate(ScreenOrientation.PORTRAIT);
        //鎖屏
        driver.lockDevice();
        //截圖
        File screenshotAs = driver.getScreenshotAs(OutputType.FILE);
        File file = new File(System.getProperty("user.dir")   "/src/main/resources/demo.png");
        FileUtils.copyFile(screenshotAs,file);
        //錄屏
        driver.startRecordingScreen();
        driver.stopRecordingScreen();
        //設置地理位置(僅限於模擬器)
        Location location = new Location(1,2,3);
        driver.setLocation(location);
        //硬件操作
        driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
    }

霍格沃茲的測試管理班是專門面向測試與質量管理人員的一門課程,通過提升從業人員的團隊管理、項目管理、績效管理、溝通管理等方面的能力,使測試管理人員可以更好的帶領團隊、項目以及公司獲得更快的成長。提供 1v1 私教指導,BAT 級別的測試管理大咖量身打造職業規劃。