如何使用WebDriver C从Google Chrome模拟器打开设备#

问题描述 投票:0回答:1

我有以下代码,

[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);
    }

我希望能够使用谷歌Chrome的模拟器运行浏览器,但不幸的是,我收到以下错误消息:“消息:已经有一个mobilemmulation功能的选项。请使用替代。参数名称: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
    }
c# google-chrome selenium-webdriver webdriver emulation
1个回答
1
投票

将文字更改为“iPhone 6”

        ChromeOptions options = new ChromeOptions();
        options.EnableMobileEmulation("iPhone 6");
        IWebDriver driver = new ChromeDriver(options);

这个对我有用

© www.soinside.com 2019 - 2024. All rights reserved.