Ejemplo 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);
        }
        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);
        }