Пример #1
0
 static void Main(string[] args)
 {
     ISelenium selenium;
     selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.baidu.com");
     selenium.Start();
     selenium.WindowMaximize();
     selenium.Open("/");
     selenium.Click("id=kw");
     selenium.Type("id=kw", "shinetech");
     selenium.Click("id=su");
     for (int second = 0; ; second++)
     {
         if (second >= 60)
         {
             Console.WriteLine("Locate element failed");
         }
         try
         {
             if (selenium.IsElementPresent("//div[@id='1']")) break;
         }
         catch (Exception)
         { }
         System.Threading.Thread.Sleep(1000);
     }
     selenium.Click("//div[@id='1']/h3/a");
     selenium.Stop();
 }
Пример #2
0
        public void BuildDeployAnTest()
        {
            var processStartInfo = new ProcessStartInfo{
                FileName = @"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe",
                Arguments = @"/nologo /clp:ErrorsOnly WebApplication\WebApplication.csproj",
                WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory,
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };
            Process buildProcess = Process.Start(processStartInfo);
            buildProcess.WaitForExit();
            Assert.AreEqual(0, buildProcess.ExitCode, "Compilation error: " + buildProcess.StandardOutput.ReadToEnd());

            Process webServerProcess = Process.Start(new ProcessStartInfo{
                FileName = @"C:\Program Files\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.EXE",
                Arguments = "/port:12345 /path:\"" + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WebApplication") + "\"",
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
                CreateNoWindow = true
            });

            Process seleniumRcProcess = Process.Start(new ProcessStartInfo{
                FileName = "java.exe",
                Arguments = @"-jar selenium-server\selenium-server.jar",
                WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory,
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
                CreateNoWindow = true,
            });

            ISelenium selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost:12345");
            selenium.Start();

            selenium.Open("/");
            selenium.Type("inputTextBox", "Test input");
            selenium.Click("actionButton");
            selenium.WaitForPageToLoad("30000");
            Assert.IsTrue(selenium.IsTextPresent("Test input"));

            try
            {
                selenium.Stop();
            }
            catch (Exception)
            {
                // Ignore errors if unable to close the browser
            }

            seleniumRcProcess.Kill();
            webServerProcess.Kill();
        }