2012-02-10 4 views
1

나는 Selenium Automation을 사용하여 우리 회사의 웹 사이트를 자동화 할 것을 요청 받았다. 하지만 나는 Selenium tool을 처음 사용하기는했지만 Selenium IDE와 RC의 기초를 배웠다. 그러나 저는 다른 자동화 도구에서 일반적으로하는 것처럼 실제 이미지와 원본 이미지를 비교하는 방법과 매우 혼동합니다. 웹 사이트에 버그가있는 결과를 얻으려면 어떻게해야합니까? 그것의 분명히 이미지 비교를 통해하지만 셀레늄은 매우 인기있는 도구 중 하나입니다 궁금해하지만 이미지를 옵션을 비교하지 않습니다. 다른 한편으로 나는 자동화 과정을 진행하는 나의 방법이 정확한지 의심 스럽다! 누군가 제발 도와주세요.Selenium에서 이미지를 비교하는 방법은 무엇입니까?

감사의 말 !! Sanjay S

답변

0

Selenium RC에 대한 지식을 언급 했으므로 선택한 프로그래밍 언어로 라이브러리를 사용하여 Selenium의 기능을 쉽게 확장 할 수 있습니다. 예를 들어, 자바에서는 PixelGrabber 클래스를 사용하여 두 이미지를 비교하고 일치하는 것을 주장 할 수 있습니다.

+0

계산합니다. 원본 이미지와 출력 이미지를 비교할 때 어려움을 느낍니다. ImageMagick 또는 ImageDiff와 같은 도구를 사용하여 이미지 비교를 수행하지만 한 번에 하나의 이미지 세트에 대해서만 작업을 수행합니다. 이미지 세트가 500 개 이상이므로 이미지 비교를 수행하는 것은 상당히 어려운 작업입니다. 여러 가지 이미지를 한 번에 비교하는 대신 시간이 많이 걸리는 이미지를 비교하는 등 다른 방법으로이를 해결할 수 있습니다. 웹 드라이버>를 사용하여 완료 할 수 있습니까? 사전 감사 ... Sanjay .. – user1068759

0

imagemagick과 imagediff도 이미지 일치에 사용하는 두 가지 좋은 도구입니다. Selenium RC와 프로그래밍 언어 지식이 필요합니다.

2

나는 simillar 작업을했습니다. 웹 페이지에서 3000 개 이상의 이미지를 비교해야했습니다. 내가 처음 이미지와 모든 이미지의 크기를 비교 한 후

public void compareImage() throws InterruptedException { 
    driver.get(baseUrl); 
    driver.manage().window().maximize(); 

    JavascriptExecutor executor = (JavascriptExecutor) driver; 

    Long previousHeight; 
    Long currentHeight; 

    do { 
     previousHeight = (Long) executor.executeScript("return    document.documentElement.scrollHeight"); 

     executor.executeScript("window.scrollBy(0, document.documentElement.scrollHeight)"); 
     Thread.sleep(500); 
     currentHeight = (Long) executor.executeScript("return  document.documentElement.scrollHeight"); 
    } while (Long.compare(previousHeight, currentHeight) != 0); 

(또는 당신은 단지 크기를 쓸 수 있습니다) : 내가 페이지를 스크롤 모든 먼저 모든 이미지를로드 C에 #

List<WebElement> images = driver.findElements(By.cssSelector("img[class='playable']")); 
    List<String> errors = new LinkedList<>(); 

    int imgWidth, imgHeight, elWidth, elHeight; 
    int imgNum = 0; 

    imgWidth = images.get(0).getSize().getWidth(); 
    imgHeight = images.get(0).getSize().getHeight(); 


    for (WebElement el : images) { 
     imgNum++; 

     elWidth = el.getSize().getWidth(); 
     elHeight = el.getSize().getHeight(); 

     if (imgWidth != elWidth || imgHeight != elHeight) { 
      errors.add(String.format("Picture # %d has incorrect size (%d : %d) px" 
        , imgNum, elWidth, elHeight)); 
     } 
    } 

    for (String str : errors) 
     System.out.println(str); 

    if (errors.size() == 0) 
     System.out.println("All images have the same size"); 
} 
0

이미지 비교. 정확한 결과를 얻으려면 캡쳐 화면을 찍기 전에 앤티 앨리어스 브라우저 기능을 사용하지 않는 것이 좋습니다. 그렇지 않으면 픽셀이 조금씩 다르게 그려집니다. 예를 들어 HTML 캔버스 요소 options.AddArgument ("disable-canvas-aa"); 내가 프로그래밍 언어 C#을 위해 셀레늄 RC를 사용할 때

private static bool ImageCompare(Bitmap bmp1, Bitmap bmp2, Double TolerasnceInPercent) 
    { 
     bool equals = true; 
     bool flag = true; //Inner loop isn't broken 

     //Test to see if we have the same size of image 
     if (bmp1.Size == bmp2.Size) 
     { 
      for (int x = 0; x < bmp1.Width; ++x) 
      { 
       for (int y = 0; y < bmp1.Height; ++y) 
       { 
        Color Bitmap1 = bmp1.GetPixel(x, y); 
        Color Bitmap2 = bmp2.GetPixel(x, y); 

        if (Bitmap1.A != Bitmap2.A) 
        { 
         if (!CalculateTolerance(Bitmap1.A, Bitmap2.A, TolerasnceInPercent)) 
         { 
          flag = false; 
          equals = false; 
          break; 
         } 
        } 
        if (Bitmap1.R != Bitmap2.R) 
        { 
         if (!CalculateTolerance(Bitmap1.R, Bitmap2.R, TolerasnceInPercent)) 
         { 
          flag = false; 
          equals = false; 
          break; 
         } 
        } 
        if (Bitmap1.G != Bitmap2.G) 
        { 
         if (!CalculateTolerance(Bitmap1.G, Bitmap2.G, TolerasnceInPercent)) 
         { 
          flag = false; 
          equals = false; 
          break; 
         } 
        } 
        if (Bitmap1.B != Bitmap2.B) 
        { 
         if (!CalculateTolerance(Bitmap1.B, Bitmap2.B, TolerasnceInPercent)) 
         { 
          flag = false; 
          equals = false; 
          break; 
         } 
        } 

       } 
       if (!flag) 
       { 
        break; 
       } 
      } 
     } 
     else 
     { 
      equals = false; 
     } 
     return equals; 
    } 
0

이 C#을 기능을 허용

private static bool CalculateTolerance(Byte FirstImagePixel, Byte SecondImagePixel, Double TolerasnceInPercent) 
    { 
     double OneHundredPercent; 
     double DifferencesInPix; 
     double DifferencesPercentage; 


     if (FirstImagePixel > SecondImagePixel) 
     { 
      OneHundredPercent = FirstImagePixel; 
     } 
     else 
     { 
      OneHundredPercent = SecondImagePixel; 
     } 

     if (FirstImagePixel > SecondImagePixel) 
     { 
      DifferencesInPix = FirstImagePixel - SecondImagePixel; 
     } 
     else 
     { 
      DifferencesInPix = SecondImagePixel - FirstImagePixel; 
     } 

     DifferencesPercentage = (DifferencesInPix * 100)/OneHundredPercent; 

     DifferencesPercentage = Math.Round(DifferencesPercentage, 2); 

     if (DifferencesPercentage > TolerasnceInPercent) 
     { 
      return false;     
     } 

     return true; 
    } 
관련 문제