我正在遵循browserstack的documentation上关于使用自动化的问题,当前遇到错误,并且对URI有点困惑。

我的代码如下所示:

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace SeleniumTest {
  class Program {
    static void Main(string[] args) {
      IWebDriver driver;
      DesiredCapabilities capability = DesiredCapabilities.Firefox();
      capability.SetCapability("browserstack.user", "USERNAME");
      capability.SetCapability("browserstack.key", "ACCESS_KEY");

      driver = new RemoteWebDriver(
        new Uri("http://hub.browserstack.com/wd/hub/"), capability
      );
      driver.Navigate().GoToUrl("http://www.google.com");
      Console.WriteLine(driver.Title);

      IWebElement query = driver.FindElement(By.Name("q"));
      query.SendKeys("Browserstack");
      query.Submit();
      Console.WriteLine(driver.Title);

      driver.Quit();
    }
  }
}


我对uri http://hub.browserstack.com/wd/hub/感到困惑

我不明白这个URI是什么?

为什么需要它?

为什么这行代码http://hub.browserstack.com/wd/hub/给我这样的错误,例如


  “您必须经过身份验证才能访问此URL”
  
  状态码= 403


确切的错误如下


  类型“ OpenQA.Selenium.WebDriverException”的异常发生在
  WebDriver.dll,但未在用户代码中处理
  
  附加信息:意外错误。
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  McAfee Web Gateway-通知-身份验证
  需要
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  认证方式
  需要
  
  
  
  
  
    

<td class="contentData">

  You must be authenticated to access this URL.

</td>

  
    
  
  
  
  
  
     urlprotocol =“ http”;
  
     statuscode = 403;
  
  
  
     if(statuscode == 401 && urlprotocol ==“ ftp”){

  document.write("<form name=\"ftpform\" method=\"get\" action=\"\">");

  document.write("<table class=\"contentData\">");

  document.write("<tr><td class=\"contentData\" colspan=2>Please enter your credentials in the form below and click \"Access FTP\"

  
  如果您的浏览器不显示FTP身份验证提示,则单击按钮
  网站。”);

  document.write("<tr><td class=\"contentData\">Username:</td><td><input type=\"text\"

  
  id = \“ ftpUsername \” name = \“ ftpUsername \” size = 40 />“);

  document.write("<tr><td class=\"contentData\">Password:</td><td><input type=\"password\"

  
  id = \“ ftpPassword \” name = \“ ftpPassword \” size = 40 />“);

  document.write("<tr><td class=\"contentData\" colspan=2 align=center><input type=\"button\" onclick=\"redirectToFTP();\"

  
  value = \“访问FTP \” />“);

  document.write("</table>");

  document.write("</form>");

  
     }
  
  
  
     函数redirectToFTP(){

  var username=unescape(document.getElementById("ftpUsername").value);

  var password=unescape(document.getElementById("ftpPassword").value);

  location.href = "ftp://"+username+":"+password+"@hub.browserstack.com:80/wd/hub/session"

  
     }
  
  
  
  
  
  
  
  
  
    

<td class="infoData">

  <b>URL: </b><script type="text/javascript">break_line("http://hub.browserstack.com/wd/hub/session");</script><br />

</td>

  
    
  
  
  
  代理:XXXXXXX规则:身份验证:NTLM
  
  
  
  
  
  


我刚刚用XXXXXX替换了代理

我也在使用真正的完全许可的Browserstack帐户用户名/密码,但是出于这个问题的目的,请在此处找到示例。用户名“ USERNAME”,密码“ ACCESS_KEY”。

任何反馈都非常感谢,谢谢。

最佳答案

如果仅用有效的浏览器堆栈凭据替换USERNAMEACCESS_KEY,则C#代码运行良好。如果仍然出现403错误,请仔细检查您的凭据。

通过browserstack,您可以在由browserstack管理的计算机上远程运行测试,而不是在自己的计算机上本地运行测试。 URL http://hub.browserstack.com/wd/hub/是您浏览器堆栈的入口,通过它们可以验证谁在运行测试,因此您提供了用户名和access_key。

关于selenium - Browserstack Selenium Automation HUB,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36895243/

10-09 00:36