public void UISendTest() { // create a new Internet Explorer instance pointing to the ASP.NET Development Server using (IE ie = new IE(Constants.DevWebSite + "send.aspx")) { // Maximize the IE window ie.ShowWindow(NativeMethods.WindowShowStyle.Maximize); // Fill in the form ie.SelectList(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_SenderDropDownList")).Select(Constants.Sender); ie.TextField(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_RecipientTextBox")).TypeText(Constants.Recipient); ie.TextField(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_MessageTextBox")).TypeText(MESSAGE); WatiN.Core.FileUpload fUp; fUp = ie.FileUpload(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_MultiUpload_Input_0")); fUp.Set(Constants.File0); fUp = ie.FileUpload(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_MultiUpload_Input_1")); fUp.Set(Constants.File1); fUp = ie.FileUpload(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_MultiUpload_Input_2")); fUp.Set(Constants.File2); ie.TextField(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_SecurityCodeTextBox")).TypeText(Constants.SecurityCode); //Trigger the key up event to execute the web service and allow some time for callback ie.TextField(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_SecurityCodeTextBox")).KeyUp(); System.Threading.Thread.Sleep(1000); //Click send and wait until end of post if (ie.Button(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_SendButton")).Enabled) { ie.Button(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_SendButton")).ClickNoWait(); SimpleTimer t = new SimpleTimer(60 * 60); Span s; do { s = ie.Span(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_FinalReportLabel")); if (s.Exists) { goto EXIT; } System.Threading.Thread.Sleep(1000); } while (!t.Elapsed); throw new WatiN.Core.Exceptions.TimeoutException(string.Format("waiting {0} seconds for element to show up.", 60 * 60)); EXIT: Div d = ie.Div(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_SendFinalPanel")); Assert.AreEqual(true, ((d.Exists) && (d.Links.Length > 0) && d.Links[0].Url.StartsWith(Constants.DevWebSite, StringComparison.InvariantCultureIgnoreCase))); } else { Assert.IsTrue(false, "Send button is disabled because of incorrect data"); } } }
public void UploadVideo(IE ie, string filePath) { ie.Link(Find.ById("uploadVideo")).Click(); var fu = ie.FileUpload(Find.ById("ctl00_cphAdmin_txtUploadVideo")); fu.Set(filePath); ie.Button(Find.ById("ctl00_cphAdmin_btnUploadVideo")).Click(); ie.WaitForComplete(); }
public void UploadImage(IE ie, string filePath) { ie.Link(Find.ById("uploadImage")).Click(); var fu = ie.FileUpload(Find.ByClass("ImageUpload")); fu.Set(filePath); ie.Button(Find.ById("ctl00_cphAdmin_btnUploadImage")).Click(); ie.WaitForComplete(); }
/// <summary> /// This is different, you must provide the element id /// </summary> public override void Do(IE ie) { if (ie == null) { ie = Wxs.Instance.Ie; } try { WatiN.Core.FileUpload fi = ie.FileUpload(Find.ById(elementId)); fi.Set(fileName); fi.Click(); Wxs.Instance.Log.Debug( String.Format("File [{0}] uploaded with uploader [{1}]", fileName, elementId)); } catch (Exception e) { Wxs.Instance.Log.Error("Error on FileUpload : " + name, e); } }
public void Leboncoin(BackgroundWorker worker, int z) { if (!log.Text.Contains("Chargement...")) { worker.ReportProgress(0, "Chargement..."); } browser.GoTo("https://www.leboncoin.fr/"); browser.WaitForComplete(); worker.ReportProgress(1); if (browser.Div(Find.ByClass("clearfix")).Exists) { if (!log.Text.Contains("- Connecté")) { worker.ReportProgress(0, "- Connecté"); } } else { worker.ReportProgress(0, "- En cours de connexion..."); browser.Button(Find.ByClass("button-flat button-secondary popin-open trackable custom-small-hidden")).Click(); browser.ElementOfType <TextFieldExtended>(Find.ByName("st_username")).Value = mail; browser.TextField(Find.ByName("st_passwd")).Value = pwd; try { browser.Button(Find.ByValue("Se connecter")).Click(); browser.WaitForComplete(); if (browser.Div(Find.ByClass("create")).Exists) { if (!log.Text.Contains("Connecté")) { worker.ReportProgress(0, "- Connecté"); } } else if (browser.ContainsText("Votre identifiant ou mot de passe est incorrect") || browser.ContainsText("Aucun compte ne correspond à cette adresse e-mail")) { worker.ReportProgress(0, " "); worker.ReportProgress(0, "-- Votre identifiant ou mot de passe est incorrect --"); Kill("connection"); } }catch { worker.ReportProgress(0, "- Erreur lors de la connection."); Kill("connection"); } } if (error != "connection") { worker.ReportProgress(1); browser.GoTo("https://compteperso.leboncoin.fr/account/index.html?ca=12_s"); // Suppression de l'annonce if (browser.Link(Find.ByText(titrelbc)).Exists) { browser.Link(Find.ByText(titrelbc)).Click(); worker.ReportProgress(0, " "); worker.ReportProgress(0, "- Suppression de \"" + titrelbc + "\" en cours..."); browser.Link(Find.ByTitle("Supprimer l'annonce")).Click(); worker.ReportProgress(1); browser.WaitForComplete(); browser.Button(Find.ByName("continue")).Click(); if (browser.ContainsText("L'annonce ci-dessous ne peut pas être supprimée, soit parce qu'elle a déjà été supprimée soit parce qu'elle est en cours de suppression ou de validation") || browser.Text.Contains("Cette annonce est désactivée")) { worker.ReportProgress(0, "- L'annonce a déjà été supprimée!"); } else { browser.Button(Find.ByValue("Valider")).Click(); if (browser.ContainsText("Votre demande de suppression a bien été prise en compte")) { worker.ReportProgress(0, "- L'annonce a été supprimée"); } else { worker.ReportProgress(0, "- Erreur lors de la suppression de l'annonce"); } } worker.ReportProgress(1); } // Mise en ligne de l'annonce browser.GoTo("https://compteperso.leboncoin.fr/account/index.html?ca=12_s"); worker.ReportProgress(0, " "); worker.ReportProgress(0, "- Mise en ligne de \"" + titrelbc + "\"..."); browser.WaitForComplete(); browser.Link(Find.ByText("Déposez une annonce")).Click(); worker.ReportProgress(1); browser.WaitForComplete(); Invoke(new Action(() => { browser.RunScript("$('#category option').filter(function(i, e) { return $(e).text() == '" + catégorie + "'}).prop('selected', 'selected').trigger('change');"); browser.TextField(Find.ById("subject")).Value = titrelbc; browser.TextField(Find.ById("body")).Value = textelbc; browser.ElementOfType <TextFieldExtended>(Find.ById("price")).Value = prixlbc.ToString(); browser.TextField(Find.ByName("zipcode")).Value = zip; browser.TextField(Find.ByName("city")).Value = ville; if (browser.ElementOfType <TextFieldExtended>(Find.ById("phone")).Value == "") { browser.ElementOfType <TextFieldExtended>(Find.ById("phone")).Value = phone; } if (checké == true) { browser.Label("phone_hidden").Click(); } for (int i = 0; i < souscategory.Length; i++) { if (!string.IsNullOrEmpty(souscategory[i])) { try { browser.RunScript("$('#" + souscategoryname[i] + " option').filter(function(i, e) { return $(e).text() == \"" + souscategory[i] + "\"}).prop('selected', 'selected').trigger('change');"); } catch { } if (catégorie == "Voitures" && souscategoryname[i] == "brand") { browser.RunScript("$('#brand option[value=\"" + souscategory[i] + "\"]').prop('selected', true).trigger('change');"); browser.SelectList(Find.ById("model")).WaitUntil("disabled", false.ToString()); browser.RunScript("$('#model option[value=\"" + model + "\"]').prop('selected', true).trigger('change');"); } } } if (browser.ElementOfType <TextFieldExtended>(Find.ById("mileage")).Parent.Parent.Parent.Parent.ClassName == "field") { browser.ElementOfType <TextFieldExtended>(Find.ById("mileage")).Value = mileage; } if (browser.ElementOfType <TextFieldExtended>(Find.ById("cubic_capacity")).Parent.Parent.Parent.Parent.ClassName == "field") { browser.ElementOfType <TextFieldExtended>(Find.ById("cubic_capacity")).Value = cc; } if (browser.ElementOfType <TextFieldExtended>(Find.ById("square")).Parent.Parent.Parent.Parent.ClassName == "field") { browser.ElementOfType <TextFieldExtended>(Find.ById("square")).Value = surface; } if (browser.ElementOfType <TextFieldExtended>(Find.ById("rooms")).Parent.Parent.ClassName == "field") { browser.ElementOfType <TextFieldExtended>(Find.ById("rooms")).Value = piece; } })); worker.ReportProgress(1); if (photo1 != "") { if (File.Exists(photo1)) { browser.FileUpload(Find.ById("image0")).Set(photo1); Invoke(new Action(() => { FocusToPreviousWindow(); })); worker.ReportProgress(0, "Téléchargement de l'image 1..."); browser.Div("uploadPhoto-0").WaitUntil <Element>(element => element.GetAttributeValue("data-state").Equals("uploaded")); } else { worker.ReportProgress(0, "Image 1 non trouvée!"); } worker.ReportProgress(1); } if (photo2 != "") { if (File.Exists(photo2)) { browser.FileUpload(Find.ById("image1")).Set(photo2); Invoke(new Action(() => { FocusToPreviousWindow(); })); worker.ReportProgress(0, "Téléchargement de l'image 2..."); browser.Div("uploadPhoto-1").WaitUntil <Element>(element => element.GetAttributeValue("data-state").Equals("uploaded")); } else { worker.ReportProgress(0, "Image 2 non trouvée!"); } worker.ReportProgress(1); } if (photo3 != "") { if (File.Exists(photo3)) { browser.FileUpload(Find.ById("image2")).Set(photo3); Invoke(new Action(() => { FocusToPreviousWindow(); })); worker.ReportProgress(0, "Téléchargement de l'image 3..."); browser.Div("uploadPhoto-2").WaitUntil <Element>(element => element.GetAttributeValue("data-state").Equals("uploaded")); } else { worker.ReportProgress(0, "Image 3 non trouvée!"); } worker.ReportProgress(1); } browser.CheckBox(Find.ById("phone_hidden")).Click(); //Valider if (browser.Button(Find.ById("newadSubmit")).Exists) { browser.Button(Find.ById("newadSubmit")).Click(); } browser.CheckBox(Find.ById("accept_rule")).Click(); if (browser.Button(Find.ById("lbc_submit")).Exists) { browser.Button(Find.ById("lbc_submit")).Click(); } if (browser.ContainsText("Nous avons bien reçu votre annonce. Nous vous remercions pour votre confiance.")) { worker.ReportProgress(0, "- Annonce mise en ligne!"); } else { worker.ReportProgress(0, "- Problème lors de la mise en ligne"); } worker.ReportProgress(1); // FIN if (rang != 0) { if (z == 1) { Click1(); } else if (z == 2) { Click2(); } worker.CancelAsync(); } else { worker.ReportProgress(100); worker.ReportProgress(0, " "); worker.ReportProgress(0, "-- MISE EN LIGNE TERMINÉE --"); Invoke(new Action(() => { browser.ForceClose(); browser.Dispose(); notifyIcon1.BalloonTipTitle = "Mise en ligne terminée!"; notifyIcon1.BalloonTipText = "LeBOTcoin a bien renouvelé vos annonces."; notifyIcon1.ShowBalloonTip(3500); })); } } worker.Dispose(); }
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); } }