本文整理汇总了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();
}
}
示例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;
}
示例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", "*");
//.........这里部分代码省略.........