コード例 #1
0
ファイル: PomDeltaUtils.cs プロジェクト: svendster/Ginger
        private DeltaElementInfo ConvertElementToDelta(ElementInfo elementInfo, eDeltaStatus deltaStatus, object group, bool isSelected, string deltaExtraDetails)
        {
            //copy element and convert it to Delta
            DeltaElementInfo newDeltaElement = new DeltaElementInfo();

            newDeltaElement.ElementInfo = elementInfo;

            elementInfo.ElementStatus            = ElementInfo.eElementStatus.Unknown;
            newDeltaElement.DeltaStatus          = deltaStatus;
            newDeltaElement.DeltaExtraDetails    = deltaExtraDetails;
            newDeltaElement.SelectedElementGroup = group;
            newDeltaElement.IsSelected           = isSelected;
            foreach (ElementLocator locator in elementInfo.Locators)
            {
                DeltaElementLocator deltaLocator = new DeltaElementLocator();
                deltaLocator.ElementLocator = locator;
                deltaLocator.ElementLocator.LocateStatus = ElementLocator.eLocateStatus.Unknown;
                deltaLocator.DeltaStatus = deltaStatus;
                newDeltaElement.Locators.Add(deltaLocator);
            }
            foreach (ControlProperty propery in elementInfo.Properties)
            {
                DeltaControlProperty deltaPropery = new DeltaControlProperty();
                deltaPropery.ElementProperty = propery;
                deltaPropery.DeltaStatus     = deltaStatus;
                newDeltaElement.Properties.Add(deltaPropery);
            }
            return(newDeltaElement);
        }
コード例 #2
0
ファイル: PomDeltaUtils.cs プロジェクト: svendster/Ginger
        private void SetMatchingElementDeltaDetails(ElementInfo existingElement, ElementInfo latestElement)
        {
            DeltaElementInfo matchedDeltaElement = new DeltaElementInfo();

            //copy possible customized fields from original
            latestElement.Guid         = existingElement.Guid;
            latestElement.ElementName  = existingElement.ElementName;
            latestElement.Description  = existingElement.Description;
            latestElement.ElementGroup = existingElement.ElementGroup;
            if (existingElement.OptionalValuesObjectsList.Count > 0 && latestElement.OptionalValuesObjectsList.Count == 0)
            {
                latestElement.OptionalValuesObjectsList = existingElement.OptionalValuesObjectsList;
            }
            matchedDeltaElement.ElementInfo = latestElement;
            ////////------------------ Delta Locators
            foreach (ElementLocator latestLocator in latestElement.Locators)
            {
                latestLocator.LocateStatus = ElementLocator.eLocateStatus.Unknown;
                DeltaElementLocator deltaLocator = new DeltaElementLocator();
                latestLocator.LocateStatus  = ElementLocator.eLocateStatus.Unknown;
                deltaLocator.ElementLocator = latestLocator;
                ElementLocator matchingExistingLocator = existingElement.Locators.Where(x => x.LocateBy == latestLocator.LocateBy).FirstOrDefault();
                if (matchingExistingLocator != null)
                {
                    latestLocator.Guid = matchingExistingLocator.Guid;
                    if (matchingExistingLocator.LocateBy == eLocateBy.ByXPath)
                    {
                        //fiting previous learned Xpath to latest structure to avoid false change indication
                        if (matchingExistingLocator.LocateValue.StartsWith("/") == false)
                        {
                            string   updatedXpath = string.Empty;
                            string[] xpathVals    = matchingExistingLocator.LocateValue.Split(new char[] { '/' });
                            for (int indx = 0; indx < xpathVals.Count(); indx++)
                            {
                                if (indx == 0)
                                {
                                    xpathVals[0] = xpathVals[0] + "[1]";
                                }
                                updatedXpath += "/" + xpathVals[indx];
                            }

                            matchingExistingLocator.LocateValue = updatedXpath;
                        }
                    }
                    //compare value
                    if ((string.IsNullOrWhiteSpace(matchingExistingLocator.LocateValue) == true && string.IsNullOrWhiteSpace(latestLocator.LocateValue) == true) ||
                        matchingExistingLocator.LocateValue.Equals(latestLocator.LocateValue, StringComparison.OrdinalIgnoreCase))   //Unchanged
                    {
                        deltaLocator.DeltaStatus = eDeltaStatus.Unchanged;
                    }
                    else//Changed
                    {
                        deltaLocator.DeltaStatus       = eDeltaStatus.Changed;
                        deltaLocator.DeltaExtraDetails = string.Format("Previous value was: '{0}'", matchingExistingLocator.LocateValue);
                    }
                }
                else//new locator
                {
                    deltaLocator.DeltaStatus = eDeltaStatus.Added;
                }
                matchedDeltaElement.Locators.Add(deltaLocator);
            }
            //not Learned Locators
            List <ElementLocator> notLearnedLocators = existingElement.Locators.Where(x => latestElement.Locators.Where(y => y.Guid == x.Guid).FirstOrDefault() == null).ToList();

            foreach (ElementLocator notLearedLocator in notLearnedLocators)
            {
                DeltaElementLocator deltaLocator = new DeltaElementLocator();
                notLearedLocator.LocateStatus = ElementLocator.eLocateStatus.Unknown;
                deltaLocator.ElementLocator   = notLearedLocator;
                if (notLearedLocator.IsAutoLearned == true)//deleted
                {
                    deltaLocator.DeltaStatus       = eDeltaStatus.Deleted;
                    deltaLocator.DeltaExtraDetails = "Locator not exist on latest";
                }
                else//customized locator so avoid it
                {
                    deltaLocator.DeltaStatus       = eDeltaStatus.Avoided;
                    deltaLocator.DeltaExtraDetails = "Customized locator not exist on latest";
                    if (KeepOriginalLocatorsOrderAndActivation == true)
                    {
                        latestElement.Locators.Add(notLearedLocator);
                    }
                }
                matchedDeltaElement.Locators.Add(deltaLocator);
            }
            if (KeepOriginalLocatorsOrderAndActivation == true)
            {
                foreach (ElementLocator originalLocator in existingElement.Locators)
                {
                    ElementLocator latestLocator = latestElement.Locators.Where(x => x.Guid == originalLocator.Guid).FirstOrDefault();

                    if (latestLocator != null)
                    {
                        latestLocator.Active = originalLocator.Active;
                        int originalIndex = existingElement.Locators.IndexOf(originalLocator);
                        if (originalIndex <= latestElement.Locators.Count)
                        {
                            latestElement.Locators.Move(latestElement.Locators.IndexOf(latestLocator), originalIndex);
                            matchedDeltaElement.Locators.Move(matchedDeltaElement.Locators.IndexOf(matchedDeltaElement.Locators.Where(x => x.ElementLocator == latestLocator).First()), originalIndex);
                        }
                    }
                }
            }

            ////////--------------- Properties
            foreach (ControlProperty latestProperty in latestElement.Properties)
            {
                DeltaControlProperty deltaProperty            = new DeltaControlProperty();
                ControlProperty      matchingExistingProperty = existingElement.Properties.Where(x => x.Name == latestProperty.Name).FirstOrDefault();
                if (matchingExistingProperty != null)
                {
                    latestProperty.Guid           = matchingExistingProperty.Guid;
                    deltaProperty.ElementProperty = latestProperty;
                    if ((string.IsNullOrWhiteSpace(matchingExistingProperty.Value) == true && string.IsNullOrWhiteSpace(latestProperty.Value) == true) ||
                        (matchingExistingProperty.Value != null && matchingExistingProperty.Value.Equals(latestProperty.Value, StringComparison.OrdinalIgnoreCase)))    //Unchanged
                    {
                        deltaProperty.DeltaStatus = eDeltaStatus.Unchanged;
                    }
                    else//Changed
                    {
                        if (PropertiesChangesToAvoid == DeltaControlProperty.ePropertiesChangesToAvoid.None ||
                            (PropertiesChangesToAvoid == DeltaControlProperty.ePropertiesChangesToAvoid.OnlySizeAndLocationProperties && mVisualPropertiesList.Contains(deltaProperty.Name) == false))
                        {
                            deltaProperty.DeltaStatus       = eDeltaStatus.Changed;
                            deltaProperty.DeltaExtraDetails = string.Format("Previous value was: '{0}'", matchingExistingProperty.Value);
                        }
                        else
                        {
                            deltaProperty.DeltaStatus       = eDeltaStatus.Avoided;
                            deltaProperty.DeltaExtraDetails = string.Format("Previous value was: '{0}' but change was avoided", matchingExistingProperty.Value);
                        }
                    }
                }
                else//new Property
                {
                    deltaProperty.ElementProperty = latestProperty;
                    if (string.IsNullOrWhiteSpace(latestProperty.Value) == false)
                    {
                        deltaProperty.DeltaStatus = eDeltaStatus.Added;
                    }
                    else
                    {
                        deltaProperty.DeltaStatus       = eDeltaStatus.Avoided;
                        deltaProperty.DeltaExtraDetails = "New property but value is empty so it was avoided";
                    }
                }
                matchedDeltaElement.Properties.Add(deltaProperty);
            }
            //deleted Properties
            List <ControlProperty> deletedProperties = existingElement.Properties.Where(x => latestElement.Properties.Where(y => y.Name == x.Name).FirstOrDefault() == null).ToList();

            foreach (ControlProperty deletedProperty in deletedProperties)
            {
                DeltaControlProperty deltaProp = new DeltaControlProperty();
                deltaProp.ElementProperty = deletedProperty;
                if (PropertiesChangesToAvoid == DeltaControlProperty.ePropertiesChangesToAvoid.None ||
                    (PropertiesChangesToAvoid == DeltaControlProperty.ePropertiesChangesToAvoid.OnlySizeAndLocationProperties && mVisualPropertiesList.Contains(deletedProperty.Name) == false))
                {
                    deltaProp.DeltaStatus       = eDeltaStatus.Deleted;
                    deltaProp.DeltaExtraDetails = "Property not exist on latest";
                }
                else
                {
                    deltaProp.DeltaStatus       = eDeltaStatus.Avoided;
                    deltaProp.DeltaExtraDetails = "Property not exist on latest but avoided";
                }
                matchedDeltaElement.Properties.Add(deltaProp);
            }

            //------------ General Status set
            List <DeltaElementLocator>  modifiedLocatorsList   = matchedDeltaElement.Locators.Where(x => x.DeltaStatus == eDeltaStatus.Changed || x.DeltaStatus == eDeltaStatus.Deleted).ToList();
            List <DeltaControlProperty> modifiedPropertiesList = matchedDeltaElement.Properties.Where(x => x.DeltaStatus == eDeltaStatus.Changed || x.DeltaStatus == eDeltaStatus.Deleted).ToList();

            if (modifiedLocatorsList.Count > 0 || modifiedPropertiesList.Count > 0)
            {
                matchedDeltaElement.DeltaStatus = eDeltaStatus.Changed;
                matchedDeltaElement.IsSelected  = true;
                if (modifiedLocatorsList.Count > 0 && modifiedPropertiesList.Count > 0)
                {
                    matchedDeltaElement.DeltaExtraDetails = "Locators & Properties changed";
                }
                else if (modifiedLocatorsList.Count > 0)
                {
                    matchedDeltaElement.DeltaExtraDetails = "Locators changed";
                }
                else if (modifiedPropertiesList.Count > 0)
                {
                    matchedDeltaElement.DeltaExtraDetails = "Properties changed";
                }
            }
            else
            {
                matchedDeltaElement.DeltaStatus = eDeltaStatus.Unchanged;
                matchedDeltaElement.IsSelected  = false;
                List <DeltaElementLocator>  minorLocatorsChangesList   = matchedDeltaElement.Locators.Where(x => x.DeltaStatus == eDeltaStatus.Avoided || x.DeltaStatus == eDeltaStatus.Added || x.DeltaStatus == eDeltaStatus.Unknown).ToList();
                List <DeltaControlProperty> minorPropertiesChangesList = matchedDeltaElement.Properties.Where(x => x.DeltaStatus == eDeltaStatus.Avoided || x.DeltaStatus == eDeltaStatus.Added || x.DeltaStatus == eDeltaStatus.Unknown).ToList();
                if (minorLocatorsChangesList.Count > 0 || minorPropertiesChangesList.Count > 0)
                {
                    matchedDeltaElement.DeltaExtraDetails = "Unimportant differences exists";
                }
            }

            DeltaViewElements.Add(matchedDeltaElement);
        }
コード例 #3
0
 public static bool Compare(ElementLocator A, DeltaElementLocator B)
 {
     return(A.LocateBy == B.LocateBy && A.LocateValue == B.LocateValue);
 }