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

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

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

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

  代碼變動(dòng): 比如某個(gè)元素不在

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

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

  在運(yùn)行出錯(cuò)的時(shí)候,捕獲錯(cuò)誤并截圖有兩種思路:

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

  利用 Juint 的 TestRule, 自定義一個(gè) Rule 在運(yùn)行失敗的時(shí)候截圖。

  自定義監(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;

  }

  意思是說,每個(gè)異常都是 ScreenshotException 的對(duì)象,轉(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下一頁
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 亚洲综合激情丁香六月 | 欧美一区二区三区免费 | 麻豆日韩国产精品欧美在线 | 欧美一a一片一级一片 | 农村妇女又色黄一级毛片 | 香焦视频在线观看黄 | 日韩三级一区二区 | 嫩草影院懂你的影院 | 亚洲欧美日韩中文v在线 | 一区二区三区无码高清视频 | xxxx69中国hd老师18 | 欧美18~20性hd | 99在线视频精品 | 久久综合色婷婷 | 日韩国产欧美一区二区三区 | 岛国午夜精品视频在线观看 | 在线免费视频网站 | 亚洲精品亚洲人成在线播放 | 伊人久久大杳蕉综合大象 | 国产91精品高跟丝袜在线 | 国产精品自在线 | 欧美日本在线视频 | 亚洲一区二区三区在线网站 | 高清午夜看片a福利在线观看琪琪 | 婷婷激情狠狠综合五月 | 欧美黄视频在线观看 | 成人男女网18免费91 | 欧美成人免费草草影院视频 | 黄色在线播放 | 成人日韩欧美 | 精品欧美在线观看 | 国产精品福利在线观看秒播 | 黄色的视频网站 | 国产在线视频第一页 | 国产精品麻豆一区二区三区 | 日韩欧美视频在线一区二区 | 99re热精品视频国产免费 | 久久99精品久久久久久园产越南 | 黄色一级毛片看一级毛片 | 国产成人精品日本亚洲语音2 | 色老头在线视频 |