Selenium C tests in Browserstack

0 votes

Is there anyone who has used Browserstack to run Selenium C# tests? I'm trying out this example from the Browserstack, but I can't seem to get the test into Visual Studio's Test Explorer. I'm not sure why I'm unable to run the test. Do you have any suggestions? In Visual Studio, I have no issues executing my local test.

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();
    }
}
}
Jun 11, 2022 in C# by pranav
• 2,590 points
651 views

1 answer to this question.

0 votes

Try this and make changes according to your needs

  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**
answered Jun 21, 2022 by jyoti
• 1,240 points

Related Questions In C#

0 votes
1 answer

What are the differences between C, C# and C++ in terms of real-world applications?

C is a bare-bones, straightforward, and clean ...READ MORE

answered May 30, 2022 in C# by rajiv
• 1,620 points
698 views
0 votes
1 answer

Examples of dynamic polymorphism in c#

Check the example of polymorphism below. We ...READ MORE

answered Jun 7, 2022 in C# by pranav
• 2,590 points
855 views
0 votes
1 answer

Print Pdf in C#

Using an installed Adobe Reader or any ...READ MORE

answered Jun 7, 2022 in C# by pranav
• 2,590 points
828 views
0 votes
1 answer

Is a Library a project or a C# source code file in Visual Studio?

A library project is a collection of ...READ MORE

answered Jun 7, 2022 in C# by rajiv
• 1,620 points
474 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,673 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
0 votes
1 answer

How to find the extension of a file in C#

Go to here https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getextension?redirectedfrom=MSDN&view=net-6.0#System_IO_Path_GetExtension_System_String_ string myFilePath = @"C:\MyFile.txt"; string ext ...READ MORE

answered Jun 21, 2022 in C# by jyoti
• 1,240 points
635 views
0 votes
1 answer

Logging DML operations in ASP.NET MVC project

There are several options. You might register an ...READ MORE

answered Jun 14, 2022 in C# by jyoti
• 1,240 points
1,190 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP