2017-08-17 53 views
0

目前,我的代碼需要一些分辨率的截圖。我想讓所有圖像與最後捕獲的圖​​像共存。硒/ JAVA圖像比較

我的代碼截取屏幕截圖。現在我想做一些與分辨率文件夾和當前圖像文件夾的最後一個列表比較,並生成圖像哪裏程序將標記什麼是不同的。任何幫助將被通知。

@Test 
public void testResolution() throws InterruptedException 
{ 
    this.url = "https://www.google.com"; 
    driver.get(this.url); 
    driver.navigate().to(this.url); 
    String[] resulutions = { "1366x768" , "360x640" , "768x1024" , "375x667" , "1920x1080" , "320x568" , "1600x900" , "1280x800" , 
      "1440x900" , "1536x864" , "414x736" , "1280x1024" , "1280x720" , "1440x900" , "1680x1050" , "1024x768" , "1920x1080" , 
      "1280x800" , "1024x768" , "1280x800" , "412x732" , "320x534" , "320x570" , "1093x614", }; 

      // add resolution 

    for (String resulution : resulutions) 
    {  
     String[] parts = resulution.split("x");  
     // Screen resolution 
     Dimension screenRes = new Dimension(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]));      
     // Set browser resolution 
     driver.manage().window().setSize(screenRes); 
     driver.navigate().refresh(); 
     Thread.sleep(3000); 
     this.takeScreenShot(resulution); 
    } 
} 

/** 
* 
* @param fileName 
*/ 

private void takeScreenShot(String fileName) 
{  
    File screenShot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); 
    try { 
     //FileUtils.copyFile(screenShot, new File("Old"+fileName+"/"+fileName+ ".png")); 
     //FileUtils.copyFile(screenShot, new File("E:\\Faysal_test/"+fileName+"/"+fileName+ ".png")); 
     FileUtils.copyFile(screenShot, new File("D:\\Automation/VRS/vrs-resolution/Screenshot/new/"+fileName+"/"+fileName+ ".png")); 

    } catch (IOException ioe) { 
     throw new RuntimeException(ioe.getMessage(), ioe); 
    } 
} 

@Test 

public void testResolutionold() throws InterruptedException 
{ 

    this.url = "https://www.rentalhomes.com/property/extended-stay-america-billings-west-end/BC-517037"; 
    driver.get(this.url); 
    driver.navigate().to(this.url); 
    String[] resulutions = { "1366x768" , "360x640" , "768x1024" , "375x667" , "1920x1080" , "320x568" , "1600x900" , "1280x800" , 
      "1440x900" , "1536x864" , "414x736" , "1280x1024" , "1280x720" , "1440x900" , "1680x1050" , "1024x768" , "1920x1080" , 
      "1280x800" , "1024x768" , "1280x800" , "412x732" , "320x534" , "320x570" , "1093x614",}; 
      // add resolution  
    for (String resulution : resulutions) 
    { 

     String[] parts = resulution.split("x"); 

     // Screen resolution 
     Dimension screenRes = new Dimension(Integer.parseInt(parts[0]), Integer.parseInt(parts[1])); 


     // Set browser resolution 
     driver.manage().window().setSize(screenRes); 
     driver.navigate().refresh(); 
     Thread.sleep(3000); 
     this.takeScreenShotold(resulution); 
    } 

} 

/** 
* 
* @param fileName 
*/ 

private void takeScreenShotold(String fileName) 
{ 

    File screenShot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); 
    try { 
     //FileUtils.copyFile(screenShot, new File("Old"+fileName+"/"+fileName+ ".png")); 
     //FileUtils.copyFile(screenShot, new File("E:\\Faysal_test/"+fileName+"/"+fileName+ ".png")); 
     FileUtils.copyFile(screenShot, new File("D:\\Automation/VRS/vrs-resolution/Screenshot/old/"+fileName+"/"+fileName+ ".png")); 

    } catch (IOException ioe) { 
     throw new RuntimeException(ioe.getMessage(), ioe); 
    } 
} 
+0

[將圖像與實際屏幕進行比較]可能存在重複(https://stackoverflow.com/questions/20661250/compare-image-to-actual-screen) – JeffC

回答

0

查看OpenCV庫。你可以找到你需要的東西。看看如何比較圖像here