Beispiel #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;
        }
Beispiel #2
0
        public static bool CanBeCut(WebElementInfoViewModel el)
        {
            if (el == null)
            {
                return(false);
            }
            if (WebElementsViewModelsHelper.IsAnyParentReference(el))
            {
                return(false);
            }
            if (el.Parent == null)
            {
                return(true);
            }
            if (el.Parent.ElementType == WebElementTypes.DropDown || el.Parent.ElementType == WebElementTypes.RadioGroup)
            {
                return(false);
            }
            if (el.Parent.ElementType == WebElementTypes.Control ||
                el.Parent.ElementType == WebElementTypes.Context ||
                el.Parent.ElementType == WebElementTypes.Page ||
                el.Parent.ElementType == WebElementTypes.Directory)
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
 public static bool CanElementHasCustomChildren(WebElementInfoViewModel elementInfo)
 {
     return
         (elementInfo == null ||
          (elementInfo is CombinedWebElementInfoViewModel &&
           !(elementInfo.ElementType == WebElementTypes.DropDown ||
             elementInfo.ElementType == WebElementTypes.RadioGroup ||
             elementInfo.ElementType == WebElementTypes.Reference ||
             elementInfo.ElementType == WebElementTypes.Frame)));
 }
        private WebElementWithReferenceViewModel GetReferencedParent(WebElementInfoViewModel model)
        {
            var parent = model?.Parent;

            while (parent != null)
            {
                if (parent is WebElementWithReferenceViewModel r)
                {
                    return(r);
                }
                parent = parent.Parent;
            }
            return(null);
        }
Beispiel #5
0
        public static List <string> GetExistedNamesForChildWebElements(WebElementInfoViewModel el,
                                                                       WebElementsTreeUserControl webElementsTreeUserControl,
                                                                       string originalName)
        {
            List <string> existedNames = el.Parent == null
                ? webElementsTreeUserControl.WebElements?.Select(c => c.Name).ToList()
                : el.Parent.Elements?.Select(e => e.Name).ToList();

            if (originalName != null)
            {
                existedNames.Remove(originalName);
            }

            return(existedNames);
        }
        private static void ExpandElementTree(WebElementInfoViewModel model, ItemsControl control)
        {
            var stack = new Stack <WebElementInfoViewModel>();
            var p     = model.Parent;

            while (p != null)
            {
                stack.Push(p);
                p = p.Parent;
            }

            while (stack.Count != 0)
            {
                var el = stack.Pop();
                ExpandElementTreeItem(el, control);
            }
        }
Beispiel #7
0
        public static bool VerifyName(WebElementInfoViewModel el,
                                      WebElementsTreeUserControl webElementsTreeUserControl,
                                      string originalName,
                                      out string error)
        {
            error = null;

            var existedNames = GetExistedNamesForChildWebElements(
                el,
                webElementsTreeUserControl,
                originalName);

            if (existedNames.Contains(el.Name))
            {
                error = $"WebElement with name: {el.Name} already exists on the level";
                return(false);
            }
            return(true);
        }
Beispiel #8
0
        public WebElementCreateEditDialog(Func <WebElementInfoViewModel, string> validate, WebElementInfoViewModel webElement)
        {
            _validate = validate;

            if (webElement == null)
            {
                throw new ArgumentNullException(nameof(webElement));
            }

            IsEditMode        = true;
            Title             = $"Edit WebElement: {webElement.Name}";
            SourceWebElement  = webElement;
            WebElement        = WebElementsViewModelsHelper.CreateModelCopyWithBaseInfo(webElement);
            WebElement.Parent = webElement.Parent;

            InitializeComponent();

            DataContext = this;
        }
Beispiel #9
0
        public static bool CanBeCloned(WebElementInfoViewModel el)
        {
            if (el == null)
            {
                return(false);
            }
            if (WebElementsViewModelsHelper.IsAnyParentReference(el))
            {
                return(false);
            }
            if (el.Parent == null)
            {
                return(false);
            }
            if (el.Parent.ElementType == WebElementTypes.DropDown || el.Parent.ElementType == WebElementTypes.RadioGroup)
            {
                return(false);
            }

            return(true);
        }
        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;
        }
        protected override void ExecuteCommand()
        {
            WebElementInfoViewModel createdElement = null;

            if (_elementType == WebElementTypes.Reference)
            {
                createdElement = CreateReference();
                if (createdElement == null)
                {
                    return;
                }
            }
            else
            {
                createdElement = CreateWebElementInfo();

                if (createdElement == null)
                {
                    return;
                }

                if (_elementType == WebElementTypes.DropDown ||
                    _elementType == WebElementTypes.RadioGroup)
                {
                    var combinedCreatedElement = createdElement as CombinedWebElementInfoViewModel;

                    if (combinedCreatedElement.Elements == null)
                    {
                        combinedCreatedElement.Elements = new ObservableCollection <WebElementInfoViewModel>();
                    }

                    if (_elementType == WebElementTypes.DropDown)
                    {
                        var inputTemplate = new WebElementInfoViewModel
                        {
                            Name        = $"{createdElement.Name} Input",
                            Description = $"Input for {createdElement.Name}",
                            InnerKey    = DropDownElementInfo.Keys.Input,
                            ElementType = WebElementTypes.Element,
                            IsKey       = true,
                            Locator     = new WebLocatorInfoViewModel
                            {
                                IsRelative   = true,
                                LocatorType  = WebLocatorType.XPath,
                                LocatorValue = ".//"
                            }
                        };

                        var inputElement = CreateWebElementInfo(
                            combinedCreatedElement,
                            inputTemplate);
                        if (inputElement == null)
                        {
                            return;
                        }

                        inputElement.Parent = combinedCreatedElement;
                        combinedCreatedElement.Elements.Add(inputElement);
                    }

                    var optionTemplate = new WebElementInfoViewModel
                    {
                        Name        = $"{createdElement.Name} Option",
                        Description = $"Option for {createdElement.Name}",
                        InnerKey    = _elementType == WebElementTypes.DropDown
                            ? DropDownElementInfo.Keys.Option
                            : RadioGroupElementInfo.Keys.Option,
                        ElementType = WebElementTypes.Element,
                        IsKey       = true,
                        Locator     = new WebLocatorInfoViewModel
                        {
                            IsRelative   = true,
                            LocatorType  = WebLocatorType.XPath,
                            LocatorValue = ".//"
                        }
                    };

                    var optionElement = CreateWebElementInfo(
                        combinedCreatedElement,
                        optionTemplate);
                    if (optionElement == null)
                    {
                        return;
                    }

                    optionElement.Parent = combinedCreatedElement;
                    combinedCreatedElement.Elements.Add(optionElement);
                }

                if (_elementType == WebElementTypes.Frame)
                {
                    var frameElement      = createdElement as WebElementWithReferenceViewModel;
                    var referenceTreePath = frameElement.ReferenceBreadString;
                    if (referenceTreePath == null)
                    {
                        var blockedTypesToPick = WebElementsViewModelsHelper.GetBlockedElementTypesForElementType(_elementType);

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


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

                    var referencedElement = (WebElementInfoViewModel)_webElementsTreeUserControl.WebElements.FindNodeByTreePath(referenceTreePath);

                    var copy = WebElementsViewModelsHelper.CreateFullModelCopy(referencedElement);
                    copy.Parent = frameElement;
                    if (frameElement.Elements == null)
                    {
                        frameElement.Elements = new ObservableCollection <WebElementInfoViewModel>();
                    }
                    frameElement.Elements.Clear();
                    frameElement.Elements.Add(copy);
                }
            }
            if (createdElement == null)
            {
                return;
            }

            if (Selected == null)
            {
                if (_webElementsTreeUserControl.WebElements == null)
                {
                    _webElementsTreeUserControl.WebElements = new ObservableCollection <CombinedWebElementInfoViewModel>();
                }
                _webElementsTreeUserControl.WebElements.Add(createdElement as CombinedWebElementInfoViewModel);
            }
            else
            {
                var comb = Selected as CombinedWebElementInfoViewModel;
                if (comb == null)
                {
                    MessageBox.Show("Magic error. WebElement was created not from CombinedWebElement");
                    return;
                }

                if (comb.Elements == null)
                {
                    comb.Elements = new ObservableCollection <WebElementInfoViewModel>();
                }

                comb.Elements.Add(createdElement);
                createdElement.Parent = comb;
            }

            return;
        }
        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 static void ExpandElementTreeItem(WebElementInfoViewModel model, ItemsControl control)
        {
            var tvi = SaKiWpfHelper.FindTreeViewItemForObject(control, model);

            tvi?.SetValue(TreeViewItem.IsExpandedProperty, true);
        }
Beispiel #14
0
        protected override void ExecuteCommand()
        {
            if (!CanExecute(null))
            {
                return;
            }

            WebElementInfoViewModel model = Cut;

            var combined = Selected as CombinedWebElementInfoViewModel;

            if (combined == null && Selected != null)
            {
                MessageBox.Show("Magic!!! Try to paste to not combined element!");
                return;
            }

            if (combined != null)
            {
                if (combined.Elements == null)
                {
                    combined.Elements = new ObservableCollection <WebElementInfoViewModel>();
                }
            }

            if (Copied != null)
            {
                var info = WebElementsViewModelsHelper.CreateInfoFromModel(Copied);
                model = WebElementsViewModelsHelper.CreateModelFromInfo(info);
            }
            else
            {
                if (model.Parent != null)
                {
                    model.Parent.Elements.Remove(model);
                }
                else
                {
                    _webElementsTreeUserControl.WebElements.Remove(model as CombinedWebElementInfoViewModel);
                }
            }

            model.Parent = combined;

            if (combined != null)
            {
                combined.Elements.Add(model);
            }
            else
            {
                var cmb = model as CombinedWebElementInfoViewModel;
                if (cmb == null)
                {
                    MessageBox.Show("Magic!!! Try to paste not combined element to Root!");
                    return;
                }
                _webElementsTreeUserControl.WebElements.Add(cmb);
            }

            _webElementsTreeUserControl.SelectedWebElement = model;
        }