public WebElementNode(PageObjectNode parent, string label, string name, string id, string cclass, string node, string type, string path, string toname, bool enumerable) : base(parent, WebElementString) { ParentPageObjectNode = parent; Label = label; Name = name; Id = id; ClassName = cclass; Node = node; Type = type; Path = path; ToPage = toname; IsEnumerable = enumerable; }
/// <summary> /// This method, for the BlockCreatorGui, creates a miniature tree and fills it with the /// given actions for the block. Then, it builds the tree. /// </summary> /// <param name="elements"> /// The elements of the block. /// </param> /// <param name="blockName"> /// The name of the block. /// </param> public static void ExportBlock(List <UserAction> elements, string blockName) { if (elements.Count > 0) { CheckDirectories(); var block = new PageObjectNode(null, blockName); foreach (UserAction action in elements) { block.Children.Add(new WebElementNode(block, action.Label, action.Name, action.Id, action.ClassName, action.Node, action.Type, action.Path, blockName, action.IsEnumerable)); } block.BuildRaw(); } }
/// <summary> /// Used when the application is first run, this method reads the entire XML file and /// creates corresponding node objects (FolderNode, PageObjectNode, and WebElementNode) /// to be used later for exporting purposes. /// </summary> /// <returns> /// Returns the root node (head) of the loaded tree. /// </returns> public static FolderNode LoadPageObjectTree() { var head = new FolderNode(null, PageObjectLibraryName); PageObjectNode pageObject = null; try { var reader = new XmlTextReader(OutputPath + "\\" + TreeName); FolderNode curFolder; while (true) { reader.Read(); if (reader.Name == PageObjectLibraryName) { head = new FolderNode(null, PageObjectLibraryName); curFolder = head; break; } } while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == PageObjectNode.PageObjectString) { pageObject = new PageObjectNode(curFolder, reader.GetAttribute("Name")); curFolder.Children.Add(pageObject); } else if (reader.Name == WebElementNode.WebElementString) { string label = reader.GetAttribute("Label"); string name = reader.GetAttribute("Name"); string id = reader.GetAttribute("Id"); string cclass = reader.GetAttribute("Class"); string node = reader.GetAttribute("Node"); string type = reader.GetAttribute("Type"); string path = reader.GetAttribute("Path"); string toname = reader.GetAttribute("ToPage"); string enumerable = reader.GetAttribute("IsEnumerable"); if (pageObject == null) { Debug.WriteLine("Bad tree XML! A web element was found before a page object! Exiting"); return(head); } pageObject.Children.Add(new WebElementNode(pageObject, label, name, id, cclass, node, type, path, toname, bool.Parse(enumerable))); } else { var folder = new FolderNode(curFolder, reader.Name); curFolder.Children.Add(folder); curFolder = folder; } } else if (reader.NodeType == XmlNodeType.EndElement && reader.Name != PageObjectNode.PageObjectString && reader.Name != WebElementNode.WebElementString) { curFolder = curFolder.Parent; } } reader.Close(); } catch (Exception e) { Debug.WriteLine(e.Message); Debug.WriteLine("Creating a new page objext tree!"); } return(head); }