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


C# ChromeOptions.EnableMobileEmulation方法代码示例

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


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

示例1: Launch

        internal void Launch(bool mobile, string url = "https://www.bing.com/") {
            Quit();
            _viewModel.ResetProfileCommand.RaiseCanExecuteChanged();

            ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
            service.HideCommandPromptWindow = true;

            ChromeOptions options = new ChromeOptions();
            options.AddArgument("start-maximized");
            options.AddArgument("user-data-dir=" + App.Folder + "profile");

            if (mobile)
                options.EnableMobileEmulation("Google Nexus 5");

            try {
                _driver = new ChromeDriver(service, options);
                _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));

                _builder = new Actions(_driver);

                LogUpdate("Launching Chrome " + (mobile ? "Mobile" : "Desktop"), Colors.CadetBlue);

                if (url != null)
                    _driver.Navigate().GoToUrl(url);
            }
            catch (Exception ex) {
                LogUpdate("Error Launching Chrome " + (mobile ? "Mobile" : "Desktop") + "\r\n" + ex.Message, Colors.Red);
                service.Dispose();
            }
        }
开发者ID:dawson-freddie30,项目名称:binginator,代码行数:30,代码来源:MainModel.cs

示例2: CreateOptions

 /// <summary>
 /// Creates and returns ChromeOptions for a mobile device
 /// </summary>
 /// <param name="device"></param>
 /// <returns></returns>
 public ChromeOptions CreateOptions(string device)
 {
     ChromeOptions options = new ChromeOptions();
     options.EnableMobileEmulation(device);
     return options;
 }
开发者ID:koreyba,项目名称:lottosend,代码行数:11,代码来源:BuyGroupMultiDrawTicketTests.cs

示例3: InitializeMultiBrowserEmulatorDriver

        /// <summary>
        /// Gets the multi browser emulator web driver.
        /// </summary>
        /// <param name="testSettings">The test settings.</param>
        /// <param name="emulator">The emulator.</param>
        /// <param name="orientation">The device orientation.</param>
        /// <param name="testOutputHelper">The test output helper.</param>
        /// <returns></returns>
        public static ITestWebDriver InitializeMultiBrowserEmulatorDriver(TestSettings testSettings, Emulator emulator, DeviceOrientation orientation, ITestOutputHelper testOutputHelper)
        {
            ScreenShotCounter = 0;
            TestOutputHelper = testOutputHelper;
            testSettings.BrowserName = emulator + " " + orientation;
            testSettings = ValidateSavePaths(testSettings);
            //string driverLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
            //                        "\\MultiBrowser\\Drivers\\ChromeDrivers\\2.20\\chromedriver.exe";
            string driverLocation = Path.Combine(AssemblyDirectory, "chromedriver.exe");
            driverLocation = ValidateDriverPresentOrUnblocked(WebDriverType.ChromeDriver, driverLocation);

            var driverService = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverLocation),
                Path.GetFileName(driverLocation));
            ValidateDriverPresentOrUnblocked(WebDriverType.ChromeDriver, driverLocation);

            var currentInstallPath = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MultiBrowser", false) ??
                                     Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432node\MultiBrowser",
                                         false);
            string installPathValue = null;
            if (currentInstallPath != null)
            {
                installPathValue = (string) currentInstallPath.GetValue("Path");
            }
            if (installPathValue != null)
            {
                if (!installPathValue.EndsWith("\\"))
                {
                    installPathValue = installPathValue + "\\";
                }
            }

#if DEBUG
            installPathValue = @"C:\Projects\MobileEmulator\bin\Debug\x64\";
#endif
            var options = new ChromeOptions
            {
                LeaveBrowserRunning = false,
                BinaryLocation =
                    Path.Combine(installPathValue ?? @"C:\Program Files (x86)\MultiBrowser", "MultiBrowser Emulator.exe")
            };

            var emulatorSettings = MultiBrowser.GetMultiBrowserEmulators(emulator);
            if (orientation == DeviceOrientation.Portrait)
            {
                var mobileEmulationSettings = new ChromeMobileEmulationDeviceSettings
                {
                    UserAgent = emulatorSettings.DeviceUserAgent,
                    Width = emulatorSettings.DeviceWidth,
                    Height = emulatorSettings.DeviceHeight,
                    EnableTouchEvents = true,
                    PixelRatio = emulatorSettings.DevicePixelRatio
                };
                options.EnableMobileEmulation(mobileEmulationSettings);
                //options.AddAdditionalCapability("mobileEmulation", new
                //{
                //    deviceMetrics = new
                //    {
                //        width = emulatorSettings.DeviceWidth,
                //        height = emulatorSettings.DeviceHeight,
                //        pixelRatio = emulatorSettings.DevicePixelRatio
                //    },
                //    userAgent = emulatorSettings.DeviceUserAgent
                //});
            }
            else
            {
                var mobileEmulationSettings = new ChromeMobileEmulationDeviceSettings
                {
                    UserAgent = emulatorSettings.DeviceUserAgent,
                    Width = emulatorSettings.DeviceHeight,
                    Height = emulatorSettings.DeviceWidth,
                    EnableTouchEvents = true,
                    PixelRatio = emulatorSettings.DevicePixelRatio
                };
                options.EnableMobileEmulation(mobileEmulationSettings);
                

                //options.AddAdditionalCapability("mobileEmulation", new
                //{
                //    deviceMetrics = new
                //    {
                //        width = emulatorSettings.DeviceHeight,
                //        height = emulatorSettings.DeviceWidth,
                //        pixelRatio = emulatorSettings.DevicePixelRatio
                //    },
                //    userAgent = emulatorSettings.DeviceUserAgent
                //});
            }
#if DEBUG
            options.BinaryLocation = @"C:\Projects\MobileEmulator\bin\Debug\x64\MultiBrowser Emulator.exe";
#endif
            string authServerWhitelist = "auth-server-whitelist=" + testSettings.TestUri.Authority.Replace("www", "*");
//.........这里部分代码省略.........
开发者ID:Jayman1305,项目名称:Selenium.Extensions,代码行数:101,代码来源:WebDriverManager.cs


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