亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-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
主站蜘蛛池模板: 欧美日韩性视频一区二区三区 | 亚洲大尺度 | 亚洲国产中文字幕在线观看 | 永久网站 | 成人一级毛片 | 精品久久久久久综合网 | 特级毛片s级全部免费 | 狠狠干夜夜爱 | 欧美人成在线观看ccc36 | 精品国产高清自在线一区二区三区 | 黄色网址免费大全 | 日韩福利视频导航 | 午夜18 | 在线亚洲综合美国十次 | 欧美日韩高清不卡一区二区三区 | 成人网18免费 | 国产成人人人爆出白浆 | 按摩一级片 | 国产日韩欧美久久久 | 91精品视频免费 | 午夜大片免费完整在线看 | 亚洲黄色中文字幕 | 激情久久久久久久久久久 | 免费乱理伦片在线观看八戒 | 小黄鸭视频网站 | 日韩video | 全午夜免费一级毛片 | 久热久草| 在线黄色网页 | 日本精品夜色视频一区二区 | 黄色免费的视频 | 日韩.欧美.国产.无需播放器 | 国产成人一区免费观看 | 日韩制服丝袜在线 | 91精品小视频 | 国产区一区二区三区 | 操人视频网站 | 香焦视频在线观看黄 | 欧美日韩免费在线观看 | 午夜福利毛片 | 午夜视频福利在线 |