0

I am following browserstack's documentation on using automation and currently getting an error and am abit confused about the URI.

My code looks like the following:

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

I am confused about the uri http://hub.browserstack.com/wd/hub/

I don't understand what is this URI ?

why is it needed for ?

why does this line of code http://hub.browserstack.com/wd/hub/ give me errors such as

"You must be authenticated to access this URL"

Status Code=403

The exact error is below

An exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll but was not handled in user code

Additional information: Unexpected error.

McAfee Web Gateway - Notification - Authentication Required

Authentication Required
<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\"
button if your browser doesn't present authentication prompt for FTP sites.");
  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=\"Access FTP\" />");
  document.write("</table>");

  document.write("</form>");
} function 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>

Proxy: XXXXXXX

Rule: Authenticate: NTLM


I have just replaced the Proxy with XXXXXX

I am also using a real fully licensed Browserstack Account Username/Password, but for the purpose of this question have the examples there. "USERNAME" for username and "ACCESS_KEY" for password.

any feedback is much appreciated, thank you.

arjwolf
  • 11
  • 3

3 Answers3

1

Your C# code runs fine if you simply replace the USERNAME and ACCESS_KEY with valid browserstack credentials. If you still get the 403 error, then double-check your credentials.

Through browserstack you can run your tests remotely on a machine managed by browserstack as opposed to running a test locally on your own machine. The url http://hub.browserstack.com/wd/hub/ is your entry point to browserstack by which they can verify who is running the tests and hence you supply a username and access_key.

sowa
  • 1,249
  • 16
  • 29
1

The URL http://hub.browserstack.com/wd/hub/ corresponds to BrowserStack's Selenium hub and it is required to run tests on BrowserStack. To run an automated (Selenium) test on BrowserStack, you need to point your tests to this Selenium Hub along with your Username and Automate key. Looking at the code snippet shared, I see you are passing the BrowserStack credentials correctly.

Checking the error stack trace shared, it seems you are behind a NTLM proxy. You will have to figure out a way to pass NTLM proxy details with your Selenium requests in C# to run your tests on BrowserStack. For example, if you were behind a Basic HTTP proxy, you could have configured your tests by adding the following lines to your config file:

<system.net>
 <defaultProxy useDefaultCredentials="true">
  <proxy usesystemdefault="True"/>
 </defaultProxy>
</system.net>

Would suggest mailing to support@browserstack.com, if you have more questions regarding this.

Umang Sardesai
  • 762
  • 6
  • 14
0

I could not figure out the spot but may be you can get an idea with below mentioned code which I'm using to connect it through

        DesiredCapabilities capability = DesiredCapabilities.Chrome();
        capability.SetCapability("browserstack.user", "userName");
        capability.SetCapability("browserstack.key", "password");
        capability.SetCapability("browserstack.debug", true);
        driver = new RemoteWebDriver(new Uri("http://hub.browserstack.com/wd/hub/"), capability);
Pankaj Dubey
  • 279
  • 2
  • 18