示例#1
0
        public void CreateBaseline()
        {
            VisualElementsInfo VEI = mDriver.GetVisualElementsInfo();

            if (string.IsNullOrEmpty(mAct.BaselineInfoFile))
            {
                // Create default file name for info file
                mAct.BaselineInfoFile = @"~\Documents\ScreenShots\" + mAct.Description + " - Baseline.txt";
            }
            string filename = mAct.GetFullFilePath(mAct.BaselineInfoFile);

            VEI.Save(filename);
        }
示例#2
0
        //constructor which load the data from file
        public static VisualElementsInfo Load(string FileName)
        {
            if (mJsonSerializer == null)
            {
                initJSon();
            }

            using (StreamReader SR = new StreamReader(FileName))
                using (JsonReader reader = new JsonTextReader(SR))
                {
                    VisualElementsInfo VEI = (VisualElementsInfo)mJsonSerializer.Deserialize(reader, typeof(VisualElementsInfo));
                    return(VEI);
                }
        }
示例#3
0
        void IVisualAnalyzer.Compare()
        {
            //TODO: use interface on the driver to get elements
            if (mDriver is IVisualTestingDriver)
            {
                IVisualTestingDriver d = (IVisualTestingDriver)mDriver;

                string             filename = mAct.GetFullFilePath(mAct.BaselineInfoFile);
                VisualElementsInfo VE1      = VisualElementsInfo.Load(filename);
                VE1.Bitmap = mAct.baseImage;

                VisualElementsInfo VE2 = d.GetVisualElementsInfo();
                VE1.Compare(VE2);
                IEnumerable <VisualElement> listwithnomatch = from x in VE1.Elements where x.Text != "" && x.MatchingElement == null select x;

                // Create compare bitmap for VE1
                Bitmap bmp = new Bitmap(VE1.Bitmap);
                // mark element with no match
                foreach (VisualElement VE in listwithnomatch)
                {
                    using (Graphics gr = Graphics.FromImage(bmp))
                    {
                        gr.SmoothingMode = SmoothingMode.AntiAlias;

                        //TODO: check the -3 or + 6 will not go out of bitmap
                        Rectangle rect = new Rectangle(VE.X - 3, VE.Y - 3, VE.Width + 6, VE.Height + 6);

                        gr.FillRectangle(Brushes.Transparent, rect);
                        using (Pen thick_pen = new Pen(Color.HotPink, 2))
                        {
                            gr.DrawRectangle(thick_pen, rect);
                        }
                    }
                }

                mAct.CompareResult = bmp;

                // Add output of mismatch
                mAct.AddOrUpdateReturnParamActual("Mismatch elements in target", listwithnomatch.Count() + "");

                //TODO: if output each mismatch then do output


                mAct.AddScreenShot(bmp, "Compare Result");

                //TODO: add small bitmap of mismatch elem
            }
        }
示例#4
0
        public void Compare(VisualElementsInfo VEI)
        {
            // we try to match elem by tag and text
            // Each elem found we mark it
            foreach (VisualElement VE in Elements)
            {
                // Make sure we are in allowed offset
                //TODO: add to config
                int offset = 100;  // up to +/- 100 pixels move is allowed

                VisualElement VE1 = (from x in VEI.Elements where
                                     x.ElementType == VE.ElementType &&
                                     x.Text == VE.Text &&
                                     (Math.Abs(x.X - VE.X) < offset) &&
                                     Math.Abs(x.Y - VE.Y) < offset
                                     select x
                                     ).FirstOrDefault();
                if (VE1 != null)
                {
                    if (!string.IsNullOrEmpty(VE1.Text))
                    {
                        if (VE1.MatchingElement != null) // there is already a match
                        {
                            //TODO: handle match more than once
                        }
                        else
                        {
                            // We found matching element create the connection at both sides
                            VE.MatchingElement  = VE1;
                            VE1.MatchingElement = VE;
                        }
                    }
                }
            }
            //TODO: use it when we want to create the piece of the emep in seperate bitmap - for comapre
        }