Esempio n. 1
0
        public WebElementCreateEditDialog(Func <WebElementInfoViewModel, string> validate,
                                          CombinedWebElementInfoViewModel parent,
                                          string elementType,
                                          WebElementInfoViewModel baseInfo)
        {
            _validate  = validate;
            IsEditMode = false;

            Title      = $"Create new WebElement with type: {elementType}";
            WebElement = WebElementsViewModelsHelper.CreateModelFromWebElementType(elementType);

            if (baseInfo != null)
            {
                WebElementsViewModelsHelper.FillModelWithBaseInfo(WebElement, baseInfo, true);
            }

            if (WebElement.InnerKey != null)
            {
                Title = $"Specify new WebElement with role {WebElement.InnerKey}";
            }
            WebElement.Parent = parent;

            InitializeComponent();

            DataContext = this;
        }
        private WebElementInfoViewModel CreateReference()
        {
            var blockedTypesToPick = WebElementsViewModelsHelper.GetBlockedElementTypesForElementType(_elementType);

            var picker = new WebElementPickerDialog(_webElementsTreeUserControl.WebElements.ToList(),
                                                    false,
                                                    null,
                                                    null,
                                                    blockedTypesToPick);

            if (picker.ShowDialog() != true)
            {
                return(null);
            }
            var referenceTreePath = picker.SelectedWebElementTreePath;
            var referencedElement = (WebElementInfoViewModel)_webElementsTreeUserControl.WebElements.FindNodeByTreePath(referenceTreePath);
            var referenceCopy     = WebElementsViewModelsHelper.CreateFullModelCopy(referencedElement);

            var templateInfo = WebElementsViewModelsHelper.CreateModelFromWebElementType(WebElementTypes.Reference)
                               as WebElementWithReferenceViewModel;

            WebElementsViewModelsHelper.FillModelWithBaseInfo(templateInfo, referencedElement);
            templateInfo.Locator              = null;
            templateInfo.ElementType          = WebElementTypes.Reference;
            templateInfo.ReferenceBreadString = referenceTreePath;
            templateInfo.ReferencedWebElement = referenceCopy;

            var createdElement = CreateWebElementInfo(null, templateInfo) as WebElementWithReferenceViewModel;

            if (createdElement == null)
            {
                return(null);
            }

            createdElement.ReferencedWebElement = referenceCopy;
            if (createdElement.Elements == null)
            {
                createdElement.Elements = new ObservableCollection <WebElementInfoViewModel>();
            }
            referenceCopy.Parent = createdElement;

            return(createdElement);
        }
Esempio n. 3
0
        private void AcceptMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var validationResult = _validate?.Invoke(WebElement);

            if (!string.IsNullOrWhiteSpace(validationResult))
            {
                MessageBox.Show(validationResult, "WebElement data is not valid", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            if (IsEditMode)
            {
                WebElementsViewModelsHelper.FillModelWithBaseInfo(SourceWebElement, WebElement);
                WebElementsViewModelsHelper.UpdateAllReferences(WebElements, SourceWebElement);
                WebElement = SourceWebElement;
            }

            SourceWebElement = null;
            DialogResult     = true;
            Close();
        }
        private WebElementInfoViewModel CreateWebElementInfo(CombinedWebElementInfoViewModel parent = null, WebElementInfoViewModel template = null)
        {
            var validator = WebElementCommandsHelper.GetCreateUpdateWebElementValidator(_webElementsTreeUserControl, null);

            //TODO: add ctor override to accept WebElementInfoViewModel with default data
            var dialog = new WebElementCreateEditDialog(validator,
                                                        parent ?? Selected as CombinedWebElementInfoViewModel,
                                                        _elementType,
                                                        template);

            dialog.WebElements = _webElementsTreeUserControl.WebElements;
            if (dialog.ShowDialog() != true)
            {
                return(null);
            }

            var createdWebElement = WebElementsViewModelsHelper.CreateModelFromWebElementType(_elementType);

            WebElementsViewModelsHelper.FillModelWithBaseInfo(
                createdWebElement,
                dialog.WebElement);

            return(createdWebElement);
        }
        private void EditReferencedElementButton_Click(object sender, RoutedEventArgs e)
        {
            if (WebElements == null ||
                !(WebElement is WebElementWithReferenceViewModel rm))
            {
                MessageBox.Show("Edit operaion is not supported. WebElements source is not specified or element doesn't support references");
                return;
            }

            var blockedTreePath = new List <string>();

            var curParent = WebElement;

            while (!(curParent?.Parent == null ||
                     curParent.Parent.ElementType == WebElementTypes.Directory))
            {
                curParent = curParent.Parent;
            }

            blockedTreePath.Clear();
            blockedTreePath.Add(curParent.GetTreePath());

            var picker = new WebElementPickerDialog(WebElements.ToList(),
                                                    WebElement.ElementType == WebElementTypes.Frame,
                                                    rm.ReferenceBreadString,
                                                    blockedTreePath,
                                                    WebElementsViewModelsHelper.GetBlockedElementTypesForElementType(rm.ElementType)
                                                    );

            if (picker.ShowDialog() != true)
            {
                return;
            }

            if (rm.ReferenceBreadString == picker.SelectedWebElementTreePath)
            {
                return;
            }

            rm.ReferenceBreadString = picker.SelectedWebElementTreePath;

            var r    = (WebElementInfoViewModel)WebElements.FindNodeByTreePath(rm.ReferenceBreadString);
            var copy = WebElementsViewModelsHelper.CreateFullModelCopy(r);

            if (rm.ElementType == WebElementTypes.Reference)
            {
                var baseInfo = new WebElementInfoViewModel
                {
                    Name        = copy.Name,
                    Description = copy.Description,
                    Tags        = copy.Tags,
                    ElementType = null,
                    Locator     = null,
                    InnerKey    = null,
                };

                WebElementsViewModelsHelper.FillModelWithBaseInfo(rm, baseInfo, true);
            }

            rm.Elements?.Clear();
            if (rm.Elements == null)
            {
                rm.Elements = new ObservableCollection <WebElementInfoViewModel>();
            }

            if (rm.ElementType == WebElementTypes.Reference)
            {
                if (copy is CombinedWebElementInfoViewModel combinedRef)
                {
                    if (combinedRef.Elements != null)
                    {
                        foreach (var c in combinedRef.Elements)
                        {
                            rm.Elements.Add(c);
                            c.Parent = rm;
                        }
                    }
                }
            }
            else
            {
                if (rm.ReferencedWebElement != null)
                {
                    rm.ReferencedWebElement.Parent = null;
                    rm.ReferencedWebElement        = null;
                }

                rm.Elements.Add(copy);
            }

            rm.ReferencedWebElement = copy;
            copy.Parent             = rm;
            rm.HasLocator           = false;

            WebElement = WebElementsViewModelsHelper.CreateFullModelCopy(rm);
            UpdateLayout();
            WebElement = rm;
        }