public static async Task OnSubmitEventNotCalled() { var httpResources = Mocks.HttpResourceProvider() .Resource("http://site.net/", "<form method=post action='login'><input name=username type=text><input type=submit id=sub></form>") .Resource("http://site.net/login", "<div id=d></div>"); var engine = TestingEngine.Build(new ResourceProvider(httpResources, null)); engine.OpenUrl("http://site.net").Wait(); var doc = engine.Document; var form = doc.Get <HtmlFormElement>("form").First();; bool formsOnSubmitCalled = false; form.OnSubmit += _ => formsOnSubmitCalled = true; bool windowOnSubmitCalled = false; engine.Window.OnSubmit += _ => windowOnSubmitCalled = true; form.Submit(); Assert.IsFalse(formsOnSubmitCalled); Assert.IsFalse(windowOnSubmitCalled); }
public static string SubmitPostFormEncodingType(string enctype) { var httpResources = Mocks.HttpResourceProvider() .Resource("http://site.net/", $"<form method=post action='login' enctype='{enctype}'>" + $"<input name=username type=text>" + $"<input name=password type=password>" + "<textarea name=\"Text1\" cols=\"40\" rows=\"5\"></textarea>" + $"</form>") .Resource("http://site.net/login", "<div id=d></div>"); var engine = TestingEngine.Build(new ResourceProvider(httpResources, null)); engine.OpenUrl("http://site.net").Wait(); var doc = engine.Document; doc.Get <HtmlInputElement>("[name=username]").First().Value = "[email protected]"; doc.Get <HtmlInputElement>("[name=password]").First().Value = "1! %&"; doc.Get <HtmlTextAreaElement>("[name=Text1]").First().Value = "hello\r\nworld=pip"; doc.Get <HtmlFormElement>("form").First().Submit(); Assert.IsNotNull(engine.WaitId("d")); return(Encoding.UTF8.GetString(httpResources.History[1].Data)); }
public static string SubmitPostFormCheckbox(bool check) { var httpResources = Mocks.HttpResourceProvider() .Resource("http://site.net/", "<form method=post action='login'>" + "<input name=rememberme type=cheCkbox id=checkbox>" + "</form>") .Resource("http://site.net/login", "<div id=d></div>"); var engine = TestingEngine.Build(new ResourceProvider(httpResources, null)); engine.OpenUrl("http://site.net").Wait(); var doc = engine.Document; var form = doc.Get <HtmlFormElement>("form").First(); if (check) { var cb = (HtmlInputElement)form.Elements.Single(); cb.Checked = true; } form.Submit(); return(Encoding.UTF8.GetString(httpResources.History[1].Data)); }
public string EncTypeFromAttr(string encType) { var engine = TestingEngine.Build("http://a.bc/Account/Login/", $"<form id=f enctype=\"{encType}\"></form>"); engine.OpenUrl("http://a.bc/Account/Login/").Wait(); var form = (HtmlFormElement)engine.Document.GetElementById("f"); return(form.Enctype); }
public string GetAction(string attrValue) { var engine = TestingEngine.Build("http://a.bc/Account/Login/", $"<form id=f action=\"{attrValue}\"></form>"); engine.OpenUrl("http://a.bc/Account/Login/").Wait(); var form = (HtmlFormElement)engine.Document.GetElementById("f"); return(form.Action); }
public string SetGetEncType(string encType) { var engine = TestingEngine.Build("http://a.bc/Account/Login/", "<form id=f></form>"); engine.OpenUrl("http://a.bc/Account/Login/").Wait(); var form = (HtmlFormElement)engine.Document.GetElementById("f"); form.Enctype = encType; Assert.AreEqual(encType, form.GetAttribute("enctype")); return(form.Enctype); }
public string SetGetAction(string actionValue) { var engine = TestingEngine.Build("http://a.bc/Account/Login/", "<form id=f></form>"); engine.OpenUrl("http://a.bc/Account/Login/").Wait(); var form = (HtmlFormElement)engine.Document.GetElementById("f"); form.Action = actionValue; Assert.AreEqual(actionValue, form.GetAttribute("action")); return(form.Action); }