有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java应用程序截图时收到空消息

我是自动化新手。 我在截图时收到空消息

TestNG侦听器代码

@Override
public void onTestFailure(ITestResult arg0) {
    //write screenshot codes here
    String s=arg0.getName();
    try {
        Base.getScreenshot(s);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    

基类截图方法

        public static void getScreenshot(String s) throws IOException
        {
        try{
        
        File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);              
        // Copy files to specific location
        // arg0.getName() will return name of test case so that screenshot name will be same as test case name
        FileUtils.copyFile(src, new File(System.getProperty("user.dir")+"\\"+s+".png"));
        System.out.println("Successfully captured a screenshot");
        }catch (Exception e){
        System.out.println("Exception while taking screenshot "+e.getMessage());
        }
        
}

我使用一些不正确的定位器调用tentNG failure手动使测试失败,在截图时,它检索到空消息,如下所示

输出: 截图为空时发生异常

有谁能帮我解决这个问题吗

我现在被封锁了:(


共 (0) 个答案