/// <summary> /// This method uses an XmlTextWriter to write the tree to an XML file, starting with /// the head node. /// </summary> /// <param name="head"> /// The root node of the tree. /// </param> private static void WriteTreeToXml(FolderNode head) { Directory.CreateDirectory(OutputPath); var writer = new XmlTextWriter(OutputPath + "\\" + TreeName, null); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); head.WriteToXml(writer); writer.WriteEndDocument(); writer.Flush(); writer.Close(); }
/// <summary> /// For the PageObjectCreatorGui, this method will update the tree with the actions, /// write the tree to an XML file, check directories, build the files, and create /// a test file. /// </summary> /// <param name="actions"> /// The actions from the PageObjectCreatorGui. /// </param> /// <param name="head"> /// The head of the tree. /// </param> /// <param name="testName"> /// The desired name of the test. /// </param> public static void ExportToOutputFolder(List <UserAction> actions, FolderNode head, string testName) { if (actions.Count > 1) { UpdateTreeWithActions(actions, head); WriteTreeToXml(head); CheckDirectories(); head.BuildRaw(); CreateTestRaw(actions, testName); MessageBox.Show( actions.Count + " new page objects " + (actions.Count > 1 ? " and a new test " : "") + "were exported to \"" + OutputPath + "\"!", "Export to Output Folder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <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); }
public PageObjectNode(FolderNode parent, string name) : base(parent, PageObjectString) { Name = name; }
public FolderNode(FolderNode parent, string title) { Parent = parent; Title = title; }