Thursday, January 7, 2016

Selenium ScreenShots


Working with screen shots/ Print screen through selenium API

      public static String takeScreenShots(WebDriver driver) {  
           TakesScreenshot screen = (TakesScreenshot) driver;  
           File srcFile = screen.getScreenshotAs(OutputType.FILE);  
           copyFile(srcFile, "C:\\Test\\fileCopy");  
           driver.get("http://www.google.com");  
           String title = driver.getTitle();  
           return title;  
      }  
      public static void copyFile(File srcFile, String directoryPath) {  
           try {  
                // srcFile = new File("C:\\Test\\File1.txt");  
                File desDirectory = new File(directoryPath);  
                FileUtils.copyFileToDirectory(srcFile, desDirectory);  
           } catch (IOException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
           }  
      }  

No comments:

Post a Comment