当前位置: 首页>>代码示例>>C#>>正文


C# RemoteWebDriver.Manage方法代码示例

本文整理汇总了C#中OpenQA.Selenium.Remote.RemoteWebDriver.Manage方法的典型用法代码示例。如果您正苦于以下问题:C# RemoteWebDriver.Manage方法的具体用法?C# RemoteWebDriver.Manage怎么用?C# RemoteWebDriver.Manage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenQA.Selenium.Remote.RemoteWebDriver的用法示例。


在下文中一共展示了RemoteWebDriver.Manage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateChromeGridDriver

        public static IWebDriver CreateChromeGridDriver(string profileName, string hubAddress)
        {
            if (hubAddress == null)
            {
                throw new ArgumentException("remoteAddress");
            }

            var chromeOptions = new ChromeOptions();
            if (!string.IsNullOrWhiteSpace(profileName))
            {
                var fileChars = Path.GetInvalidFileNameChars();
                var pathChars = Path.GetInvalidFileNameChars();
                var invalidChars = fileChars.Union(pathChars);

                profileName = String.Join("", profileName.Where(c => !invalidChars.Contains(c)));

                chromeOptions.AddArguments(String.Format("user-data-dir=c:\\ChromeProfiles\\{0}", profileName));
            }

            RemoteWebDriver Driver = new RemoteWebDriver(new Uri(hubAddress), chromeOptions.ToCapabilities());

            Driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 1, 0));
            Driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 1));
            Driver.Manage().Window.Maximize();
            return Driver;
        }
开发者ID:chriscore,项目名称:SpecDriver,代码行数:26,代码来源:WebDriver.cs

示例2: MyTestInitialize

 public void MyTestInitialize()
 {
     verificationErrors = new StringBuilder();
     DesiredCapabilities capability = DesiredCapabilities.Firefox();
     driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);
     driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
     driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(50));
     driver.Manage().Window.Maximize();
     driver.Navigate();
 }
开发者ID:sergueik,项目名称:selenium_java,代码行数:10,代码来源:Test.cs

示例3: ClassInit

        public static void ClassInit(TestContext context)
        {
            // Chrome specifics
            _webDriver = new ChromeDriver(@"C:\Tools");

            //Set page load timeout to 20 seconds (occasionally 5 secs is too tight after a deployment)
            _webDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(20));

            try
            {
                // Get the URL for the current environment (e.g. Dev, QA, Prod) as set in the release environment
                string releaseEnvironmentAppBaseURL = Environment.GetEnvironmentVariable("WebAppName");
                if (releaseEnvironmentAppBaseURL != null)
                {
                    _webAppBaseURL = "http://" + releaseEnvironmentAppBaseURL + ".azurewebsites.net";
                    Console.WriteLine("WebApp Base URL found: " + _webAppBaseURL);
                }
                else
                {
                    // The environment variable exists but has no value, so use a default
                    _webAppBaseURL = _defaultWebAppBaseURL;
                    Console.WriteLine("WebApp Base URL not set, using default: " + _defaultWebAppBaseURL);
                }
            }
            catch (Exception Ex)
            {
                // The environment variable probably doesn't exist (might be called from within VS)
                Console.WriteLine("Exception thrown accessing environment variable: " + Ex.Message);
                Console.WriteLine("Using default: " + _defaultWebAppBaseURL);
                _webAppBaseURL = _defaultWebAppBaseURL;
            }
        }
开发者ID:gidavies,项目名称:SimpleDemoApp,代码行数:32,代码来源:ChromeTests.cs

示例4: getWebDriver

        public static RemoteWebDriver getWebDriver(string DriverName = "")
        {
            if (WebDriver == null)
            {
                switch (DriverName)
                {
                    case "IE":
                        var options = new InternetExplorerOptions();
                        options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                        WebDriver = new InternetExplorerDriver(/*Settings.CurrentSettings.BrowserPath,*/ options);

                        //IeCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
                //WebDriver = new InternetExplorerDriver(ieCapabilities);
                        break;
                    case "CHROME":
                    default:
                        WebDriver = new ChromeDriver();
                        break;
                }
                /*System.setProperty("webdriver.ie.driver", "src\\test\\resources\\drivers\\IEDriverServer.exe");
                DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
                ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
                webDriver = new InternetExplorerDriver(ieCapabilities);
                webDriver.manage().timeouts()
                        .implicitlyWait(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
                maximizeBrowser();*/
                WebDriver.Manage().Timeouts()
                        .ImplicitlyWait(TimeSpan.FromSeconds(WAIT_TIMEOUT));
                MaximizeBrowser();
            }

            return WebDriver;
        }
开发者ID:VNikita,项目名称:Test_auto,代码行数:33,代码来源:WebDriverSetup.cs

示例5: MyTestInitialize

        public static void MyTestInitialize(TestContext testContext)
        {
            verificationErrors = new StringBuilder();
            try
            {
                // driver = new InternetExplorerDriver(IE_DRIVER_PATH);

                DesiredCapabilities capability = DesiredCapabilities.Firefox();
                driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);

                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
                driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(50));

            }
            catch (Exception ex) { }
        }
开发者ID:HydAu,项目名称:PowershellUISamples,代码行数:16,代码来源:EmployeeControllerTest.cs

示例6: Selenium_Server_Test

        public void Selenium_Server_Test()
        {
            IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Firefox());
            driver.Url = "http://www.google.com";
            var searchBox = driver.FindElement(By.Id("lst-ib"));
            searchBox.SendKeys("Lotus flower");
            searchBox.SendKeys(Keys.Enter);

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            var imagetext = driver.FindElement(By.LinkText("Kuvahaku"));
            Assert.That(imagetext.Text, Is.EqualTo("Kuvahaku"));
            imagetext.Click();

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); //avoid error on no such element
            var imagelistId = driver.FindElement(By.Id("rg_s"));
            var fouthdivclass = imagelistId.FindElements(By.CssSelector("[class='rg_di rg_el ivg-i']"))[1].FindElement(By.TagName("a"));
            fouthdivclass.Click();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            var ImageLink = driver.FindElement(By.LinkText("Näytä kuva"));
            ImageLink.Click();
        }
开发者ID:Qianfinland,项目名称:Net,代码行数:21,代码来源:Program.cs

示例7: BeforeScenario

        public void BeforeScenario()
        {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.SetCapability(CapabilityType.BrowserName, Environment.GetEnvironmentVariable("browserName"));
            capabilities.SetCapability(CapabilityType.Version, Environment.GetEnvironmentVariable("version"));
            capabilities.SetCapability(CapabilityType.Platform, Environment.GetEnvironmentVariable("platformOs"));
            capabilities.SetCapability("username", Environment.GetEnvironmentVariable("SAUCE_USERNAME"));
            capabilities.SetCapability("accessKey", Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY"));
            capabilities.SetCapability("name", ScenarioContext.Current.ScenarioInfo.Title);

            RemoteWebDriver webDriver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), capabilities, TimeSpan.FromSeconds(600));
            webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
            ScenarioContext.Current["driver"] = webDriver;
        }
开发者ID:KevinMarkVI,项目名称:CSharp-SpecFlow-Selenium,代码行数:14,代码来源:Hooks1.cs

示例8: Main

        static void Main(string[] args)
        {
            DesiredCapabilities capability = null;
            IWebDriver driver = null;
            for (int i = 1; i < 4; i++)
            {
                switch (i)
                {
                    case 1:
                        capability = DesiredCapabilities.Firefox();
                        capability.SetCapability("BrowserName", "firefox");
                        break;
                    case 2:
                        capability = DesiredCapabilities.Chrome();
                        capability.SetCapability("BrowserName", "chrome");
                        break;
                    case 3:
                        capability = DesiredCapabilities.InternetExplorer();
                        capability.SetCapability("BrowserName", "internet explorer");
                        break;
                    default:
                        return;
                }

                driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);
                driver.Manage().Window.Maximize();
                driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(10));
                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
                driver.Navigate().GoToUrl("http://www.baidu.com");
                IWebElement searchBox = driver.FindElement(By.Id("kw"));
                IWebElement searchButton = driver.FindElement(By.Id("su"));
                searchBox.SendKeys("Shinetech");
                searchButton.Click();
                driver.Dispose();
            }
        }
开发者ID:TylerTan,项目名称:SeleniumGridDemo,代码行数:36,代码来源:Program.cs

示例9: TitleIsCorrect

        public void TitleIsCorrect()
        {
            for (int i = 0; i < 30; i++)
            {
                //IWebDriver webDriver = new ChromeDriver();
                //IWebDriver webDriver = new PhantomJSDriver();
                // TODO ^^ So instead of this we do this:
                IWebDriver webDriver = new RemoteWebDriver(new Uri("http://localhost:4444"), new DesiredCapabilities());
                // ^^ this is how you'd call a Selenium Grid server, the desired capability is used to ask for a particular browser (or set of configuration)
                // you will need to first run phantomjs.exe --webdriver=4444
                // you might run a local instance simply by calling java -jar selenium-grid.jar or something, then register browsers with it
                // you could also call source labs, browserstack or whatever

                // When using ChromeDriver you could try reuisng a webdriver session,
                // but then you could get failing tests interfering with other tests, you can do some work to mitigation this and use things like cookejars to isolate tests
                // but with PhantomJS giving you a new session each time, you don't have to worry about it.

                // we had it so that failures would output a screenshot (that would get attached to the test result), this is available through the webdriver api and is support by PhantomJS
                // we also had the webdriver switchable by config, so that we could quickly switch to a full browser to troubleshoot bugs

                webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));


                webDriver.Navigate().GoToUrl("http://localhost:3988/");
                var header = webDriver.FindElement(By.CssSelector("div.jumbotron > h1"));
                header.Text.ShouldBe("ASP.NET");
            }

            //var liCount = _webDriver.FindElement(By.Id("test-content")).FindElements(By.TagName("li")).Count;

            //liCount.ShouldBe(3);

            // This sort of fiddly stuff, i.e. elements with timeouts, domReady etc... are not as bad as I remember.
            // because FindElements will wait using the _webdriver implicit wait settings (set when we construct the WebDriver object)
            // but what if there was already an <li> in the list, it fails! what if the dom exists, but then we replace it with ajax

            // thats when you might do something explicit like this:

            //var fiveSecondWait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(5));
            //fiveSecondWait.Until(wd =>
            //{
            //    // do some checks
            //    return true;
            //});

            // We used to queue some javascript so that we know that all synchrounous task had been parse and completed by the browser and we were ready to rock
        }
开发者ID:slang25,项目名称:SampleAutomatedWebTesting,代码行数:47,代码来源:Tests.cs

示例10: _Setup

        /// <summary>starts a sauce labs sessions</summary>
        /// <param name="browser">name of the browser to request</param>
        /// <param name="version">version of the browser to request</param>
        /// <param name="platform">operating system to request</param>
        private IWebDriver _Setup(string browser, string version, string platform)
        {
            // construct the url to sauce labs
            Uri commandExecutorUri = new Uri("<http://ondemand.saucelabs.com/wd/hub>");
            // set up the desired capabilities
            DesiredCapabilities desiredCapabilites = new DesiredCapabilities(browser, version, Platform.CurrentPlatform); // set the desired browser
            desiredCapabilites.SetCapability("platform", platform); // operating system to use
            desiredCapabilites.SetCapability("username", Constants.SAUCE_LABS_ACCOUNT_NAME); // supply sauce labs username
            desiredCapabilites.SetCapability("accessKey", Constants.SAUCE_LABS_ACCOUNT_KEY);  // supply sauce labs account key
            desiredCapabilites.SetCapability("name", TestContext.CurrentContext.Test.Name); // give the test a name

            // start a new remote web driver session on sauce labs
            var _Driver = new RemoteWebDriver(commandExecutorUri, desiredCapabilites);
            _Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));

            // navigate to the page under test
            _Driver.Navigate().GoToUrl("<https://saucelabs.com/test/guinea-pig>");

            return _Driver;
        }
开发者ID:saucelabs-sample-scripts,项目名称:C-Sharp-Selenium,代码行数:24,代码来源:GuineaPigTests.cs

示例11: Execute

        public CommandExecutionResult Execute(UITestSuite[] testSuites, WebAutoConfiguration configuration)
        {
            if (!Directory.Exists(configuration.ResultsFolder))
                Directory.CreateDirectory(configuration.ResultsFolder);

            CommandExecutionResult result = new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty };
            Assembly assembly = Assembly.LoadFrom("WebAuto.Commands.dll");

            var uiMap = Repository.GetUIMap(configuration.UIMapFile);
            foreach (var testSuite in testSuites)
            {
                Console.WriteLine(testSuite.Name);
                foreach (var testcase in testSuite)
                {
                    Console.WriteLine(string.Format(" {0}", testcase.Value.GroupName));
                    var dataBucket = Repository.GetData(Path.Combine(configuration.DataDirectory, testcase.Value.GroupName + configuration.FileExtension));

                    IWebDriver driver = null;
                    switch (configuration.Browser)
                    {
                        case "firefox":
                            driver = new FirefoxDriver();
                            break;
                        case "chrome":
                            driver = new ChromeDriver();
                            break;
                        case "ie":
                            driver = new InternetExplorerDriver();
                            break;
                        case "htmlunit":
                            driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnitWithJavaScript());
                            break;
                        default:
                            driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnit());
                            break;
                    }
                    driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 20));
                    new Utility().ResizeTest(driver);

                    var usedData = new Dictionary<string, int>();
                    foreach (var sequence in testcase.Value.CommandGroups.Sequences)
                    {
                        var commandContainer = new UICommandContainer();
                        commandContainer.Name = sequence.Value.Name;

                        Console.WriteLine(string.Format("  {0}", sequence.Value.Name));

                        if (!usedData.ContainsKey(sequence.Value.Name))
                        {
                            usedData.Add(sequence.Value.Name, 1);
                        }
                        else
                        {
                            usedData[sequence.Value.Name]++;
                        }

                        var dataName = usedData[sequence.Value.Name] > 1
                                       	? string.Format("{0}({1})", sequence.Value.Name.ToLower(), usedData[sequence.Value.Name])
                                       	: sequence.Value.Name.ToLower();

                        // check if sequence uses a list table
                        if (dataBucket.DataTables.ContainsKey(dataName))
                        {
                            var table = dataBucket.DataTables[dataName];
                            foreach (var dataValue in table)
                            {
                                foreach (var command in sequence.Value.Commands)
                                {
                                    var c = new UICommand()
                                    {
                                        CommandName = command.CommandName,
                                        Description = command.Description ?? string.Empty,
                                        Target = command.Target ?? string.Empty,
                                        Value = command.Value ?? string.Empty
                                    };
                                    var cmd = PrepareCommand(c, dataValue, uiMap);
                                    Console.WriteLine(string.Format("   {0} {1} {2}",
                                        cmd.CommandName,
                                        cmd.Target,
                                        cmd.Value));

                                    string className = "WebAuto.Commands." + Utility.UppercaseFirst(cmd.CommandName) + "Command";
                                    Type t = assembly.GetType(className);
                                    var cmd2 = (WebAuto.Interfaces.Command)Activator.CreateInstance(t);
                                    cmd2.CommandName = cmd.CommandName;
                                    cmd2.Description = cmd.Description;
                                    cmd2.Target = cmd.Target;
                                    cmd2.Value = cmd.Value;

                                    ((ICommand) cmd2).Execute(driver);
                                }
                            }
                        }
                        else
                        {
                            foreach (var command in sequence.Value.Commands)
                            {
                                var c = new UICommand()
                                {
                                    CommandName = command.CommandName,
//.........这里部分代码省略.........
开发者ID:ngocluu263,项目名称:WebAuto,代码行数:101,代码来源:TestManager.cs

示例12: SauceLabsDriverInstance

        private static IWebDriver SauceLabsDriverInstance(string platform, string browser, string version, string testName)
        {
            // construct the url to sauce labs
            Uri commandExecutorUri = new Uri(SauceLabsConstants.Url);

            // set up the desired capabilities
            DesiredCapabilities desiredCapabilites = new DesiredCapabilities(browser, version, Platform.CurrentPlatform); // set the desired browser
            desiredCapabilites.SetCapability("platform", platform); // operating system to use
            desiredCapabilites.SetCapability("username", SauceLabsConstants.AccountName); // supply sauce labs username
            desiredCapabilites.SetCapability("accessKey", SauceLabsConstants.AccountKey);  // supply sauce labs account key
            //desiredCapabilites.SetCapability("name", TestContext.CurrentContext.Test.Name); // give the test a name
            desiredCapabilites.SetCapability("name", testName);

            // start a new remote web driver session on sauce labs
            var driver = new RemoteWebDriver(commandExecutorUri, desiredCapabilites);
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
            driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30));

            return driver;
        }
开发者ID:dburriss,项目名称:UiMatic,代码行数:20,代码来源:DriverFactory.cs

示例13: SetupTest

 public void SetupTest()
 {
     _driver = new FirefoxDriver();
     _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
 }
开发者ID:mjhilton,项目名称:TestStack.Seleno,代码行数:5,代码来源:WebTestBase.cs

示例14: SetupSauceLabsDirver

        private IWebDriver SetupSauceLabsDirver()
        {
            // construct the url to sauce labs
            var commandExecutorUri = new Uri("http://ondemand.saucelabs.com/wd/hub");

            // set up the desired capabilities
            var desiredCapabilites = new DesiredCapabilities(SaucelabsBrowser, SaucelabsBrowserVersion, Platform.CurrentPlatform);
            // set the desired browser
            desiredCapabilites.SetCapability("platform", SaucelabsPlatform); // operating system to use
            desiredCapabilites.SetCapability("username", Constants.SAUCE_LABS_ACCOUNT_NAME);
            // supply sauce labs username
            desiredCapabilites.SetCapability("accessKey", Constants.SAUCE_LABS_ACCOUNT_KEY);
            // supply sauce labs account key
            desiredCapabilites.SetCapability("name", "IMS DEMO test"); // give the test a name

            // start a new remote web driver session on sauce labs
            IWebDriver remoteDriver = new RemoteWebDriver(commandExecutorUri, desiredCapabilites);
            remoteDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
            remoteDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30));

            // navigate to the page under test
            //remoteDriver.Navigate().GoToUrl("https://saucelabs.com/test/guinea-pig");

            return remoteDriver;
        }
开发者ID:rainymaple,项目名称:WebTester,代码行数:25,代码来源:UnitTest1.cs

示例15: PageBase

 public PageBase(RemoteWebDriver driver)
 {
     _driver = driver;
     driver.Manage().Window.Maximize();
 }
开发者ID:BO45,项目名称:NzbDrone,代码行数:5,代码来源:PageBase.cs


注:本文中的OpenQA.Selenium.Remote.RemoteWebDriver.Manage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。