public void Register() { try { Ie = new IE("about:blank"); Ie.GoTo("http://localhost/GuestBook/GuestBook.aspx"); Ie.TextField(Find.ByName("name")).TypeText("Jay"); Ie.TextField(Find.ByName("comments")).TypeText("Hello"); Ie.Button(Find.ByName("save")).Click(); Assert.AreEqual("Jay", Ie.TableCell(Find.By("innerText", "Jay")).Text, @"innerText does not match"); Assert.AreEqual("Hello", Ie.TableCell(Find.By("innerText", "Hello")).Text, @"innerText does not match"); } finally { if (Ie != null) { InternetExplorer internetExplorer = (InternetExplorer)Ie.InternetExplorer; internetExplorer.Quit(); } } }
private static void GetPatentFromPage(IE browser, int year) { var inventor = browser.TableCell(x => x.PreviousSibling != null && x.PreviousSibling.Text == "Opfinder").Text; var patentIdAndDate = browser.TableCell(x => x.PreviousSibling != null && x.PreviousSibling.Text == "Patent/reg.nr. og dato").Text; var patentId = patentIdAndDate.Split(',').First(); using (var context = new Context()) { var patent = new Patent { Html = browser.Html, InventorField = inventor, PatentId = patentId, Year = year, }; context.Patents.Add(patent); context.SaveChanges(); } }
public static object FindControlInBrowserByID(IE ie, string strID, Enumerators.ControlType ctrl) { if (ctrl == Enumerators.ControlType.Span) { Span sp = ie.Span(Find.ById(strID)); Assert.IsTrue(sp.Exists, "Could not Find: " + strID); return sp; } else if (ctrl == Enumerators.ControlType.Link) { Link lnk = ie.Link(Find.ById(strID)); Assert.IsTrue(lnk.Exists, "Could not Find: " + strID); return lnk; } else if (ctrl == Enumerators.ControlType.Frame) { Frame iFrame = ie.Frame(Find.ById(strID)); return iFrame; } else if (ctrl == Enumerators.ControlType.Image) { Image img = ie.Image(Find.ById(strID)); Assert.IsTrue(img.Exists, "Could not Find: " + strID); return img; } else if (ctrl == Enumerators.ControlType.TableCell) { TableCell tCell = ie.TableCell(Find.ById(strID)); Assert.IsTrue(tCell.Exists, "Could not Find: " + strID); return tCell; } else if (ctrl == Enumerators.ControlType.Table) { Table tbl = ie.Table(Find.ById(strID)); Assert.IsTrue(tbl.Exists, "Could not Find: " + strID); return tbl; } else if (ctrl == Enumerators.ControlType.TableRow) { TableRow row = ie.TableRow(Find.ById(strID)); Assert.IsTrue(row.Exists, "Could not Find: " + strID); return row; } else if (ctrl == Enumerators.ControlType.CheckBox) { CheckBox chk = ie.CheckBox(Find.ById(strID)); Assert.IsTrue(chk.Exists, "Could not Find: " + strID); return chk; } else if (ctrl == Enumerators.ControlType.Button) { Button btn = ie.Button(Find.ById(strID)); Assert.IsTrue(btn.Exists, "Could not Find: " + strID); return btn; } else if (ctrl == Enumerators.ControlType.TextField) { TextField txt = ie.TextField(Find.ById(strID)); Assert.IsTrue(txt.Exists, "Could not Find: " + strID); return txt; } else if (ctrl == Enumerators.ControlType.SelectList) { SelectList sList = ie.SelectList(Find.ById(strID)); Assert.IsTrue(sList.Exists, "Could not Find: " + strID); return sList; } else if (ctrl == Enumerators.ControlType.Div) { Div division = ie.Div(Find.ById(strID)); Assert.IsTrue(division.Exists, "Could not Find: " + strID); return division; } else if (ctrl == Enumerators.ControlType.TableRow) { TableRow tRow = ie.TableRow(Find.ById(strID)); Assert.IsTrue(tRow.Exists, "Could not Find: " + strID); return tRow; } else if (ctrl == Enumerators.ControlType.FileUpload) { FileUpload fileUpload = ie.FileUpload(Find.ById(strID)); Assert.IsTrue(fileUpload.Exists, "Could not find: " + strID); return fileUpload; } else { return null; } }
public static object FindControlInBrowserByCustom(IE ie, string strCustomAttribute, string strToFind, Enumerators.ControlType ctrl) { if (ctrl == Enumerators.ControlType.Span) { Span sp = ie.Span(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(sp.Exists, "Could not Find: " + strToFind); return sp; } else if (ctrl == Enumerators.ControlType.Link) { Link lnk = ie.Link(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(lnk.Exists, "Could not Find: " + strToFind); return lnk; } else if (ctrl == Enumerators.ControlType.Frame) { Frame frame = ie.Frame(Find.By(strCustomAttribute, strToFind)); Assert.AreEqual(frame.Name, strToFind); return frame; } else if (ctrl == Enumerators.ControlType.Image) { Image img; if (strCustomAttribute == "src") { img = ie.Image(Find.BySrc(strToFind)); } else { img = ie.Image(Find.By(strCustomAttribute, strToFind)); } Assert.IsTrue(img.Exists, "Could not Find: " + strToFind); return img; } else if (ctrl == Enumerators.ControlType.TableCell) { TableCell tCell = ie.TableCell(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(tCell.Exists, "Could not Find: " + strToFind); return tCell; } else if (ctrl == Enumerators.ControlType.Table) { Table tbl = ie.Table(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(tbl.Exists, "Could not Find: " + strToFind); return tbl; } else if (ctrl == Enumerators.ControlType.TableRow) { TableRow row = ie.TableRow(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(row.Exists, "Could not Find: " + strToFind); return row; } else if (ctrl == Enumerators.ControlType.CheckBox) { CheckBox chk = ie.CheckBox(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(chk.Exists, "Could not Find: " + strToFind); return chk; } else if (ctrl == Enumerators.ControlType.Button) { Button btn = ie.Button(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(btn.Exists, "Could not Find: " + strToFind); return btn; } else if (ctrl == Enumerators.ControlType.TextField) { TextField txt = ie.TextField(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(txt.Exists, "Could not Find: " + strToFind); return txt; } else if (ctrl == Enumerators.ControlType.SelectList) { SelectList sList = ie.SelectList(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(sList.Exists, "Could not Find: " + strToFind); return sList; } else if (ctrl == Enumerators.ControlType.Div) { Div div = ie.Div(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(div.Exists, "Could not Find: " + strToFind); return div; } else { return null; } }