简体   繁体   English

如何在 C# 中使用 AddAdditionalCapability 设置 Saucelabs 隧道标识符?

[英]How to get Saucelabs tunnelidentifier set up using AddAdditionalCapability in C#?

Here is my sample code which I tried but I cannot get the tunnelidentifier set up and launch test url.这是我尝试过的示例代码,但我无法设置隧道标识符并启动测试 url。 Other than generic sites which are not blocked by proxy.除了没有被代理阻止的通用网站。 Any help is appreciated.任何帮助表示赞赏。 Thanks谢谢

  [Test]
    public void SimpleTest1()
    {
        Uri sauceHubURL = new Uri("https://USERNAME:SOMEACCESSKEY@123.saucelabs.com:443/wd/hub");
        InternetExplorerOptions options = new InternetExplorerOptions();
        options.AddAdditionalCapability("parentTunnel", "PQSauceLabs");
        options.AddAdditionalCapability("tunnelIdentifier", "Mys-sauce-Tests");
        options.AddAdditionalCapability("EnsureCleanSession", true);
        string url = "https://www.google.com";
        string companyurl = "https://www.sample.com";
        
        var remoteDriver = new RemoteWebDriver(sauceHubURL, options.ToCapabilities(), TimeSpan.FromSeconds(300));
        remoteDriver.Navigate().GoToUrl(url);
    
        //remoteDriver.SwitchTo().Alert().SetAuthenticationCredentials("q25215", "test#");
        //IAlert alert = remoteDriver.SwitchTo().Alert();
        //alert.SendKeys("q25215"+ Keys.Tab + "test#" + Keys.Tab);
        //alert.Accept();

        string title = remoteDriver.Title;
        Console.WriteLine("Getting the page title: " + title);
        NUnit.Framework.Assert.AreEqual(title, "Google", "Compared values not equal");
        remoteDriver.Quit();

    }

I'm guessing this was run using the W3C Selenium bindings, so the sauce-specific options like parentTunnel need to be namespaced under sauce:options :我猜这是使用 W3C Selenium 绑定运行的,所以像parentTunnel这样的特定酱汁选项需要在sauce:options下命名:

            var driverOptions = new FirefoxOptions();
            driverOptions.PlatformName = "macOS 10.13";

            var sauceOptions = new Dictionary<string, object>();
            sauceOptions.Add("username", sauceUserName);
            sauceOptions.Add("accessKey", sauceAccessKey);
            sauceOptions.Add("name", TestContext.CurrentContext.Test.Name);
            sauceOptions.Add("parentTunnel", "Mys-sauce-Tests");
            sauceOptions.Add("tunnelIdentifier", "PQSauceLabs");

            driverOptions.AddAdditionalOption("sauce:options", sauceOptions);
            //create a new Remote driver that will allow your test to send
            //commands to the Sauce Labs grid so that Sauce can execute your tests
            _driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"),
                driverOptions);

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

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