public void ExpectedErrorWhenUsingADialogBeforeAttachingIt()
 {
     using (TestManager testManager = new TestManager())
     {
         testManager.Tests.Add(new Test());
         testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
         testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSimpleDialogHandler2", "GetJavaDialogMessage", "SimpleJavaAlert,dlgSimple", string.Empty, string.Empty }));
         testManager.Execute();
     }
 }
        public void AttachToIENoRunningInstanceFound()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "AttachToIETest", "AttachToIE", string.Empty, "ByTitle", "Test page 23" }));
                testManager.Execute();

                Assert.IsTrue(testManager.Browser.Url.EndsWith("testpage2.htm"), "Command.Execute using a goto did not navigate to the expected page: testpage1.htm");
            }
        }
        public void ExecuteValidatePasses()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CreateCommandValidate("Go to test page 2,Text", "ById", "link1"));

                testManager.Execute();
            }
        }
        public void BringToFront()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "BringToFrontTest", "BringToFront", string.Empty, string.Empty, string.Empty }));
                testManager.Execute();

                Assert.IsTrue(Browser.Exists<IE>(Find.ByTitle("Test page 1")));
            }
        }
        public void AttachDialogHandlerTest()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSimpleDialogHandler", "AttachDialogHandler", "SimpleJavaAlert,dlgSimple", string.Empty, string.Empty }));
                testManager.Execute();

                Assert.AreEqual(1, testManager.Browser.DialogWatcher.Count);
            }
        }
        public void SetCheckBoxValue()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] {"SetChk", "SetValue", "false,Checked", "ById", "chkEmailMe"}));

                testManager.Execute();

                Assert.AreEqual(false, testManager.Browser.CheckBox(Find.ById("chkEmailMe")).Checked, "SetValueCommand.Execute using a checked command argument did not function appropriately");
            }
        }
        public void SetRadioButtonValue()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] {"SetRadBtn1", "SetValue", "true,Checked", "ByNameAndValue", "radio1,2"}));

                testManager.Execute();

                Assert.AreEqual(true, testManager.Browser.RadioButton(Find.ByName("radio1") && Find.ByValue("2")).Checked, "SetValueCommand.Execute using a checked command argument did not function appropriately");
            }
        }
        public void SetFileUploadValue()
        {
            using (TestManager testManager = new TestManager())
            {
                string testHtmlPage = System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm");
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(testHtmlPage));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] {"SetFileUpLoad", "SetValue", string.Format("{0},FileName", testHtmlPage), "ById", "fileUpload"}));

                testManager.Execute();

                Assert.AreEqual(testHtmlPage, testManager.Browser.FileUpload("fileUpload").FileName, "SetValueCommand.Execute using a filename command argument did not function appropriately");
            }
        }
        public void CatchExceptions()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.ThrowErrors = false;
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSimpleDialogHandler", "AttachDialogHandler", "OkDialog,dlgSimple", string.Empty, string.Empty }));
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1NotExist.htm")));
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1NotExistAsWell.htm")));
                testManager.Execute();

                Assert.AreEqual(2, testManager.Tests[0].Errors.Count);
            }
        }
        public void FindById()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Execute();

                FindMethod findMethod = FindMethod.Parse("ById", new string[] { "link1" });
                WatiN.Core.Element element = findMethod.Execute(new ExecutionContext(testManager));

                Assert.IsNotNull(element, "FindMethod.Execute using Find.ById returned null.");
            }
        }
        public void AttributeBasedValidation()
        {
            using (TestManager testManager = new TestManager())
            {
                ValidateCommand attributeValidation = (ValidateCommand)CreateCommandValidate("mainForm,Attribute:class", "ById", "form1");
                Assert.AreEqual("Attribute:class", attributeValidation.PropertyName);
                Assert.AreEqual("ClassName", attributeValidation.AttributeName);

                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(attributeValidation);

                testManager.Execute();
            }
        }
        public void AlertMessageTest()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdStart", "BringToFront", string.Empty, string.Empty, string.Empty }));
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSimpleDialogHandler", "AttachDialogHandler", "SimpleJavaAlert,dlgSimple", string.Empty, string.Empty }));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdClickLink", "ClickNoWait", string.Empty, "ById", "linkAlert" }));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSimpleDialogHandler2", "GetJavaDialogMessage", "SimpleJavaAlert,dlgSimple", string.Empty, string.Empty }));
                testManager.Execute();

                Assert.AreEqual("This is an alert message", testManager.ExecutionContext.LastFoundValue);
            }
        }
        public void AttachToIE()
        {
            Process.Start("iexplore.exe", System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm"));

            // Give IE a chance to load.
            Thread.Sleep(2000);

            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "AttachToIETest", "AttachToIE", string.Empty, "ByTitle", "Test page 1" }));
                testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage2.htm")));
                testManager.Execute();

                Assert.IsTrue(testManager.Browser.Url.EndsWith("testpage2.htm"), string.Format("Command.Execute using a goto did not navigate to the expected page: testpage2.htm, instead found :{0}", testManager.Browser.Url));
            }
        }
 public void ExceptionsAreThrown()
 {
     try
     {
         using (TestManager testManager = new TestManager())
         {
             testManager.Tests.Add(new Test());
             testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSimpleDialogHandler", "AttachDialogHandler", "OkDialog,dlgSimple", string.Empty, string.Empty }));
             testManager.Tests[0].Commands.Add(
                 CommandTest.CreateCommandGotoUrl(
                     System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1NotExist.htm")));
             testManager.Tests[0].Commands.Add(
                 CommandTest.CreateCommandGotoUrl(
                     System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1NotExistAsWell.htm")));
             testManager.Execute();
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine("Exception: " + exception.GetType().Name + " was thrown.");
         throw;
     }
 }
        public void ExecuteValidateValue()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(SetValueCommandTest.CreateCommandText("Edward,Text", "ById", "FirstName"));
                testManager.Tests[0].Commands.Add(CreateCommandValidate("Edward,Value", "ById", "FirstName"));

                testManager.Execute();
            }
        }
        public void SetSelectListMultipleValues()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] {"SetCardList", "SetValues", "1,2,3,SelectedItem", "ById", "cardList2"}));

                testManager.Execute();

                SelectList cardList = testManager.Browser.SelectList(Find.ById("cardList2"));
                Assert.AreEqual(3, cardList.SelectedOptions.Count, "SetValueCommand.Execute using a select list command argument did not function appropriately");
            }
        }
        public void ExecuteGoto()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Execute();

                Assert.IsTrue(testManager.Browser.Url.EndsWith("testpage1.htm"), "Command.Execute using a goto did not navigate to the expected page: testpage1.htm");
            }
        }
        public void ExecuteGotoInvalidUrl()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSimpleOkDialogHandler", "AttachDialogHandler", "OkDialog,dlgSimple", string.Empty, string.Empty }));
                testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1NotExist.htm")));
                //testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSimpleDialogHandler", "AttachDialogHandler", "SimpleJavaAlert,dlgSimple", string.Empty, string.Empty }));
                testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Execute();

                Assert.IsTrue(testManager.Browser.Url.EndsWith("testpage1.htm"), "Command.Execute using a goto did not navigate to the expected page: testpage1.htm");
            }
        }
        public void SetTextFieldValue()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CreateCommandText("Edward,Text", "ById", "FirstName"));

                testManager.Execute();

                Assert.AreEqual("Edward", testManager.Browser.TextField("FirstName").Value, "Command.Execute using a text command did not function appropriately");
            }
        }
        public void LastElement()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(SetValueCommandTest.CreateCommandText("Edward,Text", "ById", "FirstName"));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "ValidateLastElementTest", "Validate", "Edward,Value", "ByLastElement", string.Empty }));
                testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage2.htm")));
                testManager.Execute();

                Assert.IsTrue(testManager.Browser.Url.EndsWith("testpage2.htm"), string.Format("Command.Execute using a goto did not navigate to the expected page: testpage2.htm, instead found :{0}", testManager.Browser.Url));
            }
        }
        public void ExecuteGotoTilda()
        {
            string tempImageFile = @"~testpage1.htm";

            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(tempImageFile));
                testManager.Execute();

                Assert.IsTrue(testManager.Browser.Url.EndsWith("testpage1.htm"), "Command.Execute using a goto did not navigate to the expected page: testpage1.htm");
            }
        }
 public void Focus()
 {
     using (TestManager testManager = new TestManager())
     {
         testManager.Tests.Add(new Test());
         testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
         testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "FocusTest", "Focus", string.Empty, "ById", "chkEmailMe" }));
         testManager.Execute();
     }
 }
        public void SetCookie()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSetCookie", "SetCookie", "http://www.google.co.uk/,\"wax=1234; expires=Wed, 01-Jan-2020 00:00:00 GMT\"", string.Empty, string.Empty }));
                testManager.Execute();

                Assert.AreEqual("wax=1234", testManager.Browser.GetCookie("http://www.google.co.uk/", "wax"));
            }
        }
        public void GetCookie()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSetCookie", "SetCookie", "http://www.google.co.uk/,\"wax=1234; expires=Wed, 01-Jan-2020 00:00:00 GMT\"", string.Empty, string.Empty }));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdGetCookie", "GetCookie", "\"http://www.google.co.uk/\",\"wax\"", string.Empty, string.Empty }));
                testManager.Execute();

                Assert.AreEqual("wax=1234", testManager.ExecutionContext.LastFoundValue, "GetCookie failed to retrieve the expected value.");
            }
        }
 public void Refresh()
 {
     using (TestManager testManager = new TestManager())
     {
         testManager.Tests.Add(new Test());
         testManager.Tests[0].Commands.Add(CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
         testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "RefreshTest", "Refresh", string.Empty, string.Empty, string.Empty }));
         testManager.Execute();
     }
 }
        public void ValidateLastFound()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdSetCookie", "SetCookie", "http://www.google.co.uk/,\"wax=1234; expires=Wed, 01-Jan-2020 00:00:00 GMT\"", string.Empty, string.Empty }));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdGetCookie", "GetCookie", "\"http://www.google.co.uk/\",\"wax\"", string.Empty, string.Empty }));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "CmdValidateLastFound", "ValidateLastFound", "wax=1234", string.Empty, string.Empty }));

                testManager.Execute();
            }
        }
        public void Screenshot()
        {
            string tempImageFile = Path.GetTempFileName();

            try
            {
                using (TestManager testManager = new TestManager())
                {
                    testManager.Tests.Add(new Test());
                    testManager.Tests[0].Commands.Add(
                        CreateCommandGotoUrl(
                            System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                    testManager.Tests[0].Commands.Add(
                        CommandFactory.Parse(
                            new String[] { "CmdScreenshot", "Screenshot", tempImageFile, string.Empty, string.Empty }));
                    testManager.Execute();

                    Assert.IsTrue(File.Exists(tempImageFile), "Image file not found after executing the screen shot command.");
                }
            }
            finally
            {
                if (File.Exists(tempImageFile))
                {
                    File.Delete(tempImageFile);
                }
            }
        }
        /// <summary>
        /// Executes this instance.
        /// </summary>
        public void Execute()
        {
            using (TestManager testManager = new TestManager(this.execaoSucesso))
            {
                PreExecuteInitialize(testManager);

                if (this.ExecutionStarted != null)
                {
                    this.ExecutionStarted(this, EventArgs.Empty);
                }

                testManager.Execute();

                if (this.ExecutionCompleted != null)
                {
                    this.ExecutionCompleted(this, EventArgs.Empty);
                }
            }
        }
        public void ExecuteValidateSelectedValue()
        {
            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(CommandTest.CreateCommandGotoUrl(System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(CommandFactory.Parse(new String[] { "SetCardList", "SetValue", "2,SelectedItem", "ById", "cardList" }));
                testManager.Tests[0].Commands.Add(CreateCommandValidate("2,SelectedItem", "ByLastElement", string.Empty));

                testManager.Execute();
            }
        }
        public void ScreenshotWithTilda()
        {
            string tempImageFile = @"~\test1.png";

            using (TestManager testManager = new TestManager())
            {
                testManager.Tests.Add(new Test());
                testManager.Tests[0].Commands.Add(
                    CreateCommandGotoUrl(
                        System.IO.Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")));
                testManager.Tests[0].Commands.Add(
                    CommandFactory.Parse(
                        new String[] { "CmdScreenshot", "Screenshot", tempImageFile, string.Empty, string.Empty }));
                testManager.Execute();

                Assert.IsTrue(File.Exists(tempImageFile.Replace("~", Environment.CurrentDirectory)), string.Format("Image file {0} not found after executing the screen shot command.", tempImageFile.Replace("~", Environment.CurrentDirectory)));
            }
        }