PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.Tests/BeTest.cs

#
C# | 78 lines | 58 code | 18 blank | 2 comment | 5 complexity | a78a0998d9a09e40b8cd174c3459d3a2 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. using System;
  2. using NUnit.Framework;
  3. using WatiN.Core;
  4. using BlogEngine.Tests.PageTemplates.Account;
  5. namespace BlogEngine.Tests
  6. {
  7. public abstract class BeTest
  8. {
  9. protected IE ie = null;
  10. [TestFixtureSetUp]
  11. public void SetUp()
  12. {
  13. ie = new IE();
  14. ie.Refresh();
  15. ie.ClearCache();
  16. Settings.WaitForCompleteTimeOut = 240;
  17. // to hide IE window
  18. // ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide);
  19. }
  20. [STAThread]
  21. static void Main(string[] args)
  22. {
  23. }
  24. [TestFixtureTearDown]
  25. public void TearDown()
  26. {
  27. ie.Close();
  28. }
  29. public void Login(string user, string pwd = "")
  30. {
  31. if (string.IsNullOrEmpty(pwd))
  32. pwd = user;
  33. var login = ie.Page<Login>();
  34. ie.GoTo(login.Url);
  35. TypeQuickly(login.UserName, user);
  36. TypeQuickly(login.Password, pwd);
  37. login.LoginButton.Click();
  38. }
  39. public void Logout()
  40. {
  41. ie.GoTo(Constants.Root);
  42. var login = ie.Page<Login>();
  43. var logOffLink = login.LogoffLink;
  44. if (logOffLink != null && logOffLink.Text == Constants.LogOff)
  45. {
  46. logOffLink.Click();
  47. }
  48. }
  49. public static void TypeQuickly(TextField textField, string text)
  50. {
  51. textField.SetAttributeValue("value", text);
  52. }
  53. public void Wait(int seconds)
  54. {
  55. int i;
  56. int.TryParse(string.Format("{0}000", seconds), out i);
  57. System.Threading.Thread.Sleep(i);
  58. }
  59. }
  60. }