Rambler's Top100
Главная
Новости
Статьи
Форумы
Книги
Коды
Сообщество
Блоги
О нас
 

Логин

Email:
  Пароль:

Войти
Зарегистрироваться
Забыл пароль

Поиск

 Искать :
 
Вперед

Книги по теме

Искать:
в:
Порядок:

Исходник

Автор:

jahlive

 
Название:

NUnit testing for UI

Дата: 22 November 2005
Описание: Isxodnik pokazivaet kak ispol'zovat' NUnit dlja testirovki Front End. Scenarij takov: Idem na default.aspx nashej application -> Perexodim na login.aspx -> Vvodim User name i Password -> Proverjaem Autentikaciju  
  Разместить ссылку на этот исходник в форуме вы можете вставив в текст сообщения следующую строку: [CODEPOST ID=171]NUnit testing for UI[/CODEPOST]
Оценка: Проголосовало 1 посетителей, средняя оценка 4.00
Оценить:
  1 using System.Diagnostics;
  2 using System.Threading;
  3 using mshtml;
  4 using NUnit.Framework;
  5 using SHDocVw;
  6 
  7 namespace SomeProject.UI.Test
  8 {
  9 	/// <summary>
 10 	/// Summary description for LoginTest.
 11 	/// </summary>
 12 	[TestFixture]
 13 	public class LoginTest
 14 	{
 15 		static AutoResetEvent documentComplete = new AutoResetEvent(false);
 16 		
 17 		[Test]
 18 		public void CanLogin()
 19 		{
 20 			//Prepearing IE
 21 			InternetExplorer ie = null;
 22 			Process p = Process.Start("iexplore.exe", "about:blank");
 23 			Assert.IsNotNull(p, "Process handle = " + p.MainWindowHandle.ToString()) ;
 24 
 25 			ShellWindows allBrowsers = new ShellWindows();
 26 
 27 			Assert.IsFalse(allBrowsers.Count == 0, "Can not find or attach to IE") ;
 28 			
 29 			int i = 0; // attach to correct browser
 30 			while (i < allBrowsers.Count && ie == null)
 31 			{
 32 				InternetExplorer e = (InternetExplorer)allBrowsers.Item(i);
 33 				if (e.HWND == (int)p.MainWindowHandle)
 34 					ie = e;
 35 				++i;
 36 			}
 37 			Assert.IsNotNull(ie,"Failed To attach to IE");
 38 			ie.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(ie_DocumentComplete);
 39 
 40 			//Navigating to the APPs
 41 			object nil = new object();
 42 
 43 			ie.Navigate("http://localhost/yourProject/default.aspx", ref nil, ref nil, ref nil, ref nil);
 44 			//This should redirect to the Login.aspx
 45 
 46 			documentComplete.WaitOne();
 47 
 48 			HTMLDocument theDoc = (HTMLDocument)ie.Document;
 49 			
 50 			//Filling out form
 51 			HTMLInputElement textBoxUid = (HTMLInputElement)theDoc.getElementById("userName");
 52 			textBoxUid.value = "dshalimov";
 53 
 54 			HTMLInputElement textBoxPwd = (HTMLInputElement)theDoc.getElementById("password");
 55 			textBoxPwd.value = "password";
 56 			
 57 			//Clicking button
 58 			HTMLInputElement butt = (HTMLInputElement)theDoc.getElementById("btnLogin");
 59 			butt.click();
 60 
 61 			documentComplete.WaitOne();
 62 
 63 			//Redirecting to dashboard page
 64 			//Reload doc
 65 			theDoc = (HTMLDocument)ie.Document;
 66 
 67 			HTMLBody body = (HTMLBody)theDoc.getElementsByTagName("body").item(0, null);
 68 			Assert.IsTrue(body.createTextRange().findText("Welcome Dmitry Shalimov!", 0, 0),"Logged In") ;
 69 
 70 			//Closing IE in 1 sec
 71 			Thread.Sleep(1000);
 72 			ie.Quit();
 73 
 74 		}
 75 
 76 		private void ie_DocumentComplete(object pDisp, ref object URL)
 77 		{
 78 			documentComplete.Set();
 79 		}
 80 	}
 81 }
 82 
Вернуться к списку исходников в категории Общие вопросы программирования на ASP.NET
 
Apartments for Rent

Rambler's Top100
Рейтинг@Mail.ru
Идея: Dimon aka Manowar Программирование: Dimon aka Manowar Дизайн: Dan Lebedev
Хостинг от компании Parking.ru
Карта сайта