public void Compare_IncorrectFilePaths(string sourcePath, string targetPath, int fuzziness, string diffSavePath)
        {
            //Assign
            var currentPath = Directory.GetCurrentDirectory();
            var imagesPath  = $"{currentPath}\\Image\\TestFiles";

            if (!string.IsNullOrEmpty(sourcePath))
            {
                sourcePath = sourcePath.Replace("$imagesPath$", imagesPath);
            }

            if (!string.IsNullOrEmpty(targetPath))
            {
                targetPath = targetPath.Replace("$imagesPath$", imagesPath);
            }

            if (!string.IsNullOrEmpty(diffSavePath))
            {
                diffSavePath = targetPath.Replace("$imagesPath$", imagesPath);
            }

            var logger        = new Mock <ILogger <ImageComparer> >();
            var imageComparer = new ImageComparer(logger.Object);

            //Act
            Exception ex = Assert.Throws <MagickBlobErrorException>(() => imageComparer.Compare(sourcePath, targetPath, fuzziness, diffSavePath));

            //Assert
            ex.Should().NotBeNull();
        }
Beispiel #2
0
        /// <summary>
        /// Calls the method to compare the pictures and if differences found
        /// sends a mail to the defined address book.
        /// </summary>
        /// <param name="cam"></param>
        private void CompareTakenPictures(Camera cam)
        {
            string        path  = Path.Combine(picturesFolder, cam.CameraName);
            List <String> files = Directory.EnumerateFiles(path).ToList();

            if (files.Count > 2)
            {
                foreach (string file in files)
                {
                    File.Delete(file);
                }
            }
            else if (files.Count == 2)
            {
                FileInfo file0 = new FileInfo(files[0]);
                FileInfo file1 = new FileInfo(files[1]);

                if (file0.CreationTime > file1.CreationTime)
                {
                    file0 = new FileInfo(files[1]);
                    file1 = new FileInfo(files[0]);
                }

                Boolean compareResult = ImageComparer.Compare(file0.FullName, file1.FullName);

                if (!compareResult)
                {
                    new EmailCreator().SendMailForDifferentImages(file1.FullName);
                }

                File.Delete(file0.FullName);
            }
        }
        public void SimilarImage_MediumTolerance_Positive()
        {
            Image           expectedImage = Image.FromFile(testImagesPath + "Actual.jpg");
            Image           actualImage   = Image.FromFile(testImagesPath + "Actual_Edited.jpg");
            ColorDifference diff          = new ColorDifference(225);
            bool            compare       = ImageComparer.Compare(expectedImage, actualImage, diff);

            Assert.IsTrue(compare, "Compared Edited Images With Medium Tolerance");
        }
        public void SimilarImage_ZeroTolerance()
        {
            Image           expectedImage = Image.FromFile(testImagesPath + "Actual.jpg");
            Image           actualImage   = Image.FromFile(testImagesPath + "Actual_Edited.jpg");
            ColorDifference diff          = new ColorDifference(0);
            bool            compare       = ImageComparer.Compare(expectedImage, actualImage, diff);

            Assert.IsFalse(compare, "Compared Edited Images With Zero Tolerance");
        }
Beispiel #5
0
        public void CompareDifferentImagesLessDifferences()
        {
            string pathImage1 = @".\PictureUtils\Pictures\picture002.jpg";
            string pathImage2 = @".\PictureUtils\Pictures\picture003.jpg";

            bool actual = ImageComparer.Compare(pathImage1, pathImage2);

            Assert.AreEqual(true, actual);
        }
Beispiel #6
0
        public void CompareDifferentImagesMoreDifferences()
        {
            string pathImage1 = @".\PictureUtils\Pictures\picture001.jpg";
            string pathImage2 = @".\PictureUtils\Pictures\picture002.jpg";

            bool actual = ImageComparer.Compare(Path.GetFullPath(pathImage1), Path.GetFullPath(pathImage2));

            Assert.AreEqual(false, actual);
        }
Beispiel #7
0
        public void CompareSameImages()
        {
            string pathImage1 = @".\PictureUtils\Pictures\picture001.jpg";
            string pathImage2 = @".\PictureUtils\Pictures\picture001.jpg";

            bool actual = ImageComparer.Compare(Path.GetFullPath(pathImage1), Path.GetFullPath(pathImage2));

            Assert.AreEqual(true, actual);
        }
        public void MirrorImageComparision_LowTolerance()
        {
            Image           expectedImage = Image.FromFile(testImagesPath + "Actual.jpg");
            Image           actualImage   = Image.FromFile(testImagesPath + "Actual_Mirror.jpg");
            ColorDifference diff          = new ColorDifference(0);
            bool            compare       = ImageComparer.Compare(expectedImage, actualImage, diff, out var outPutFile);

            outPutFile.Save(testImagesPath + "Output\\" + System.Reflection.MethodBase.GetCurrentMethod().Name + ".jpg");
            Assert.IsFalse(compare, "Compared Edited Images With Medium Tolerance");
        }
        public void IdenticalImage_ZeroTolerance()
        {
            Image           expectedImage = Image.FromFile(testImagesPath + "Actual.jpg");
            Image           actualImage   = Image.FromFile(testImagesPath + "Actual_Copy.jpg");
            ColorDifference diff          = new ColorDifference(0);
            bool            compare       = ImageComparer.Compare(expectedImage, actualImage, diff, out var outPutFile);

            outPutFile.Save(testImagesPath + "Output\\" + System.Reflection.MethodBase.GetCurrentMethod().Name + ".jpg");
            Assert.IsTrue(compare, "Comparision should return 'TRUE'");
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            ChromeDriver driver = new ChromeDriver();


            driver.Navigate().GoToUrl("https://passport.cnblogs.com/user/signin");
            driver.Manage().Window.Maximize();//窗口最大化,便于脚本执行

            //设置超时等待(隐式等待)时间设置10秒
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10000);

            driver.FindElementByXPath("//*[@id=\"input1\"]").SendKeys("username");

            driver.FindElementByXPath("//*[@id=\"input2\"]").SendKeys("password");

            driver.FindElementByXPath("//*[@id=\"signin\"]").Click();
            Thread.Sleep(3000);
            driver.FindElementByXPath("//*[@id=\"captchaBox\"]/div/div[2]/div[1]/div[3]/span[1]").Click();
            Actions actions = new Actions(driver);

            Thread.Sleep(3000);
            driver.GetScreenshot().SaveAsFile("原始验证图.png");
            // /html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]
            driver.FindElementByXPath("/html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]").Click();
            //actions.DragAndDropToOffset(driver,leftShift,0).Build().Perform();//单击并在指定的元素上按下鼠标按钮,然后移动到指定位置
            Thread.Sleep(3000);
            driver.GetScreenshot().SaveAsFile("阴影验证图.png");

            //E:\LoginTest-master\LoginTest-master\LoginTest\bin\Debug
            Bitmap a = new Bitmap(@"E:\LoginTest-master\LoginTest-master\LoginTest\bin\Debug\原始验证图.png");
            Bitmap b = new Bitmap(@"E:\LoginTest-master\LoginTest-master\LoginTest\bin\Debug\阴影验证图.png");
            int    c = GetArgb(a, b);

            actions.DragAndDropToOffset(driver.FindElementByXPath("/html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]"), c - 494, 0).Build().Perform();//移动滑块到阴影处


            List <Rectangle> Compare = ImageComparer.Compare(a, b);

            foreach (Rectangle item in Compare)
            {
                Thread.Sleep(2000);
                actions.DragAndDropToOffset(driver.FindElementByXPath("/html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]"), item.X + 13, 0).Build().Perform();   //移动滑块到阴影处
            }

            while (true)
            {
                Thread.Sleep(1000);
                Console.WriteLine(0);
            }
        }
        public void Compare_Images(string testName, string sourceImage, string targetImage, double expectedDifferenceMin, double expectedDifferenceMax, int fuzz = 0)
        {
            //Assign
            var currentPath = Directory.GetCurrentDirectory();
            var source      = $"{currentPath}\\Image\\TestFiles\\{sourceImage}";
            var target      = $"{currentPath}\\Image\\TestFiles\\{targetImage}";
            var diff        = $"{currentPath}\\Image\\TestFiles\\Result_{testName}.bmp";

            var logger = new Mock <ILogger <ImageComparer> >();

            var imageComparer = new ImageComparer(logger.Object);

            //Act
            var difference = imageComparer.Compare(source, target, fuzz, diff);

            //Assert
            difference.Should().BeGreaterOrEqualTo(expectedDifferenceMin);
            difference.Should().BeLessOrEqualTo(expectedDifferenceMax);
        }
Beispiel #12
0
        public void TransformTwoImagesAndCompare()
        {
            //Saturation button should be in unselected state

            #region TestData
            Image           image1, image2;
            bool            compareWithZeroTolerance, compareWith100Tolerance;
            ColorDifference diff          = new ColorDifference(0);
            string          originalImage = testImagesPath + "Actual.jpg";
            string          imagesPath    = FileUtilities.CheckAndCreateDirectory(testImagesPath + System.Reflection.MethodBase.GetCurrentMethod().Name + @"\");
            string          runTimeImage1 = imagesPath + "First.jpg";
            string          runTimeImage2 = imagesPath + "Second.jpg";

            #endregion

            #region OpenImageAndEdit1

            FileUtilities.OpenFile(originalImage);
            wndImagePro.ClickTabAdjust();
            wndImagePro.ClickBtnRotate();

            wndImagePro.ClickTabMeasure();
            wndImagePro.ClickBtnCreate();
            wndImagePro.ClickTabCapture();
            wndImagePro.ClickBtnSaturation();

            //wndImagePro.TabCountOrSize().ClickPoint();
            //wndImagePro.BtnCount().ClickPoint(-40);

            wndImagePro.ImageViewer.ClickPoint();
            wndImagePro.ImageViewer.CaptureImage(runTimeImage1);

            #endregion

            #region setup

            wndImagePro.CloseAllToolsAndViews(true);

            #endregion

            #region OpenImageAndEdit2

            System.Threading.Thread.Sleep(2000);
            FileUtilities.OpenFile(originalImage);
            FileUtilities.OpenFile(originalImage);

            wndImagePro.ClickTabAdjust();
            wndImagePro.ClickBtnRotate();

            wndImagePro.ClickTabMeasure();
            wndImagePro.ClickBtnCreate();
            System.Threading.Thread.Sleep(1000);

            //Observation: Saturation is selected by default
            //wndImagePro.TabCapture.ClickPoint();
            //wndImagePro.BtnSaturation.Click();

            wndImagePro.ImageViewer.ClickPoint();
            wndImagePro.ImageViewer.CaptureImage(runTimeImage2);

            #endregion


            image1 = Image.FromFile(runTimeImage1);
            image2 = Image.FromFile(runTimeImage2);

            compareWithZeroTolerance = ImageComparer.Compare(image1, image2, diff, out Image outPutFile);
            outPutFile.Save(imagesPath + "Output1.jpg");
            Assert.IsTrue(compareWithZeroTolerance, "Images should be same compareWithZeroTolerance");

            diff = new ColorDifference(100);
            compareWith100Tolerance = ImageComparer.Compare(image1, image2, diff, out outPutFile);
            outPutFile.Save(imagesPath + "Output2.jpg");
            Assert.IsTrue(compareWith100Tolerance, "Images should be same compareWith100Tolerance");
        }
Beispiel #13
0
        public void TransformPartiallyAndCompare_ExpectedFail()
        {
            #region TestData
            bool   compare = false;
            Image  image1;
            Image  image2;
            string imagesPath = FileUtilities.CheckAndCreateDirectory(testImagesPath + System.Reflection.MethodBase.GetCurrentMethod().Name + @"\"); ColorDifference diff = new ColorDifference(0);
            string originalImage = imagesPath + "Actual.jpg";
            string runTimeImage1 = imagesPath + "First.jpg";
            string runTimeImage2 = imagesPath + "Second.jpg";

            #endregion

            #region OpenImageAndEdit1

            FileUtilities.OpenFile(originalImage);
            wndImagePro.ClickTabAdjust();
            wndImagePro.ClickBtnRotate();

            wndImagePro.ClickTabMeasure();
            wndImagePro.ClickBtnCreate();

            System.Threading.Thread.Sleep(1000);

            wndImagePro.ClickTabCapture();
            wndImagePro.ClickBtnSaturation(); //Select Saturation

            wndImagePro.ImageViewer.ClickPoint();
            wndImagePro.ImageViewer.CaptureImage(runTimeImage1);

            #endregion

            wndImagePro.CloseAllToolsAndViews(true);

            #region OpenImageAndEdit Partial

            //System.Threading.Thread.Sleep(2000);
            FileUtilities.OpenFile(originalImage);
            FileUtilities.OpenFile(originalImage);

            wndImagePro.ClickTabAdjust();
            wndImagePro.ClickBtnRotate();

            wndImagePro.ClickTabMeasure();
            wndImagePro.ClickBtnCreate();

            wndImagePro.ClickTabCapture();
            wndImagePro.ClickBtnSaturation(); //Unselect Saturation

            wndImagePro.ImageViewer.ClickPoint();
            wndImagePro.ImageViewer.CaptureImage(runTimeImage2);

            #endregion


            image1  = Image.FromFile(runTimeImage1);
            image2  = Image.FromFile(runTimeImage2);
            compare = ImageComparer.Compare(image1, image2, diff, out Image outPutFile);
            outPutFile.Save(imagesPath + "Output1.jpg");
            Assert.IsTrue(compare, "Falsy expecting: Images should not match");
        }
Beispiel #14
0
        public void TransformStepByStepAndCompare()
        {
            /*Open original image, transform image and save
             * open original image again, apply partial transformation again, save
             * Compare two images, the compare should result false*/

            /*Complete the transformation on second image
             * Compare two images with different threshold levels
             * Test case should pass*/

            #region TestData
            Image           image1, image2, image3;
            ColorDifference diff       = new ColorDifference(0);
            string          imagesPath = FileUtilities.CheckAndCreateDirectory(testImagesPath + System.Reflection.MethodBase.GetCurrentMethod().Name + @"\");
            bool            compare;
            string          originalImage = imagesPath + "Actual.jpg";
            string          runTimeImage1 = imagesPath + "First.jpg";
            string          runTimeImage2 = imagesPath + "Second.jpg";
            string          runTimeImage3 = imagesPath + "Third.jpg";
            #endregion


            #region OpenImageAndEdit1

            FileUtilities.OpenFile(originalImage);
            wndImagePro.ClickTabAdjust();
            wndImagePro.ClickBtnRotate();

            wndImagePro.ClickTabMeasure();
            wndImagePro.ClickBtnCreate();

            System.Threading.Thread.Sleep(1000);

            wndImagePro.ClickTabCapture();
            wndImagePro.ClickBtnSaturation();
            //Select Saturation

            wndImagePro.ImageViewer.ClickPoint();
            wndImagePro.ImageViewer.CaptureImage(runTimeImage1);

            #endregion

            wndImagePro.CloseAllToolsAndViews(true);

            #region OpenImageAndEdit Partial

            //System.Threading.Thread.Sleep(2000);
            FileUtilities.OpenFile(originalImage);
            FileUtilities.OpenFile(originalImage);

            wndImagePro.ClickTabAdjust();
            wndImagePro.ClickBtnRotate();

            wndImagePro.ClickTabMeasure();
            wndImagePro.ClickBtnCreate();

            wndImagePro.ClickTabCapture();
            wndImagePro.ClickBtnSaturation();
            //Unselect Saturation

            wndImagePro.ImageViewer.ClickPoint();
            wndImagePro.ImageViewer.CaptureImage(runTimeImage2);

            #endregion


            image1 = Image.FromFile(runTimeImage1);
            image2 = Image.FromFile(runTimeImage2);

            compare = ImageComparer.Compare(image1, image2, diff, out Image outPutFile);
            outPutFile.Save(imagesPath + "Output1.jpg");
            Assert.IsFalse(compare, "Images should not match");

            #region Continue transform

            wndImagePro.ClickTabCapture();
            wndImagePro.ClickBtnSaturation();
            //Select Saturation

            wndImagePro.ImageViewer.ClickPoint();
            wndImagePro.ImageViewer.CaptureImage(runTimeImage3);


            image3 = Image.FromFile(runTimeImage3);

            diff    = new ColorDifference(0);
            compare = ImageComparer.Compare(image1, image3, diff, out outPutFile);
            outPutFile.Save(imagesPath + "Output2.jpg");
            Assert.IsTrue(compare, "Images should match");

            #endregion
        }
Beispiel #15
0
 /// <summary>
 /// 发送图像到远程
 /// </summary>
 private void SendImage()
 {
     Task.Factory.StartNew(() =>
     {
         //Bitmap lastBitmap = null;
         Rectangle rectangle = new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
         while (!_isClose)
         {
             try
             {
                 if (true)
                 {
                     using (Bitmap desktopImage = new Bitmap(rectangle.Width, rectangle.Height))
                     {
                         using (Graphics g = Graphics.FromImage(desktopImage))
                         {
                             try
                             {
                                 g.CopyFromScreen(0, 0, 0, 0, desktopImage.Size);
                             }
                             catch (Exception ex)
                             {
                                 continue;
                             }
                             MouseAndKeyHelper.DrawMouse(g);
                             //比较此次截图与上一张截图的差异
                             if (lastBitmap != null)
                             {
                                 List <Rectangle> rects = ImageComparer.Compare(lastBitmap, desktopImage);
                                 lastBitmap             = (Bitmap)desktopImage.Clone();
                                 if (rects.Count == 0)//无变化不发送
                                 {
                                     Thread.Sleep(sec);
                                 }
                                 if (rects.Count <= 480)//差异小于7块则分段传输
                                 {
                                     Dictionary <Rectangle, Bitmap> dic = new Dictionary <Rectangle, Bitmap>();
                                     foreach (var rect in rects)
                                     {
                                         Bitmap bmSmall = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppRgb);
                                         using (Graphics grSmall = Graphics.FromImage(bmSmall))
                                         {
                                             grSmall.DrawImage(desktopImage, 0, 0,
                                                               rect, GraphicsUnit.Pixel);
                                             grSmall.Save();
                                             grSmall.Dispose();
                                         }
                                         dic.Add(rect, (Bitmap)bmSmall.Clone());
                                     }
                                     if (dic.Count > 0)
                                     {
                                         _mCleint.SendFileSlice(_remote, CompressHelper.Compress(SerializeHelper.ByteSerialize(dic)));
                                         isBigChnage = false;
                                         Thread.Sleep(sec);
                                     }
                                 }
                                 else
                                 {//发送完整的图片
                                     if (isBigChnage == false)
                                     {
                                         SendImageFile(desktopImage, g);
                                         lastBitmap = (Bitmap)desktopImage.Clone();//要在之前否则销毁掉了
                                         Thread.Sleep(sec);
                                     }
                                     else
                                     {
                                         isBigChnage = false;
                                     }
                                 }
                             }
                             else
                             {                                              //第一张图片
                                 lastBitmap = (Bitmap)desktopImage.Clone(); //要在之前否则销毁掉了
                                 SendImageFile(desktopImage, g);
                                 Thread.Sleep(sec);
                             }
                         }
                     }
                 }
                 else
                 {
                     Thread.Sleep(100);
                 }
             }
             catch (Exception ex)
             {
                 continue;
             }
         }
     }, cts.Token);
 }