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); }
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(); } }
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); } }
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; }
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); }
internal void HighLightWebElement(WebElementDefinition element) { if (!IsValidForm()) { return; } var by = SwdBrowser.ConvertLocatorSearchMethodToBy(element.HowToSearch, element.Locator); SwdBrowser.HighlightElement(by); }
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(); } }
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); } }
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); }
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; }
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; }
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); }
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); }
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); }
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); } }
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 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); }
internal void ReadElementProperties(WebElementDefinition element) { UpdateWebElementWithAdditionalProperties(element); view.UpdateElementPropertiesForm(element); }
internal void HighLightWebElement(WebElementDefinition element) { var by = SwdBrowser.ConvertLocatorSearchMethodToBy(element.HowToSearch, element.Locator); SwdBrowser.HighlightElement(by); }
internal void HighLightWebElement(WebElementDefinition element) { var by = Utils.ByFromLocatorSearchMethod(element.HowToSearch, element.Locator); SwdBrowser.HighlightElement(by); }
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; }
internal void UpdatePageDefinition(WebElementDefinition element) { UpdatePageDefinition(element, false); }
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; }
internal void RemoveWebElement(WebElementDefinition element) { Presenters.PageObjectDefinitionPresenter.removeElementFromObjectPage(element); }