1

Does anyone have experience with running Selenium C# tests in Browserstack. Trying out this example from the Browserstack, but I can´t seem to get the test to the Test explorer in Visual Studio. Not sure why I´m not able to execute the test. Any ideas? I´m having no problems running my local test in Visual Studio.

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

namespace SeleniumTest
{
class Program
{
    static void Main(string[] args)
    {
        IWebDriver driver;
        DesiredCapabilities capability = DesiredCapabilities.Chrome();
        capability.SetCapability("browserName", "iPad");
        capability.SetCapability("platform", "MAC");
        capability.SetCapability("device", "undefined");
        capability.SetCapability("browserstack.user", "");
        capability.SetCapability("browserstack.key", "");

        driver = new RemoteWebDriver(
          new Uri("http://hub-cloud.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();
    }
}
}
5
  • Are you using xunit, nunit, mstest? I imagine it's not showing up in the test explorer because it's not tagged with any sort of test attribute. Commented Dec 18, 2017 at 14:47
  • Where are you stuck exactly? Commented Dec 18, 2017 at 14:55
  • This is simply written under main class, this will not reflect under test explorer. For the tests to reflect under test explorer, you should use a testing framework like Nunit, Xunit etc Commented Dec 18, 2017 at 19:14
  • Use this sample for the tests to reflect under test explorer github.com/browserstack/nunit-browserstack/blob/master/… Commented Dec 18, 2017 at 19:24
  • Thanks I will try out the github example! Commented Dec 19, 2017 at 9:03

2 Answers 2

1

Try changing this line:

driver = new RemoteWebDriver(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), capability

To

driver = new RemoteWebDriver(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), capability, TimeSpan.FromSeconds(600));

If this does not work, debug it and find out where it is failing so we can narrow it down. You are using the user and key correct?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. The strange thing is that when I right click on the code and click Run or Debug test, nothing happens. It just says No tests found to run in the output console. And no errors in the error list.
1
  using System;
  using System.Security.Policy;
  using Microsoft.VisualStudio.TestTools.UnitTesting;
  using OpenQA.Selenium;
  using OpenQA.Selenium.Remote;

namespace SeleniumTest
{
[TestClass]
class Program
{   
 [TestMethod]
   public void Test()
    {
        IWebDriver driver;
        DesiredCapabilities capability = DesiredCapabilities.Chrome();
        capability.SetCapability("browserName", "iPad");
        capability.SetCapability("platform", "MAC");
        capability.SetCapability("device", "undefined");
        capability.SetCapability("browserstack.user", "");
        capability.SetCapability("browserstack.key", "");

        driver = new RemoteWebDriver(
          new Uri("http://hub-cloud.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();
    }
}
}
**Change the add this code and try to check it by adding in empty Unit test class 
file**

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.