PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.Tests/BeTest.cs

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