我有以下代码,
[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的模拟器运行浏览器,但不幸的是,我收到以下错误消息:“消息:已经有一个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);
}
我想切换到Mobile Emulator的方法是:
[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
}
答案 0 :(得分:1)
将文字更改为“iPhone 6”
ChromeOptions options = new ChromeOptions();
options.EnableMobileEmulation("iPhone 6");
IWebDriver driver = new ChromeDriver(options);
它对我有用
答案 1 :(得分:0)