標籤:而在 點擊 bsp add line str base plain 功能
在用Appium做UI自動化過程中,大家會發現測試報告很重要,而在測試報告中很重要。
因為很多公司都是用Jenkins作為持續整合工具,所以要讓執行自動化測試的人看明白自動化在跑什麼,哪裡失敗了,關鍵節點都需要。
怎麼做呢,目前項目中是這麼實現的:
1.實現功能類:
12345678910111213141516171819 |
public static String screenShot(ShipperAndroidEmulator ae) { String dir = "screenshot" ; // TODO String time = new SimpleDateFormat( "yyyyMMdd-HHmmss" ).format( new Date()); String screenShotPath = dir + File.separator + time + ".png" ; AndroidDriver augmentedDriver = null ; augmentedDriver = ae.getAndroid(); try { File sourceFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(sourceFile, new File(screenShotPath)); } catch (Exception e) { e.printStackTrace(); return "Failed to screenshot" ; } return screenShotPath.replace( "\\" , "/" ); } |
2.用screenShot實現錯誤處理類:
12345678910 |
private void handleFailure(String notice) { String png = LogTools.screenShot( this ); String log = notice + " >> capture screenshot at " + png; logger.error(log); if (GlobalSettings.baseStorageUrl.lastIndexOf( "/" ) == GlobalSettings.baseStorageUrl.length()) { GlobalSettings.baseStorageUrl = GlobalSettings.baseStorageUrl.substring( 0 , GlobalSettings.baseStorageUrl.length() - 1 ); } Reporter.log(log + "<br/><img src=\"" + GlobalSettings.baseStorageUrl + "/" + png + "\" />" ); Assert.fail(log); } |
3.對所有appium介面操作類進行處理:
123456789101112 |
public void click(By by) { expectElementExistOrNot( true , by, timeout); try { clickTheClickable(by,System.currentTimeMillis(), 2500 ); handleSuccess( "Succeed to click " + by); } catch (Exception e){ e.printStackTrace(); handleFailure( "Failed to click " + by); } logger.info( "Clicked " + by); } |
4. 不能點擊時候重試驗擊操作
private void clickTheClickable(By byElement, long startTime, int timeOut) throws Exception {
try {
findElementBy(byElement).click();
} catch (Exception e) {
if (System.currentTimeMillis() - startTime > timeOut) {
logger.warn(byElement+ " is unclickable");
throw new Exception(e);
} else {
Thread.sleep(500);
logger.warn(byElement + " is unclickable, try again");
clickTheClickable(byElement, startTime, timeOut);
}
}
Appium自動化中的問題