Пример #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();
        }
Пример #3
0
 public void SearchAndWaitBySeleniumRemoteControl()
 {
     //not working on latest IE and FireFox versions
     ISelenium sel = new DefaultSelenium("localhost",4444, "*iehta", "http://www.google.com");
     sel.Start();
     sel.Open("http://www.google.com/");
     sel.Type("q", "FitNesse");
     sel.Click("btnG");
     sel.WaitForPageToLoad("3000");
 }
Пример #4
0
        /// <summary>
        /// Launches the Selenium RC and browser specified in the Environments.cs file
        /// </summary>
        public ISelenium LaunchBrowser(ISelenium browser)
        {
            browser = new DefaultSelenium(this.environment.host, this.environment.port, this.environment.browser, this.environment.baseURL);
            browser.Start();
            browser.SetTimeout(this.environment.timeout);
            browser.WindowMaximize();
            browser.WindowFocus();

            return browser;
        }
Пример #5
0
        public static ISelenium InitializeWebTest()
        {
            // ISelenium selenium = new DefaultSelenium("localhost", 4444, "*iexplore", startPage);
            ISelenium selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://localhost:4444");
            selenium.Start();

              //  selenium.Open(startPage);
            //selenium.WaitForPageToLoad("30000");

            return selenium;
        }
 protected override void Context_BeforeAllSpecs()
 {
     try
     {
         selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost/");
         selenium.Start();
     }
     catch (Exception ex)
     {
         startException = ex;
     }
 }
Пример #7
0
        public WebTestContext()
        {
            lock (locker)
            {
                ExpressUnitConfigurationSection config = (ExpressUnitConfigurationSection)System.Configuration.ConfigurationManager.GetSection("ExpressUnitConfiguration");

                Selenium = new DefaultSelenium(config.WebTestSettings.SeleniumHost, config.WebTestSettings.SeleniumPort, config.WebTestSettings.Browser, config.WebTestSettings.StartUrl);

                Selenium.Start();

                Selenium.Open(config.WebTestSettings.StartUrl);
            }
        }
Пример #8
0
 public void StartSeleniumShouldWorkWithSpecifiedURL()
 {
     selenium = new DefaultSelenium(processor, launcher, "myUrl");
     mockLauncher.Expect("Launch", "myUrl");
     selenium.Start();
 }
Пример #9
0
 public static DefaultSelenium GetClient(string url)
 {
     var selenium = new DefaultSelenium(seleniumServerHost, seleniumServerPort, GetTargetedBrowser(), url);
     selenium.Start();
     return selenium;
 }
        /// <summary>
        /// Creates an instance of selenium to be used by the user
        /// </summary>
        /// <param name="serverHost">the server hosting the site to be tested</param>
        /// <param name="serverPort">the port that selenium use for running</param>
        /// <param name="browserString">string holding the browser that we want to test in</param>
        /// <param name="browserUrl">Url to open to begin testing</param>
        /// <returns>Instance of selenium ready to use</returns>
        /// <exception cref="ArgumentNullException">This exception is thrown if any of the expected
        /// string arguments are passed as null or empty string</exception>
        public ISelenium CreateInstance(string serverHost, int serverPort, string browserString, string browserUrl)
        {
            if (string.IsNullOrEmpty(serverHost))
                throw new ArgumentNullException("serverHost");

            if (string.IsNullOrEmpty(browserString))
                throw new ArgumentNullException("browserString");

            if (string.IsNullOrEmpty(browserUrl))
                throw new ArgumentNullException("browserUrl");

            // If the actual selenium server isn't running then we need to start it up
            if (! SeleniumServerStarted)
                Server.Start();

            ISelenium newInstance = new DefaultSelenium(serverHost, serverPort, browserString, browserUrl);
            Instances.Add(newInstance);

            newInstance.Start();

            return newInstance;
        }
Пример #11
0
        static void Main(string[] args)
        {
            HtmlDocument doc = new HtmlDocument();
            List<string> list = new List<string>();
            HashSet<string> listposters = new HashSet<string>();
            int forumNumber = 0;
            string forumAddress = "";
            //List<string> list = new List<string>();
            ISelenium sel = new DefaultSelenium("localhost", 4444, "*chrome", forumAddress);
            sel.Start();
            sel.WindowMaximize();
            sel.Open("/");
            sel.Click("id=loginlink");
            sel.WaitForPageToLoad("30000");
            sel.Type("id=username", "");
            sel.Type("id=password", "");
            sel.Click("id=submit");
            sel.WaitForPageToLoad("30000");


            for (int y = 1; y < 14; y++)
            {
                sel.Open(string.Format("/vbulletin/forumdisplay.php?f=" + forumNumber + "&order=desc&page={0}", y));
                sel.WaitForPageToLoad("30000");

                var src = sel.GetHtmlSource();

                doc.LoadHtml(src);

                var links = doc.DocumentNode.SelectNodes("//a[@href]");

                var posters = from i in links
                              where i.OuterHtml.Contains("whoposted")
                              select i;

                var ln = from o in posters
                         select o.OuterHtml.ToString();

                foreach (var item in ln)
                {
                    LinkItem i = new LinkItem();


                    Match m2 = Regex.Match(item, @"href=\""(.*?)\""",
                    RegexOptions.Singleline);
                    if (m2.Success)
                    {
                        i.Href = m2.Groups[1].Value;
                    }

                    list.Add(i.Href.Replace("&amp;", "&"));
                }

            }

            foreach (var it in list)
            {
                sel.Open(string.Format("vbulletin/{0}", it));
                sel.WaitForPageToLoad("30000");

                var src = sel.GetHtmlSource();

                doc.LoadHtml(src);

                var links = doc.DocumentNode.SelectNodes("//a[@href]");

                var posters = from i in links
                              where i.OuterHtml.Contains("member")
                              select i;

                var ln = from o in posters
                         select o.InnerHtml.ToString();

                foreach (var item in ln)
                {
                    listposters.Add(item);
                }
            }


            sel.Close();



            //var links = doc.DocumentNode.SelectNodes("//a[@href]");
            //var links2 = doc.DocumentNode.G
            //var posters = from i in links
            //              where i.OuterHtml.Contains("lastposter")
            //              select i;

            //var link = from o in posters
            //           select o.OuterHtml;

            System.IO.File.WriteAllLines(@"C:\Users\William\Documents\CsharpRandom\SeleniumTest\AllPosters.txt", listposters);

            Console.Read();
        }
Пример #12
0
 public SeleniumWorldView()
 {
     Browser = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com");
     Browser.Start();
 }
 public void SetUp()
 {
     browser = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:49278");
     browser.Start();
 }
Пример #14
0
 public static ISelenium OpenChromeDriverRemote(string IP, int i, string website, string URL)
 {
     ISelenium selenium = new DefaultSelenium(IP, i, website, URL);
     selenium.Start();
     selenium.Open("/");
     return selenium;
 }