简体   繁体   English

DesiredCapabilities已过时

[英]DesiredCapabilities is obsolete

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

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. 问题是我正在收到警告: DesiredCapabilities is obsolete ,我不知道为了保持这种工作,我必须做些什么。

The problematic line is : _webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), capabilitiesInternet, TimeSpan.FromSeconds(300)); 有问题的行是: _webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), capabilitiesInternet, TimeSpan.FromSeconds(300)); I have tried changing it to InternetExplorerOptions caps = new InternetExplorerOptions(); 我已经尝试将其更改为InternetExplorerOptions caps = new InternetExplorerOptions(); . Unfortunately , the RemoteWebDriver only accept Icapabilities now. 不幸的是, RemoteWebDriver只接受Icapabilities现在。

The solution is at the end of the warning message 解决方案在警告消息的末尾

For use with the Java remote server or grid, use the ToCapabilites method of the InternetExplorerOptions class. 要与Java远程服务器或网格一起使用,请使用InternetExplorerOptions类的ToCapabilites方法。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM