亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 >
WebDriver之測試失敗自動截圖
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2013/4/9 17:09:56 ] 推薦標(biāo)簽:

  webDriver 測試的時候頭疼的是調(diào)試。但也遠(yuǎn)不及運行的時候出錯,再回頭調(diào)試來的痛苦。總所周知, web 自動化的代碼都非常脆弱,一份代碼一會運行失敗,一會運行成功也是很正常的事情。總的來說造成案例運行失敗的原因大抵有兩點:

  環(huán)境問題: 比如網(wǎng)絡(luò)不穩(wěn)定啊

  代碼變動: 比如某個元素不在

  遇到 bug :這是真的發(fā)現(xiàn) bug 了

  無論哪一種,遇到了都需要花一番時間去 debug。那如果這個時候有一張運行時候出錯的截圖,那一目了然了。(即便不一目了然,也有很多幫助)

  在運行出錯的時候,捕獲錯誤并截圖有兩種思路:

  自定義一個 WeDdriver 的監(jiān)聽器,在出異常的時候截圖。

  利用 Juint 的 TestRule, 自定義一個 Rule 在運行失敗的時候截圖。

  自定義監(jiān)聽器

  截圖的原理

  截圖需要用到 RemoteWebDriver。在 Selenium 官方我們可以找到:

  One nice feature of the remote

  webdriver is that exceptions often

  have an attached screen shot, encoded

  as a Base64 PNG. In order to get this

  screenshot, you need to write code

  similar to:

  public String extractScreenShot(WebDriverException e) {

  Throwable cause = e.getCause();

  if (cause instanceof ScreenshotException) {

  return ((ScreenshotException) cause).getBase64EncodedScreenshot();

  }

  return null;

  }

  意思是說,每個異常都是 ScreenshotException 的對象,轉(zhuǎn)碼一下可以用了。這是截圖的本質(zhì)。

  import java.io.File;

  import java.io.FileOutputStream;

  import java.io.IOException;

  import java.text.SimpleDateFormat;

  import java.util.Date;

  import org.openqa.selenium.WebDriver;

  import org.openqa.selenium.internal.Base64Encoder;

  import org.openqa.selenium.remote.ScreenshotException;

  import org.openqa.selenium.support.events.AbstractWebDriverEventListener;

  /**

  * This is an customized webdriver event listener.

  * Now it implements onException method: webdriver will take a screenshot

  * when it meets an exception. It's good but not so usable. And when we use

  * WebDriverWait to wait for an element appearing, the webdriver will throw

  * exception always and the onException will be excuted again and again, which

  * generates a lot of screenshots.

  * Put here for study

  * Usage:

  * WebDriver driver = new FirefoxDriver();

  * WebDriverEventListener listener = new CustomWebDriverEventListener();

  * return new EventFiringWebDriver(driver).register(listener);

  *

  * @author qa

  *

  */

  public class CustomWebDriverEventListener extends

  AbstractWebDriverEventListener {

  @Override

  public void onException(Throwable throwable, WebDriver driver) {

  Throwable cause = throwable.getCause();

  if (cause instanceof ScreenshotException) {

  SimpleDateFormat formatter = new SimpleDateFormat(

  "yyyy-MM-dd-hh-mm-ss");

  String dateString = formatter.format(new Date());

  File of = new File(dateString + "-exception.png");

  FileOutputStream out = null;

上一頁123下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 欧美18videosex性极品 | 毛茸茸free牲交 | 成人国产三级在线播放 | 成人18网站 | 久久综合久久精品 | 另类黄色| 精品久久久久免费极品大片 | 久久精品一区 | 在线观看国产一区亚洲bd | 欧美性猛交xxxxx按摩国内 | 夜色资源站www国产在线资源 | 曰批视频免费 | 国产特黄特色a级在线视频 国产特黄特色a级在线视 | 手机在线免费观看毛片 | 免费人成网站永久 | 伊人久久国产免费观看视频 | 成人区精品一区二区不卡亚洲 | 亚洲 欧美 日韩 另类 | 国产成人久久精品麻豆二区 | 一级aaaaaa片毛片在线播放 | h 在线播放 | 8x成人永久在线观看视频 | 伊人天堂网 | 日日做日日摸夜夜爽 | 最近中文字幕免费国语 | 国产亚洲人成网站观看 | 欧美日韩一 | 亚洲人交性视频 | 黄色免费的网站 | 在线观看麻豆国产精品 | 在线一区三区四区产品动漫 | 久操久操久操 | 色老头一级毛片 | h成人在线 | 国产日韩免费视频 | 免费精品精品国产欧美在线 | 国产一区系列在线观看 | 国产乱人伦精品一区二区 | 波多野结衣免费在线视频 | 69人成网站色www| 日韩黄色影视 |