Ejemplo n.º 1
0
        public WebElementDefinition GetWebElementDefinitionFromForm()
        {
            var element = new WebElementDefinition()
            {
                Name        = txtWebElementName.Text,
                HtmlId      = txtHtmlId.Text,
                CssSelector = txtCssSelector.Text,
                Xpath       = txtXPath.Text,
                HowToSearch = GetLocatorSearchMethod(),
                Locator     = GetLocatorText(),

                ReturnsCollection = chkReturnsListOfWebElements.Checked,

                // Properties
                HtmlTag = txtPropHtmlTag.Text,
                AllHtmlTagProperties = txtAllElementHtmlProps.Tag != null
                                       ? txtAllElementHtmlProps.Tag as WebElementHtmlAttributes
                                       : new WebElementHtmlAttributes(),

                // Custom Args
                Arg1 = txtPropArg1.Text,
                Arg2 = txtPropArg2.Text,
                Arg3 = txtPropArg3.Text,
            };

            return(element);
        }
Ejemplo n.º 2
0
        internal void UpdatePageDefinition(WebElementDefinition element, bool forceAddNew)
        {

            var results = new List<ValidationResult>();
            var context = new ValidationContext(element, null, null);

            bool isValid = Validator.TryValidateObject(element, context, results, true);
            if (!isValid)
            {
                var validationMessage = String.Join("\n", results.Select(t => String.Format("- {0}", t.ErrorMessage)));
                view.DisplayMessage("Validation Error", validationMessage);
                return;
            }

            if (forceAddNew)
            {
                view.AddToPageDefinitions(element);
                NotifyOnChanges();
                return;
            }

            if (_isEditingExistingNode)
            {
                view.UpdateExistingPageDefinition(_currentEditingNode, element);
                NotifyOnChanges();
            }
            else
            {
                _isEditingExistingNode = true;
                _currentEditingNode = view.AddToPageDefinitions(element);
                NotifyOnChanges();
            }
        }
Ejemplo n.º 3
0
        public void ProcessCommands()
        {
            var command = SwdBrowser.GetNextCommand();

            if (command is GetXPathFromElement)
            {
                var getXPathCommand = command as GetXPathFromElement;
                view.UpdateVisualSearchResult(getXPathCommand.XPathValue);
            }
            else if (command is AddElement)
            {
                var addElementCommand = command as AddElement;

                SimpleFrame      simpleFrame;
                BrowserPageFrame browserPageFrame = view.getCurrentlyChosenFrame();
                if (browserPageFrame != null)
                {
                    List <string> childs = new List <string>();
                    string        parentTitle;
                    if (browserPageFrame.ParentFrame != null)
                    {
                        parentTitle = browserPageFrame.ParentFrame.GetTitle();
                    }
                    else
                    {
                        parentTitle = "none";
                    }
                    if (browserPageFrame.ChildFrames != null)
                    {
                        foreach (BrowserPageFrame b in browserPageFrame.ChildFrames)
                        {
                            childs.Add(b.GetTitle());
                        }
                    }

                    simpleFrame = new SimpleFrame(browserPageFrame.Index, browserPageFrame.LocatorNameOrId, browserPageFrame.GetTitle(), parentTitle, childs);
                }
                else
                {
                    simpleFrame = new SimpleFrame(-1, "noFrameChosen", "noFrameChosen", "noFrameChosen", null);
                }

                bool emptyHtmlId = String.IsNullOrEmpty(addElementCommand.ElementId);
                var  element     = new WebElementDefinition()
                {
                    Name        = addElementCommand.ElementCodeName,
                    HtmlId      = addElementCommand.ElementId,
                    Xpath       = addElementCommand.ElementXPath,
                    HowToSearch = (emptyHtmlId) ? LocatorSearchMethod.XPath: LocatorSearchMethod.Id,
                    Locator     = (emptyHtmlId) ? addElementCommand.ElementXPath: addElementCommand.ElementId,
                    CssSelector = addElementCommand.ElementCssSelector,
                    frame       = simpleFrame,
                };
                bool addNew = true;
                Presenters.SelectorsEditPresenter.UpdateWebElementWithAdditionalProperties(element);
                Presenters.PageObjectDefinitionPresenter.UpdatePageDefinition(element, addNew);
            }
        }
Ejemplo n.º 4
0
        internal void ShowPropertiesForNode(TreeNode treeNode)
        {
            WebElementDefinition element = (treeNode.Tag as WebElementDefinition);

            WebElementDefinition readOnlyElement = element.Clone();
            TypeDescriptor.AddAttributes(readOnlyElement, new Attribute[] { new ReadOnlyAttribute(true) });
            element = readOnlyElement;

        }
Ejemplo n.º 5
0
        internal void UpdateWebElementForm(WebElementDefinition formData)
        {
            ClearWebElementForm();
            txtWebElementName.Text = formData.Name;

            // Fill with the formData
            txtCssSelector.Text = formData.CssSelector;
            txtHtmlId.Text      = formData.HtmlId;
            txtXPath.Text       = formData.Xpath;


            switch (formData.HowToSearch)
            {
            case LocatorSearchMethod.Id:
                txtHtmlId.Text     = formData.Locator;
                rbtnHtmlId.Checked = true;
                break;

            case LocatorSearchMethod.CssSelector:
                txtCssSelector.Text     = formData.Locator;
                rbtnCssSelector.Checked = true;
                break;

            case LocatorSearchMethod.XPath:
                txtXPath.Text     = formData.Locator;
                rbtnXPath.Checked = true;
                break;

            default:
                string itemToSelect = "";
                switch (formData.HowToSearch)
                {
                case LocatorSearchMethod.Name: itemToSelect = otherLocator_Name; break;

                case LocatorSearchMethod.TagName: itemToSelect = otherLocator_TagName; break;

                case LocatorSearchMethod.ClassName: itemToSelect = otherLocator_ClassName; break;

                case LocatorSearchMethod.LinkText: itemToSelect = otherLocator_LinkText; break;

                case LocatorSearchMethod.PartialLinkText: itemToSelect = otherLocator_PartialLinkText; break;
                }
                if (!String.IsNullOrEmpty(itemToSelect))
                {
                    txtOtherLocator.Text          = formData.Locator;
                    rbtnOtherLocator.Checked      = true;
                    ddlOtherLocator.SelectedIndex = Array.IndexOf(otherLocatorListItems, itemToSelect);
                }
                break;
            }

            chkReturnsListOfWebElements.Checked = formData.ReturnsCollection;

            UpdateElementPropertiesForm(formData);
        }
        internal string[] Generate(WebElementDefinition[] definitions, string fullTemplatePath)
        {
            var template = File.ReadAllText(fullTemplatePath);
            var result = Razor.Parse(template,
                new {
                        WebElementDefinitions = definitions,

                    });

            return Utils.SplitSingleLineToMultyLine(result);
        }
Ejemplo n.º 7
0
        internal void HighLightWebElement(WebElementDefinition element)
        {
            if (!IsValidForm())
            {
                return;
            }

            var by = SwdBrowser.ConvertLocatorSearchMethodToBy(element.HowToSearch, element.Locator);

            SwdBrowser.HighlightElement(by);
        }
Ejemplo n.º 8
0
        internal void UpdateExistingPageDefinition(TreeNode existingNode, WebElementDefinition element)
        {
            var action = (MethodInvoker) delegate
            {
                existingNode.Text = element.ToString();
                existingNode.Tag  = element;
                existingNode.EnsureVisible();
            };

            if (tvWebElements.InvokeRequired)
            {
                tvWebElements.Invoke(action);
            }
            else
            {
                action();
            }
        }
Ejemplo n.º 9
0
        internal void UpdateElementPropertiesForm(WebElementDefinition sourceElement)
        {
            var element = sourceElement.Clone();

            txtPropHtmlTag.Text = element.HtmlTag;

            StringBuilder htmlProperties = new StringBuilder();

            foreach (KeyValuePair <string, string> item in element.AllHtmlTagProperties)
            {
                htmlProperties.AppendFormat("{0}=\"{1}\";", item.Key, item.Value);
            }

            txtAllElementHtmlProps.Text = htmlProperties.ToString();
            txtAllElementHtmlProps.Tag  = element.AllHtmlTagProperties;

            txtPropArg1.Text = element.Arg1 ?? "";
            txtPropArg2.Text = element.Arg2 ?? "";
            txtPropArg3.Text = element.Arg3 ?? "";
        }
 internal void removeElementFromObjectPage(WebElementDefinition element)
 {
     if (_isEditingExistingNode)
     {
         DialogResult dr = MessageBox.Show("Do you want to remove the element which is named as " + _currentEditingNode.Text + "?", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (dr == DialogResult.Yes)
         {
             view.DeleteExistingElementFromPage(_currentEditingNode);
             NotifyOnChanges();
         }
         else
         {
             return;
         }
     }
     else
     {
         MessageBox.Show("Can not remove if element hasn't been ever saved. ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Ejemplo n.º 11
0
        private IEnumerable <MethodAutocompleteItem> BuildMethodsListForWebElement(WebElementDefinition webElementDefinition)
        {
            IEnumerable <string> IWebElementMethods    = GetListOfMethods(typeof(IWebElement));
            IEnumerable <string> IWebElementProperties = GetListOfProperties(typeof(IWebElement));


            List <MethodAutocompleteItem> result = new List <MethodAutocompleteItem>();

            foreach (var propName in IWebElementProperties)
            {
                result.Add(new MethodAutocompleteItem(propName));
            }

            foreach (var methodName in IWebElementMethods)
            {
                result.Add(new MethodAutocompleteItem(methodName + "( );"));
            }

            return(result);
        }
Ejemplo n.º 12
0
        public void UpdateWebElementWithAdditionalProperties(WebElementDefinition element)
        {
            var by         = SwdBrowser.ConvertLocatorSearchMethodToBy(element.HowToSearch, element.Locator);
            var attributes = new Dictionary <string, string>();

            try
            {
                attributes = SwdBrowser.ReadElementAttributes(by);
            }
            catch (Exception e)
            {
                string errorMsg = string.Format(
                    "UpdateWebElementWithAdditionalProperties:\n" +
                    "Failed to find element: How={0};   Locator={1}\n" +
                    "With exception:\n {2}"
                    , element.HowToSearch.ToString()
                    , element.Locator.ToString()
                    , e.Message

                    );
                MyLog.Error(errorMsg);
            }


            if (attributes.Count == 0)
            {
                return;
            }

            element.HtmlTag = attributes["TagName"];
            attributes.Remove("TagName");

            WebElementHtmlAttributes elementAttrs = new WebElementHtmlAttributes();

            foreach (var attrKey in attributes.Keys)
            {
                elementAttrs.Add(attrKey, attributes[attrKey]);
            }

            element.AllHtmlTagProperties = elementAttrs;
        }
Ejemplo n.º 13
0
        public void UpdateWebElementWithAdditionalProperties(WebElementDefinition element)
        {
            var by         = Utils.ByFromLocatorSearchMethod(element.HowToSearch, element.Locator);
            var attributes = SwdBrowser.ReadElementAttributes(by);

            if (attributes.Count == 0)
            {
                return;
            }

            element.HtmlTag = attributes["TagName"];
            attributes.Remove("TagName");

            WebElementHtmlAttributes elementAttrs = new WebElementHtmlAttributes();

            foreach (var attrKey in attributes.Keys)
            {
                elementAttrs.Add(attrKey, attributes[attrKey]);
            }

            element.AllHtmlTagProperties = elementAttrs;
        }
Ejemplo n.º 14
0
        private WebElementDefinition GetWebElementDefinitionFromForm()
        {
            var element = new WebElementDefinition()
            {
                Name        = txtWebElementName.Text,
                HowToSearch = GetLocatorSearchMethod(),
                Locator     = GetLocatorText(),

                // Properties
                HtmlTag = txtPropHtmlTag.Text,
                AllHtmlTagProperties = txtAllElementHtmlProps.Tag != null
                                       ? txtAllElementHtmlProps.Tag as WebElementHtmlAttributes
                                       : new WebElementHtmlAttributes(),

                // Custom Args
                Arg1 = txtPropArg1.Text,
                Arg2 = txtPropArg2.Text,
                Arg3 = txtPropArg3.Text,
            };

            return(element);
        }
Ejemplo n.º 15
0
        public WebElementDefinition Clone()
        {
            var clone = new WebElementDefinition()
            {
                Name                 = Name,
                Locator              = Locator,
                HowToSearch          = HowToSearch,
                HtmlTag              = HtmlTag,
                ReturnsCollection    = ReturnsCollection,
                Arg1                 = Arg1,
                Arg2                 = Arg2,
                Arg3                 = Arg3,
                HtmlFrameId          = HtmlFrameId,
                AllHtmlTagProperties = new WebElementHtmlAttributes(),
                AlternativeFindBys   = null,
            };


            foreach (var entry in AllHtmlTagProperties)
            {
                clone.AllHtmlTagProperties.Add(entry.Key, entry.Value);
            }


            List <WebElementLocator> clonedfindBys = new List <WebElementLocator>();

            foreach (var entry in AlternativeFindBys)
            {
                clonedfindBys.Add(new WebElementLocator()
                {
                    HowToSearch = entry.HowToSearch,
                    Locator     = entry.Locator,
                });
            }

            clone.AlternativeFindBys = clonedfindBys.ToArray();

            return(clone);
        }
Ejemplo n.º 16
0
        internal TreeNode AddToPageDefinitions(WebElementDefinition element)
        {
            var newNode = new TreeNode();

            newNode.Text = element.ToString();
            newNode.Tag  = element;

            var action = (MethodInvoker) delegate
            {
                tvWebElements.Nodes[0].Nodes.Add(newNode);
                newNode.EnsureVisible();
            };

            if (tvWebElements.InvokeRequired)
            {
                tvWebElements.Invoke(action);
            }
            else
            {
                action();
            }

            return(newNode);
        }
Ejemplo n.º 17
0
        public void ProcessCommands()
        {
            var command = SwdBrowser.GetNextCommand();

            if (command is GetXPathFromElement)
            {
                var getXPathCommand = command as GetXPathFromElement;
                view.UpdateVisualSearchResult(getXPathCommand.XPathValue);
            }
            else if (command is AddElement)
            {
                var addElementCommand = command as AddElement;

                var element = new WebElementDefinition()
                {
                    Name        = addElementCommand.ElementCodeName,
                    HowToSearch = LocatorSearchMethod.XPath,
                    Locator     = addElementCommand.ElementXPath,
                };
                bool addNew = true;
                Presenters.SelectorsEditPresenter.UpdateWebElementWithAdditionalProperties(element);
                Presenters.PageObjectDefinitionPresenter.UpdatePageDefinition(element, addNew);
            }
        }
Ejemplo n.º 18
0
        internal void UpdateElementPropertiesForm(WebElementDefinition sourceElement)
        {
            var element = sourceElement.Clone();

            txtPropHtmlTag.Text = element.HtmlTag;

            StringBuilder htmlProperties = new StringBuilder();
            foreach (KeyValuePair<string, string> item in element.AllHtmlTagProperties)
            {
                htmlProperties.AppendFormat("{0}=\"{1}\";", item.Key, item.Value);
            }

            txtAllElementHtmlProps.Text = htmlProperties.ToString();
            txtAllElementHtmlProps.Tag = element.AllHtmlTagProperties;

            txtPropArg1.Text = element.Arg1 ?? "";
            txtPropArg2.Text = element.Arg2 ?? "";
            txtPropArg3.Text = element.Arg3 ?? "";
        }
Ejemplo n.º 19
0
        internal void UpdateWebElementForm(WebElementDefinition formData)
        {
            ClearWebElementForm();
            txtWebElementName.Text = formData.Name;

            switch (formData.HowToSearch)
            {
                case LocatorSearchMethod.Id:
                    txtHtmlId.Text = formData.Locator;
                    rbtnHtmlId.Checked = true;
                    break;
                case LocatorSearchMethod.CssSelector:
                    txtCssSelector.Text = formData.Locator;
                    rbtnCssSelector.Checked = true;
                    break;
                case LocatorSearchMethod.XPath:
                    txtXPath.Text = formData.Locator;
                    rbtnXPath.Checked = true;
                    break;
                default:
                    string itemToSelect = "";
                    switch (formData.HowToSearch)
                    {
                        case LocatorSearchMethod.Name: itemToSelect = otherLocator_Name; break;
                        case LocatorSearchMethod.TagName: itemToSelect = otherLocator_TagName; break;
                        case LocatorSearchMethod.ClassName: itemToSelect = otherLocator_ClassName; break;
                        case LocatorSearchMethod.LinkText: itemToSelect = otherLocator_LinkText; break;
                        case LocatorSearchMethod.PartialLinkText: itemToSelect = otherLocator_PartialLinkText; break;
                    }
                    if (!String.IsNullOrEmpty(itemToSelect))
                    {
                        txtOtherLocator.Text = formData.Locator;
                        rbtnOtherLocator.Checked = true;
                        ddlOtherLocator.SelectedIndex = Array.IndexOf(otherLocatorListItems, itemToSelect);
                    }
                    break;
            }

            UpdateElementPropertiesForm(formData);
        }
Ejemplo n.º 20
0
 internal void ReadElementProperties(WebElementDefinition element)
 {
     UpdateWebElementWithAdditionalProperties(element);
     view.UpdateElementPropertiesForm(element);
 }
Ejemplo n.º 21
0
        internal void HighLightWebElement(WebElementDefinition element)
        {
            var by = SwdBrowser.ConvertLocatorSearchMethodToBy(element.HowToSearch, element.Locator);

            SwdBrowser.HighlightElement(by);
        }
Ejemplo n.º 22
0
        internal void HighLightWebElement(WebElementDefinition element)
        {
            var by = Utils.ByFromLocatorSearchMethod(element.HowToSearch, element.Locator);

            SwdBrowser.HighlightElement(by);
        }
Ejemplo n.º 23
0
        private WebElementDefinition GetWebElementDefinitionFromForm()
        {
            var element = new WebElementDefinition()
            {
                Name = txtWebElementName.Text,
                HowToSearch = GetLocatorSearchMethod(),
                Locator = GetLocatorText(),

                // Properties
                HtmlTag = txtPropHtmlTag.Text,
                AllHtmlTagProperties = txtAllElementHtmlProps.Tag != null
                                       ? txtAllElementHtmlProps.Tag as WebElementHtmlAttributes
                                       : new WebElementHtmlAttributes(),

                // Custom Args
                Arg1 = txtPropArg1.Text,
                Arg2 = txtPropArg2.Text,
                Arg3 = txtPropArg3.Text,

            };
            return element;
        }
Ejemplo n.º 24
0
 internal void UpdatePageDefinition(WebElementDefinition element)
 {
     UpdatePageDefinition(element, false);
 }
Ejemplo n.º 25
0
        public WebElementDefinition Clone()
        {
            var clone =  new WebElementDefinition()
            {
                Name = Name,
                Locator = Locator,
                HowToSearch = HowToSearch,
                HtmlTag = HtmlTag,
                ReturnsCollection = ReturnsCollection,
                Arg1 = Arg1,
                Arg2 = Arg2,
                Arg3 = Arg3,
                HtmlFrameId = HtmlFrameId,
                AllHtmlTagProperties = new WebElementHtmlAttributes(),
                AlternativeFindBys = null,
            };

            foreach (var entry in AllHtmlTagProperties)
            {
                clone.AllHtmlTagProperties.Add(entry.Key, entry.Value);
            }

            List<WebElementLocator> clonedfindBys = new List<WebElementLocator>();
            foreach (var entry in AlternativeFindBys)
            {
                clonedfindBys.Add(new WebElementLocator()
                                      {
                                          HowToSearch = entry.HowToSearch,
                                          Locator = entry.Locator,
                                      });
            }

            clone.AlternativeFindBys = clonedfindBys.ToArray();

            return clone;
        }
Ejemplo n.º 26
0
 internal void RemoveWebElement(WebElementDefinition element)
 {
     Presenters.PageObjectDefinitionPresenter.removeElementFromObjectPage(element);
 }