DesiredCapabilities已过时 [英] DesiredCapabilities is obsolete

查看:497
本文介绍了DesiredCapabilities已过时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前有以下代码,以便以其他用户身份运行驱动程序.

I used to have the following code in order to run the driver as different user.

 public static IWebDriver RunIEAsDifferentUser(string User,string Password)
    {

        var capabilitiesInternet = DesiredCapabilities.InternetExplorer();
        capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);
        capabilitiesInternet.SetCapability("EnsureCleanSession ", true);
        RunAs("C:\\Exlporer/IEDriverServer.exe", User, Password);
        _webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), capabilitiesInternet, TimeSpan.FromSeconds(300));
        return _webdriverIE;

    }
    public static void RunAs(string path, string username, string password)
    {
        ProcessStartInfo myProcess = new ProcessStartInfo(path);
        myProcess.UserName = username;
        myProcess.Password = MakeSecureString(password);
        myProcess.UseShellExecute = false;
        myProcess.LoadUserProfile = true;
        myProcess.Verb = "runas";
        myProcess.Domain = "DOM001";
        Process.Start(myProcess);
    }

    public static SecureString MakeSecureString(string text)
    {
        SecureString secure = new SecureString();
        foreach (char c in text)
        {
            secure.AppendChar(c);
        }

        return secure;
    }

问题是我收到警告:DesiredCapabilities is obsolete,但我不确定要使它继续工作必须做什么.

The thing is that I'm getting warning :DesiredCapabilities is obsolete and I'm not sure what I have to do in order to keep this working.

有问题的行是:_webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), capabilitiesInternet, TimeSpan.FromSeconds(300)); 我尝试将其更改为InternetExplorerOptions caps = new InternetExplorerOptions();. 不幸的是,RemoteWebDriver现在只接受Icapabilities.

The problematic line is : _webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), capabilitiesInternet, TimeSpan.FromSeconds(300)); I have tried changing it to InternetExplorerOptions caps = new InternetExplorerOptions();. Unfortunately , the RemoteWebDriver only accept Icapabilities now.

推荐答案

解决方案位于警告消息的结尾

The solution is at the end of the warning message

要与Java远程服务器或网格一起使用,请使用InternetExplorerOptions类的ToCapabilites方法.

For use with the Java remote server or grid, use the ToCapabilites method of the InternetExplorerOptions class.

InternetExplorerOptions options = new InternetExplorerOptions();
options.AddAdditionalCapability("ignoreProtectedModeSettings", true);
options.AddAdditionalCapability("EnsureCleanSession", true);
_webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), options.ToCapabilities(), TimeSpan.FromSeconds(300));

这篇关于DesiredCapabilities已过时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆