入住 CI 中国社区 登录
CodeIgniter 中国开发者社区 返回首页

rosemarry的个人空间 https://codeigniter.org.cn/forums/?39678 [收藏] [复制] [分享] [RSS]

日志

Selenium Junit————WebDriver 运行失败截图代码

已有 651 次阅读2015-8-25 17:50 |个人分类:Selenium

package Error_png;

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.*;
import org.apache.commons.io.FileUtils;
import java.util.concurrent.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

public class Error_png {
 private WebDriver driver;
 private String baseUrl;
 private boolean acceptNextAlert = true;
 private StringBuffer verificationErrors = new StringBuffer();
 public String a;

 @Before
 public void setUp() throws Exception
 {
  driver = new FirefoxDriver();
  baseUrl = "http://www.baidu.com";
  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 }
 @Test
 public void testTakesScreenshot()throws Exception{
  driver.get(baseUrl+"/login/index");
    try{
     driver.findElement(By.id("kwddd")).sendKeys("Selenium webDriver");

  }
  catch(Exception e)
  {
   File srcFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
   FileUtils.copyFile(srcFile, new File("C:\\Users\\Administrator\\workspace\\ErpOfAutomation\\src\\Error_png\\3.png"));
  }

 }
 @After
 public void tearDown() throws Exception
 {
  driver.quit();
  String verificationErrorString = verificationErrors.toString();
  if (!"".equals(verificationErrorString)) {
        fail(verificationErrorString);
      }
 }
}


路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 入住 CI 中国社区