Exemple #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();
 }
        private SeleniumProvider CreateBrowser()
        {
            if (_url == null)
                throw new NullReferenceException(
                    "No [URL] attribute was defined, either define [URL], or pass the URL of the start page to BrowserAttribute's constructor");

            switch (_browser)
            {
                case "Internet Explorer 6":
                    Browser = new DefaultSelenium("localhost", 4444, "*iexplore", _url);
                    break;
                case "Internet Explorer 7":
                    Browser = new DefaultSelenium("localhost", 4444, "*iexplore", _url);
                    break;
                case "Internet Explorer 8":
                    Browser = new DefaultSelenium("localhost", 4444, "*iexplore", _url);
                    break;
                case "Firefox 2":
                    Browser = new DefaultSelenium("localhost", 4444, "*firefox", _url);
                    break;
                case "Firefox 3":
                    Browser = new DefaultSelenium("localhost", 4444, "*firefox", _url);
                    break;
                case "Firefox 3.5":
                    Browser = new DefaultSelenium("localhost", 4444, "*firefox", _url);
                    break;
                case "Google Chrome":
                    Browser = new DefaultSelenium("localhost", 4444, "*googlechrome", _url);
                    break;
                case "Opera":
                    Browser = new DefaultSelenium("localhost", 4444, "*opera", _url);
                    break;
            }
            return new SeleniumProvider(Browser);
        }
        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();
        }
Exemple #4
0
        public ISelenium CreateInstance(BrowserClient browserClient, BrowserSetup browserSetup)
        {
            ISelenium selenium = new DefaultSelenium(browserClient.Address
                                                     , browserClient.Port
                                                     , browserSetup.Profile
                                                     , browserSetup.BaseUrl.ToString());

            return selenium;
        }
 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");
 }
Exemple #6
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;
        }
        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;
     }
 }
        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);
            }
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SeleniumTesterBase"/> class.
        /// </summary>
        public TestFixtureWeb()
            : base()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

            browserType = (BrowserType)Enum.Parse(
                                            typeof(BrowserType),
                                            ConfigurationManager.AppSettings["SELENIUM_BROWSER"],
                                            true);
            testMachine = ConfigurationManager.AppSettings["SELENIUM_HOST"];
            seleniumPort = int.Parse(
                ConfigurationManager.AppSettings["SELENIUM_PORT"],
                CultureInfo.InvariantCulture);
            seleniumSpeed = ConfigurationManager.AppSettings["SELENIUM_SPEED"];
            browserUrl = ConfigurationManager.AppSettings["SELENIUM_URL"];

            string browserExe;

            switch (browserType)
            {
                case BrowserType.InternetExplorer:
                    browserExe = "*iexplore";
                    break;
                case BrowserType.Firefox:
                    browserExe = "*firefox";
                    break;

                default:
                    throw new NotSupportedException();
            }

            selenium = new DefaultSelenium(testMachine, seleniumPort, browserExe, browserUrl);
            //selenium.SetTimeout("1000000");

            Console.WriteLine("Started Selenium session (browser type={0})", browserType);
        }
Exemple #11
0
 public void RegisterServices(ITestContext context)
 {
     var selenium = new DefaultSelenium("localhost", 4444, @"*firefox C:\Program Files (x86)\Mozilla Firefox\firefox.exe", "http://localhost:60691");
     context.Store<IBrowserDriver>(new SeleniumBrowserDriver(selenium));
 }
 public SeleniumWorldView()
 {
     Browser = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com");
     Browser.Start();
 }
Exemple #13
0
 public static DefaultSelenium GetClient(string url)
 {
     var selenium = new DefaultSelenium(seleniumServerHost, seleniumServerPort, GetTargetedBrowser(), url);
     selenium.Start();
     return selenium;
 }
 public void SetUp()
 {
     browser = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:49278");
     browser.Start();
 }
 public void StartSeleniumShouldWorkWithSpecifiedURL()
 {
     selenium = new DefaultSelenium(processor, launcher, "myUrl");
     mockLauncher.Expect("Launch", "myUrl");
     selenium.Start();
 }
		public void SetupTest()
		{
			mockProcessor = new DynamicMock(typeof (ICommandProcessor));
			processor = (ICommandProcessor) mockProcessor.MockInstance;
			selenium = new DefaultSelenium(processor);
		}
Exemple #17
0
        /// <summary>
        ///  Method to get the instance of selenium version 1.3
        /// </summary>
        /// <returns>Selenium instance</returns>
        public static Selenium.DefaultSelenium GetSeleniumOne()
        {
            try
            {
                if (selenium == null)
                {
                    selenium = new Selenium.WebDriverBackedSelenium(driver, driver.Url);
                }
                try
                {
                    selenium.Start();
                }
                catch (Exception)
                {

                }
                return selenium;
            }
            catch (Exception)
            {
                throw;
            }
        }
 public void SetupTest()
 {
     mockProcessor = new DynamicMock(typeof (ICommandProcessor));
     processor = (ICommandProcessor) mockProcessor.MockInstance;
     mockLauncher = new DynamicMock(typeof(IBrowserLauncher));
     launcher = (IBrowserLauncher) mockLauncher.MockInstance;
     selenium = new DefaultSelenium(processor, launcher);
 }
        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();
        }
        /// <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;
        }
Exemple #21
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;
 }