C# 如何使用WebDriver C从Google Chrome Emulator打开设备#
我有以下代码C# 如何使用WebDriver C从Google Chrome Emulator打开设备#,c#,google-chrome,selenium-webdriver,webdriver,emulation,C#,Google Chrome,Selenium Webdriver,Webdriver,Emulation,我有以下代码 [Binding] public class Setup { private readonly Context _context; public const int DefaultTimeOut = 10; public Setup(Context context) { _context = context; } public static IWebDriver Driver; [BeforeTestRu
[Binding]
public class Setup
{
private readonly Context _context;
public const int DefaultTimeOut = 10;
public Setup(Context context)
{
_context = context;
}
public static IWebDriver Driver;
[BeforeTestRun]
public static void SetUpBrowser()
{
ChromeOptions options = new ChromeOptions();
options.EnableMobileEmulation("Apple iPhone 6");
Driver = new ChromeDriver(options);
Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(DefaultTimeOut);
}
我希望能够使用Google Chrome的emulator运行浏览器,但不幸的是,我收到以下错误消息:“消息:已经有一个用于mobileEmulation功能的选项。请改用。参数名称:capabilityName”
如果我可以在SetUpBrowser方法之外使用它,那将更加有益,例如,在我测试中稍后运行的方法中,我想可能会将上述内容添加到ChromeOptions中,但我没有成功
我尝试上述方法的方式是:
[Binding]
public class Setup
{
private readonly Context _context;
public const int DefaultTimeOut = 10;
public Setup(Context context)
{
_context = context;
}
public static IWebDriver Driver = new ChromeDriver();
[BeforeTestRun]
public static void SetUpBrowser()
{
Driver.Manage().Window.Maximize();
Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(DefaultTimeOut);
}
我想切换到移动模拟器的方法是:
[Given(@"I am on the mobile website version")]
public void GivenIAddAmOnTheMobileWebsiteVersion()
{
ChromeOptions options = new ChromeOptions();
options.EnableMobileEmulation("Apple iPhone 6");
Cookie SetMobileCookie = new Cookie(VariableList.MobileCookieValue, "true");
MobileCookie = VariableList.MobileCookieValue;
_driver.Manage().Cookies.AddCookie(SetMobileCookie);
_driver.Click(ElementType.Id, VariableList.MemberLoginButton); //should be a new method
}
将文本更改为“iPhone 6”
它适用于我您必须将EnableMobileMulation与chrome上的参数相匹配 进入开发者模式>然后点击手机图标。在左上角,您可以找到可以使用的所有可用设备名称的列表 例如,如果你想使用iPhoneX,你的代码应该是这样的
options.EnableMobileEmulation("iPhone X");
options.EnableMobileEmulation("iPhone X");