My current Solution. Parses through the HTML file (C:\QA\Test.html), finds all input tags and Select tags, if they have an ID it will convert them into a POM based format. It then prints out to C:\QA\Pom.txt the basic object for it.
Overall, it does 90% of the work that I need, with minor editing.
using System;
using System.Linq;
using System.IO;
using CsQuery;
class Solution
{
static void Main(string[] args)
{
var doc = CQ.CreateDocumentFromFile(@"C:\QA\Test.html");
var inputFields = doc["input"];
var inputPairs = inputFields.Select(node => new Tuple<string, string>(node.Id, node.Value));
string pom = String.Empty;
foreach (var pair in inputPairs)
{
var split = pair.Item1.Split('_');
if (!String.IsNullOrEmpty(pair.Item1.Trim()))
{
pom += String.Format("[FindsBy(How = How.Id, Using = \"{0}\")]\r\n", pair.Item1);
pom += String.Format("public IWebElement {0};\r\n\r\n", split[split.Length - 1]);
}
}
var selectFields = doc["select"];
var selectPairs = selectFields.Select(node => new Tuple<string, string>(node.Id, node.Value));
foreach (var pair in selectPairs)
{
var split = pair.Item1.Split('_');
var name = split[split.Length - 1];
if (!String.IsNullOrEmpty(pair.Item1.Trim()))
{
pom += String.Format("[FindsBy(How = How.Id, Using = \"{0}\")]\r\n", pair.Item1);
pom += String.Format(@"public IWebElement {0}Element;
public SelectElement {0}
{{
get {{ return new SelectElement({0}Element); }}
}} {1}{1}{1}", name,Environment.NewLine);
}
}
File.WriteAllText(@"C:\QA\Pom.txt", pom);
}
}