虽然已定义,但构造函数File(String)不可见

时间:2017-06-20 12:54:07

标签: java cucumber cucumber-java

TakesScreenshot ts=(TakesScreenshot)driver;

File source=ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source,new File("./Screenshots/test.png"));

以上代码用于捕获屏幕截图并粘贴到文件中,但它无法找到FILE,第三行显示错误 - 构造(字符串)不可见。错误是什么?

2 个答案:

答案 0 :(得分:0)

您是否只是尝试在测试失败时捕捉屏幕截图,或者寻找不同的东西?如果前者this显示如何在@After中执行此操作,以防您在测试失败时尝试捕获屏幕截图。

答案 1 :(得分:0)

请尝试使用此完整方法截取屏幕截图并将结果存储在特定路径中。它对我有用。试试这个,让我知道。

public void TakeScreenShots(String TestID,String ResultsPath){
    try{
        GlobalVariable.bExitTestIteration = false;
        if(!(TestID.length()>0)){
            System.out.println("chk");
        }
        if((TestID.length()>0) && (ResultsPath.length()>0)){
                TestID=//DriverScript.sScenarioID;
                ResultsPath="//DriverScript.ResultsFolder";


            //****** Check if local variable is used **********
            if (ResultsPath.length()>2){
                if (ResultsPath.substring(0, 1)=="%%"){
                    ResultsPath = getDictinaryValues(ResultsPath.substring(2));
                }
            }
            //*************************************************         
            Log.info("Take a screenshot ");
            WebDriverWait wait = new WebDriverWait(driver, 10);
            File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            // Now you can do whatever you need to do with it, for example copy somewhere
            FileUtils.copyFile(scrFile, new File(ResultsPath+"\\" +TestID+ ".png"));
        }
     }catch(Exception e){
         Log.error("Not able to take a screenshot --- " + e.getMessage());           
        }
    }

请检查这段代码并回复我。

相关问题