Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: None  |  size: 3.66 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using NUnit.Framework;
  6. using WatiN.Core;
  7. using System.IO;
  8. using System.Windows.Forms;
  9.  
  10. namespace PoC_SIA {
  11.     [TestFixture]
  12.     [RequiresSTA]
  13.     public class Class1 {
  14.         [Test]
  15.         public void PruebaGetInscripciones134() {
  16.             Stream file = File.Open("c:\\inscripciones.txt", FileMode.Append);
  17.             using (StreamWriter writer = new StreamWriter(file)) {
  18.                 string username = "un_usuario";
  19.                 string password = "un_password";
  20.                 string materiaSigla = "MAT-134";
  21.                 string materiaDescripcion = "ANALISIS MATEMATICO III";
  22.                 string paralelo = "B";
  23.                 string mensaje = string.Format("{0} {1} en el paralelo {2}", materiaSigla, materiaDescripcion, paralelo);
  24.                 System.Collections.Generic.List<string> inscripciones = new List<string>();
  25.                 using (var browser = new IE("http://sia.informatica.edu.bo")) {
  26.                     browser.AutoClose = false;
  27.                     var txtLogin = Find.ByName("login");
  28.                     var txtPassword = Find.ByName("password");
  29.                     var btnIngresar = Find.ByName("FRM_INGRESAR");
  30.  
  31.                     //MessageBox.Show(browser.Frames.Count.ToString());
  32.                     //MessageBox.Show(browser.Url);
  33.  
  34.                     browser.Frames[2].TextField(txtLogin).TypeText(username);
  35.                     browser.Frames[2].TextField(txtPassword).TypeText(password);
  36.                     browser.Frames[2].Image(btnIngresar).Click();
  37.  
  38.                     for (int i = 357398; i <= 358000; i++) {
  39.                         browser.GoTo(GetInscripcionUrl(browser.Url, i));
  40.                         var btnBorrar = Find.ByName("FRM_CONFIRMAR_BORRAR");
  41.                         if (browser.ContainsText("materias inscritas")) {
  42.                             string textoInterno = browser.Text.Substring(140);
  43.                             textoInterno = ObtenerMateriaParalelo(textoInterno);
  44.                            
  45.                             writer.WriteLine(textoInterno + " --->  " + i);
  46.                             writer.WriteLine("");
  47.                             writer.Flush();
  48.                         }
  49.                     }
  50.  
  51.                     //WriteListToFile(inscripciones);
  52.  
  53.                     Assert.IsNotNull(txtLogin);
  54.                     Assert.IsNotNull(txtPassword);
  55.                     Assert.IsNotNull(btnIngresar);
  56.                     //Assert.IsTrue(browser.Frames[2].ContainsText("Bienvenido"));
  57.                 }
  58.                 writer.Close();
  59.                 file.Close();
  60.             }
  61.         }
  62.  
  63.         private string ObtenerMateriaParalelo(string textoInterno) {
  64.             string[] words = textoInterno.Split(new char[]{' ', '\t', '\n'}, StringSplitOptions.RemoveEmptyEntries);
  65.             string result = words[0] + " - " + words[words.Length - 2] + " " + words[words.Length - 1].Substring(0, words[words.Length - 1].Length - 3);
  66.             return result;
  67.         }
  68.         public string GetInscripcionUrl(string baseUrl, int baseId = 355333) {
  69.             int sum = 38 + 32 + 1;
  70.             return baseUrl.Substring(0, sum) + "eliminar_inscripcion.php?id_inscripcion=" + baseId;
  71.         }
  72.         public void WriteListToFile(System.Collections.Generic.List<string> list) {
  73.             Stream file = File.Open("c:\\inscripciones.txt", FileMode.Append);
  74.             using (StreamWriter writer = new StreamWriter(file)) {
  75.                 foreach (var inscripcion in list) {
  76.                     writer.WriteLine(inscripcion);
  77.                 }
  78.             }
  79.         }
  80.     }
  81. }