public void DifferentWayToFindDomElementTest()
        {
            // Arrange
            const string webSiteName = "TestEasyWAP";

            var server = WebServer.Create();
            var appInfo = server.CreateWebApplication(webSiteName);
            server.DeployWebApplication(appInfo.Name, new List<DeploymentItem>
                {
                    new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName }
                });
            server.BuildWebApplication(webSiteName);

            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser();
                // Act
                browser.Navigate().GoToUrl(appInfo.VirtualPath + "/SamplePostWebForm.aspx");

                // By xpath
                browser.FindElement(By.XPath("//input[@name='Button1']")).Click();
                browser.WaitForPageLoaded();

                // By Id
                browser.FindElement(By.Id("Button1")).Click();
                browser.WaitForPageLoaded();

                // By css selector
                browser.FindElement(By.CssSelector("#Button1")).Click();
                browser.WaitForPageLoaded();

                // Assert
                Assert.AreEqual("[Clicked!]", browser.FindElement(By.Id("TextBox1")).GetAttribute("value"));
            }
        }
        public void NavigateAndFindDomElementTest()
        {
            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser();

                // Act
                browser.Navigate().GoToUrl(AppInfo.VirtualPath + "/default.html");

                // Assert
                Assert.AreEqual("[This is my label]", browser.FindElement(By.Id("myLabel")).Text);
            }
        }
        public void NavigateAndButtonClickTest()
        {
            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser();

                // Act
                browser.Navigate().GoToUrl(AppInfo.VirtualPath + "/MySampleWebForm.aspx");

                // By Id
                browser.FindElement(By.Id("Button1")).Click();
                browser.WaitForPageLoaded();

                // Assert
                Assert.AreEqual("[Clicked!]", browser.FindElement(By.Id("TextBox1")).GetAttribute("value"));
            }
        }
        public void DeployNavigateAndFindDomElementTest()
        {
            // Arrange
            const string webSiteName = "TestEasyWebSite";

            var server = WebServer.Create();
            var appInfo = server.CreateWebApplication(webSiteName);
            server.DeployWebApplication(appInfo.Name, new List<DeploymentItem>
                {
                    new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName }
                });

            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser();

                // Act
                browser.Navigate().GoToUrl(appInfo.VirtualPath + "/default.html");

                // Assert
                Assert.AreEqual("[This is my label]", browser.FindElement(By.Id("myLabel")).Text);
            }
        }
        public void CustomServerAndBrowserUsingConfigTest()
        {
            // Arrange
            const string webSiteName = "TestEasyWAP";

            // Create server using Config settings
            WebServerSettings settings = new WebServerSettings
            {
                HostName = TestEasyConfig.Instance.Client.Remote ? Environment.MachineName : "",
                RootPhysicalPath = (TestEasyConfig.Instance.WebServer.Type.Equals("IISExpress", StringComparison.InvariantCultureIgnoreCase))
                    ? TestEasyHelpers.Tools.GetUniqueTempPath(webSiteName)
                    : ""
            };

            WebServer server = WebServer.Create(TestEasyConfig.Instance.WebServer.Type, settings);
            WebApplicationInfo appInfo = server.CreateWebApplication(webSiteName);
            server.DeployWebApplication(appInfo.Name, new List<DeploymentItem>
                {
                    new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName }
                });
            server.BuildWebApplication(webSiteName);
            
            // create browser object using config settings
            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser();

                // Act
                browser.Navigate().GoToUrl(appInfo.VirtualPath + "/SamplePostWebForm.aspx");

                browser.FindElement(By.XPath("//input[@name='Button1']")).Click();
                browser.WaitForPageLoaded();

                // Assert
                Assert.AreEqual("[Clicked!]", browser.FindElement(By.Id("TextBox1")).GetAttribute("value"));
            }
        }
        public void GetStatusCodeTest()
        {
            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser();

                // Act
                var httpStatusCode = browser.GetHttpStatusCode(AppInfo.VirtualPath + "/default.html");

                // Assert
                Assert.AreEqual(HttpStatusCode.OK, httpStatusCode);
            }
        }
        public void CustomServerAndBrowserTest()
        {
            // Arrange
            const string webSiteName = "TestEasyWAP";

            // Create server object
            WebServerSettings settings = new WebServerSettings
            {
                HostName = Environment.MachineName, // machine anme or empty (in this case localhost will be used)
                RootPhysicalPath = TestEasyHelpers.Tools.GetUniqueTempPath(webSiteName) // needed only when web server type is IISExpress
            };

            WebServer server = WebServer.Create("IISExpress", settings);
            WebApplicationInfo appInfo = server.CreateWebApplication(webSiteName);
            server.DeployWebApplication(appInfo.Name, new List<DeploymentItem>
                {
                    new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName }
                });
            server.BuildWebApplication(webSiteName);

            // create browser object
            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser(BrowserType.Ie, false/*, remote=true/false */);

                // Act
                browser.Navigate().GoToUrl(appInfo.VirtualPath + "/SamplePostWebForm.aspx");

                browser.FindElement(By.XPath("//input[@name='Button1']")).Click();
                browser.WaitForPageLoaded();

                // Assert
                Assert.AreEqual("[Clicked!]", browser.FindElement(By.Id("TextBox1")).GetAttribute("value"));
            }
        }
        public void SpecifyingBrowserCompatibilityModeForIe()
        {
            // Arrange
            const string webSiteName = "TestEasyWebSite";

            // create Virtual Application and deploy files
            WebServer server = WebServer.Create();
            WebApplicationInfo appInfo = server.CreateWebApplication(webSiteName);
            server.DeployWebApplication(appInfo.Name, new List<DeploymentItem>
                {
                    new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName }
                });

            server.SetCustomHeaders(
                Path.Combine(appInfo.PhysicalPath, "web.config"), 
                new Dictionary<string, string> { { "X-UA-Compatible", " IE=8"} });

            // create browser object using config settings
            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser(BrowserType.Ie, false);

                // Act
                browser.Navigate().GoToUrl(appInfo.VirtualPath + "/default.html");

                // Assert
                Assert.AreEqual("[This is my label]", browser.FindElement(By.Id("myLabel")).Text);
            }
        }
        public void DeployNavigateAndUploadFileTest()
        {
            // Arrange
            const string webSiteName = "TestEasyWAP";

            var server = WebServer.Create();
            var appInfo = server.CreateWebApplication(webSiteName);
            server.DeployWebApplication(appInfo.Name, new List<DeploymentItem>
                {
                    new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName }
                });
            server.BuildWebApplication(webSiteName);

            var fileToUpload = @"c:\temp\tempfile.txt";
            if (!File.Exists(fileToUpload))
            {
                if (!Directory.Exists(@"c:\temp"))
                {
                    Directory.CreateDirectory(@"c:\temp");
                }

                File.WriteAllText(fileToUpload, "some content");
            }

            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser();

                // Act
                browser.Navigate().GoToUrl(appInfo.VirtualPath + "/SamplePostWebForm.aspx");

                browser.FindElement(By.Id("fileUpload")).SendKeys(fileToUpload);
                browser.FindElement(By.XPath("//input[@name='Button1']")).Click();

                browser.WaitForPageLoaded();

                // Assert
                Assert.AreEqual("[Clicked!]", browser.FindElement(By.Id("TextBox1")).GetAttribute("value"));
            }
        }