Ejemplo n.º 1
0
        private bool HtmlImgCompare(string html, string imgPath)
        {
            string temphtmlPath = SpecialDirectories.Temp + "\\SUITemp.html";

            if (File.Exists(imgPath))
            {
                SUIBitmap standardImg = SUIBitmap.LoadSUIBitmap(imgPath);
                if (standardImg == null)
                {
                    throw (new SUIHtmlCompareException());
                }
                try
                {
                    SUIUtil.OutputFileFromString(html, temphtmlPath);
                    SUIIE     ie      = SUIIE.CreateIEWithURL(temphtmlPath);
                    SUIBitmap tempImg = ie.GetClientArea();
                    // Fix a bug: we need to assign image path to the captured temp SUIBitmap object.
                    tempImg.Path = imgPath;
                    //SUIIE.CleanIEProcess();
                    SUIImageComparer Comparer = new SUIImageComparer();
                    return(Comparer.Compare(standardImg, tempImg));
                }catch (SUIException e)
                {
                    throw(new SUIHtmlCompareException(e));
                }
            }
            else
            {
                try
                {
                    SUIUtil.OutputFileFromString(html, temphtmlPath);
                    SUIIE     ie      = SUIIE.CreateIEWithURL(temphtmlPath);
                    SUIBitmap tempImg = ie.GetClientArea();
                    //SUIIE.CleanIEProcess();
                    tempImg.Path = imgPath;
                    tempImg.Save();
                    return(true);
                }
                catch (SUIException e)
                {
                    throw (new SUIHtmlCompareException(e));
                }
            }
        }
Ejemplo n.º 2
0
 private bool HtmlImgCompare(string html,string imgPath)
 {
     string temphtmlPath = SpecialDirectories.Temp+"\\SUITemp.html";
     if (File.Exists(imgPath))
     {
         SUIBitmap standardImg = SUIBitmap.LoadSUIBitmap(imgPath);
         if (standardImg == null)
         {
             throw (new SUIHtmlCompareException());
         }
         try
         {
             SUIUtil.OutputFileFromString(html, temphtmlPath);
             SUIIE ie = SUIIE.CreateIEWithURL(temphtmlPath);
             SUIBitmap tempImg = ie.GetClientArea();
             // Fix a bug: we need to assign image path to the captured temp SUIBitmap object.
             tempImg.Path = imgPath;
             //SUIIE.CleanIEProcess();
             SUIImageComparer Comparer = new SUIImageComparer();
             return (Comparer.Compare(standardImg, tempImg));
         }catch(SUIException e)
         {
             throw(new SUIHtmlCompareException(e));
         }
     }
     else
     {
         try
         {
             SUIUtil.OutputFileFromString(html, temphtmlPath);
             SUIIE ie = SUIIE.CreateIEWithURL(temphtmlPath);
             SUIBitmap tempImg = ie.GetClientArea();
             //SUIIE.CleanIEProcess();
             tempImg.Path = imgPath;
             tempImg.Save();
             return true;
         }
         catch (SUIException e)
         {
             throw (new SUIHtmlCompareException(e));
         }
     }
 }
Ejemplo n.º 3
0
        public bool CompareWindowImage(SUIWindow window, SUIBitmap baseImage,Rectangle[] NotCompare)
        {
            SUIBitmap windowImage = SUIImage.GetImageFromWindow(window);
            windowImage.Path = baseImage.Path; //2007 5-24 fhu add this line.
            if (baseImage.IsNullBitmap)
            {
                if (!windowImage.IsNullBitmap)
                {
                    windowImage.Path = baseImage.Path;
                    windowImage.Save();
                    windowImage.ReleaseMem();
                    return true;
                }
            }
            //Here's the Vista specific image comparison.
            if ((SUIUtil.IsCurrentOSVista || SUIUtil.IsCurrentOSXP) && (window.IsDialog || window.IsWinForm))
            {
                SUIDialog dialog = new SUIDialog(window);
                SUIButton defaultButton = dialog.DefaultPushButton;
                if (defaultButton == null)
                    return SUIComparer.GetComparer(ComparerType.Image).Compare(baseImage, windowImage);
                else
                {
                    Bitmap bmBase = baseImage.Bitmap;
                    Bitmap bmTest = windowImage.Bitmap;
                    int base_width = bmBase.Width;
                    int base_height = bmBase.Height;

                    int test_width = bmTest.Width;
                    int test_height = bmTest.Height;

                    //First of all, compare the size of images.
                    if ((base_width != test_width) || (base_height != test_height))
                    {
                        windowImage.Path = baseImage.Path.Replace(".bmp", "_error.bmp");
                        windowImage.Save();
                        windowImage.ReleaseMem();
                        return false;
                    }

                    //Retrieve button area.
                    Rectangle defaultButtonRectangle = new Rectangle();
                    defaultButtonRectangle.X = defaultButton.X - dialog.X;
                    defaultButtonRectangle.Y = defaultButton.Y - dialog.Y;
                    defaultButtonRectangle.Width = defaultButton.Width - defaultButton.X;
                    defaultButtonRectangle.Height = defaultButton.Height - defaultButton.Y;

                    // Ignor the comparison of a 4-pixel width border so that we could
                    // get rid of the side effect of dash-line rectangle on the button.
                    Rectangle defaultButtonRectangleEx = new Rectangle();
                    defaultButtonRectangleEx.X = defaultButtonRectangle.X + 4;
                    defaultButtonRectangleEx.Y = defaultButtonRectangle.Y + 4;
                    defaultButtonRectangleEx.Width = defaultButtonRectangle.Width - 8;
                    defaultButtonRectangleEx.Height = defaultButtonRectangle.Height - 8;
                    //Ignor the effect of flatness under vista
                    Rectangle flatnessRectangle1 = new Rectangle();
                    flatnessRectangle1.X = 0;
                    flatnessRectangle1.Y = 0;
                    flatnessRectangle1.Width = 6;
                    flatnessRectangle1.Height = 6;
                    Rectangle flatnessRectangle2 = new Rectangle();
                    flatnessRectangle2.X = dialog.Width -dialog.X- 6;
                    flatnessRectangle2.Y = 0;
                    flatnessRectangle2.Width = 6;
                    flatnessRectangle2.Height = 6;
                    Rectangle[] FlatnessAreas = new Rectangle[2];
                    FlatnessAreas[0] = flatnessRectangle1;
                    FlatnessAreas[1] = flatnessRectangle2;
                    Bitmap difference = new Bitmap(base_width, base_height);
                    bool bChange = false;
                    int i, j;
                    Color pixBase;
                    Color pixTest;
                    for (i = 0; i < base_width; i++)
                    {
                        for (j = 0; j < base_height; j++)
                        {
                            pixBase = bmBase.GetPixel(i, j);
                            pixTest = bmTest.GetPixel(i, j);
                            Point temp = new Point(i, j);
                            if (IsContainsPoint(FlatnessAreas,temp))
                            {
                                //difference.SetPixel(i, j, Color.White);
                                continue;
                            }
                            if (IsContainsPoint(NotCompare,temp))
                            {
                                //difference.SetPixel(i, j, Color.White);
                                continue;
                            }
                            if (!defaultButtonRectangle.Contains(temp))
                            {
                                if (!colorComparer.Compare(pixBase, pixTest))
                                {
                                    bChange = true;
                                    difference.SetPixel(i, j, Color.Black);
                                }
                                else
                                    difference.SetPixel(i, j, Color.White);
                            }
                            else if (!defaultButtonRectangleEx.Contains(temp))
                            {
                                // Ignor the pixels in this border.
                                //difference.SetPixel(i, j, Color.Orange);
                            }
                            else //Process the pixels in OK button rectangle
                            {
                                if (!colorComparer.Compare(pixBase, pixTest))
                                {
                                    int defaultBuffer = SUIColorComparer.buffer;
                                    //Temproraly set buffer to 150 since in this special area we need a larger buffer.
                                    SUIColorComparer.buffer = 150;
                                    if (colorComparer.Compare(pixBase, SystemColors.ControlText) || colorComparer.Compare(pixTest, SystemColors.ControlText))
                                    {
                                        bChange = true;
                                        difference.SetPixel(i, j, Color.Black);
                                    }
                                    //else
                                    //    difference.SetPixel(i, j, Color.Blue);
                                    // Set the default buffer back.
                                    SUIColorComparer.buffer = defaultBuffer;
                                }
                                //else
                                //    difference.SetPixel(i, j, Color.Red);
                            }
                        }
                    }

                    if (bChange)
                    {
                        windowImage.Path = baseImage.Path.Replace(".bmp", "_error.bmp");
                        windowImage.Save();
                        windowImage.ReleaseMem();
                        string path = baseImage.Path.Replace(".bmp", "_error_difference.bmp");
                        difference.Save(path);
                        return false;
                    }
                    return true;
                }
            }
            else
            {
                SUIImageComparer imgComparer = new SUIImageComparer();
                return imgComparer.OptionCompare3(baseImage,windowImage,NotCompare);
            }
        }
Ejemplo n.º 4
0
        public bool CompareWindowImage(SUIWindow window, SUIBitmap baseImage, Rectangle[] NotCompare)
        {
            SUIBitmap windowImage = SUIImage.GetImageFromWindow(window);

            windowImage.Path = baseImage.Path; //2007 5-24 fhu add this line.
            if (baseImage.IsNullBitmap)
            {
                if (!windowImage.IsNullBitmap)
                {
                    windowImage.Path = baseImage.Path;
                    windowImage.Save();
                    windowImage.ReleaseMem();
                    return(true);
                }
            }
            //Here's the Vista specific image comparison.
            if ((SUIUtil.IsCurrentOSVista || SUIUtil.IsCurrentOSXP) && (window.IsDialog || window.IsWinForm))
            {
                SUIDialog dialog        = new SUIDialog(window);
                SUIButton defaultButton = dialog.DefaultPushButton;
                if (defaultButton == null)
                {
                    return(SUIComparer.GetComparer(ComparerType.Image).Compare(baseImage, windowImage));
                }
                else
                {
                    Bitmap bmBase      = baseImage.Bitmap;
                    Bitmap bmTest      = windowImage.Bitmap;
                    int    base_width  = bmBase.Width;
                    int    base_height = bmBase.Height;

                    int test_width  = bmTest.Width;
                    int test_height = bmTest.Height;

                    //First of all, compare the size of images.
                    if ((base_width != test_width) || (base_height != test_height))
                    {
                        windowImage.Path = baseImage.Path.Replace(".bmp", "_error.bmp");
                        windowImage.Save();
                        windowImage.ReleaseMem();
                        return(false);
                    }

                    //Retrieve button area.
                    Rectangle defaultButtonRectangle = new Rectangle();
                    defaultButtonRectangle.X      = defaultButton.X - dialog.X;
                    defaultButtonRectangle.Y      = defaultButton.Y - dialog.Y;
                    defaultButtonRectangle.Width  = defaultButton.Width - defaultButton.X;
                    defaultButtonRectangle.Height = defaultButton.Height - defaultButton.Y;

                    // Ignor the comparison of a 4-pixel width border so that we could
                    // get rid of the side effect of dash-line rectangle on the button.
                    Rectangle defaultButtonRectangleEx = new Rectangle();
                    defaultButtonRectangleEx.X      = defaultButtonRectangle.X + 4;
                    defaultButtonRectangleEx.Y      = defaultButtonRectangle.Y + 4;
                    defaultButtonRectangleEx.Width  = defaultButtonRectangle.Width - 8;
                    defaultButtonRectangleEx.Height = defaultButtonRectangle.Height - 8;
                    //Ignor the effect of flatness under vista
                    Rectangle flatnessRectangle1 = new Rectangle();
                    flatnessRectangle1.X      = 0;
                    flatnessRectangle1.Y      = 0;
                    flatnessRectangle1.Width  = 6;
                    flatnessRectangle1.Height = 6;
                    Rectangle flatnessRectangle2 = new Rectangle();
                    flatnessRectangle2.X      = dialog.Width - dialog.X - 6;
                    flatnessRectangle2.Y      = 0;
                    flatnessRectangle2.Width  = 6;
                    flatnessRectangle2.Height = 6;
                    Rectangle[] FlatnessAreas = new Rectangle[2];
                    FlatnessAreas[0] = flatnessRectangle1;
                    FlatnessAreas[1] = flatnessRectangle2;
                    Bitmap difference = new Bitmap(base_width, base_height);
                    bool   bChange = false;
                    int    i, j;
                    Color  pixBase;
                    Color  pixTest;
                    for (i = 0; i < base_width; i++)
                    {
                        for (j = 0; j < base_height; j++)
                        {
                            pixBase = bmBase.GetPixel(i, j);
                            pixTest = bmTest.GetPixel(i, j);
                            Point temp = new Point(i, j);
                            if (IsContainsPoint(FlatnessAreas, temp))
                            {
                                //difference.SetPixel(i, j, Color.White);
                                continue;
                            }
                            if (IsContainsPoint(NotCompare, temp))
                            {
                                //difference.SetPixel(i, j, Color.White);
                                continue;
                            }
                            if (!defaultButtonRectangle.Contains(temp))
                            {
                                if (!colorComparer.Compare(pixBase, pixTest))
                                {
                                    bChange = true;
                                    difference.SetPixel(i, j, Color.Black);
                                }
                                else
                                {
                                    difference.SetPixel(i, j, Color.White);
                                }
                            }
                            else if (!defaultButtonRectangleEx.Contains(temp))
                            {
                                // Ignor the pixels in this border.
                                //difference.SetPixel(i, j, Color.Orange);
                            }
                            else //Process the pixels in OK button rectangle
                            {
                                if (!colorComparer.Compare(pixBase, pixTest))
                                {
                                    int defaultBuffer = SUIColorComparer.buffer;
                                    //Temproraly set buffer to 150 since in this special area we need a larger buffer.
                                    SUIColorComparer.buffer = 150;
                                    if (colorComparer.Compare(pixBase, SystemColors.ControlText) || colorComparer.Compare(pixTest, SystemColors.ControlText))
                                    {
                                        bChange = true;
                                        difference.SetPixel(i, j, Color.Black);
                                    }
                                    //else
                                    //    difference.SetPixel(i, j, Color.Blue);
                                    // Set the default buffer back.
                                    SUIColorComparer.buffer = defaultBuffer;
                                }
                                //else
                                //    difference.SetPixel(i, j, Color.Red);
                            }
                        }
                    }

                    if (bChange)
                    {
                        windowImage.Path = baseImage.Path.Replace(".bmp", "_error.bmp");
                        windowImage.Save();
                        windowImage.ReleaseMem();
                        string path = baseImage.Path.Replace(".bmp", "_error_difference.bmp");
                        difference.Save(path);
                        return(false);
                    }
                    return(true);
                }
            }
            else
            {
                SUIImageComparer imgComparer = new SUIImageComparer();
                return(imgComparer.OptionCompare3(baseImage, windowImage, NotCompare));
            }
        }