Skip to content

Commit 71c2b5a

Browse files
committed
Fix example tests
1 parent 8398ea1 commit 71c2b5a

File tree

2 files changed

+44
-92
lines changed

2 files changed

+44
-92
lines changed
Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,37 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
43
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
74
<ProjectGuid>{9297DCCC-AE88-4E12-934A-B2BEA4864B49}</ProjectGuid>
85
<OutputType>Exe</OutputType>
9-
<AppDesignerFolder>Properties</AppDesignerFolder>
6+
<TargetFramework>net7.0</TargetFramework>
107
<RootNamespace>BrowserStackExample</RootNamespace>
118
<AssemblyName>BrowserStackExample</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
14-
<PublishUrl>publish\</PublishUrl>
15-
<Install>true</Install>
16-
<InstallFrom>Disk</InstallFrom>
17-
<UpdateEnabled>false</UpdateEnabled>
18-
<UpdateMode>Foreground</UpdateMode>
19-
<UpdateInterval>7</UpdateInterval>
20-
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
21-
<UpdatePeriodically>false</UpdatePeriodically>
22-
<UpdateRequired>false</UpdateRequired>
23-
<MapFileExtensions>true</MapFileExtensions>
24-
<ApplicationRevision>0</ApplicationRevision>
25-
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
26-
<IsWebBootstrapper>false</IsWebBootstrapper>
27-
<UseApplicationTrust>false</UseApplicationTrust>
28-
<BootstrapperEnabled>true</BootstrapperEnabled>
9+
<ImplicitUsings>enable</ImplicitUsings>
10+
<Nullable>enable</Nullable>
11+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
2912
</PropertyGroup>
3013
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3114
<PlatformTarget>AnyCPU</PlatformTarget>
32-
<DebugSymbols>true</DebugSymbols>
33-
<DebugType>full</DebugType>
34-
<Optimize>false</Optimize>
3515
<OutputPath>bin\Debug\</OutputPath>
3616
<DefineConstants>DEBUG;TRACE</DefineConstants>
37-
<ErrorReport>prompt</ErrorReport>
3817
<WarningLevel>4</WarningLevel>
3918
</PropertyGroup>
4019
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4120
<PlatformTarget>AnyCPU</PlatformTarget>
42-
<DebugType>pdbonly</DebugType>
43-
<Optimize>true</Optimize>
4421
<OutputPath>bin\Release\</OutputPath>
4522
<DefineConstants>TRACE</DefineConstants>
46-
<ErrorReport>prompt</ErrorReport>
4723
<WarningLevel>4</WarningLevel>
4824
</PropertyGroup>
25+
26+
<ItemGroup>
27+
<PackageReference Include="Selenium.WebDriver" Version="4.19.0" />
28+
</ItemGroup>
29+
4930
<ItemGroup>
5031
<Reference Include="BrowserStackLocal">
51-
<HintPath>..\..\BrowserStackLocal\BrowserStackLocal\bin\Debug\net20\BrowserStackLocal.dll</HintPath>
52-
</Reference>
53-
<Reference Include="System" />
54-
<Reference Include="System.Core" />
55-
<Reference Include="System.Drawing" />
56-
<Reference Include="System.Xml.Linq" />
57-
<Reference Include="System.Data.DataSetExtensions" />
58-
<Reference Include="Microsoft.CSharp" />
59-
<Reference Include="System.Data" />
60-
<Reference Include="System.Net.Http" />
61-
<Reference Include="System.Xml" />
62-
<Reference Include="WebDriver, Version=2.52.0.0, Culture=neutral, processorArchitecture=MSIL">
63-
<HintPath>..\packages\Selenium.WebDriver.2.52.0\lib\net40\WebDriver.dll</HintPath>
32+
<HintPath>..\..\BrowserStackLocal\BrowserStackLocal\bin\Debug\net7.0\BrowserStackLocal.dll</HintPath>
6433
<Private>True</Private>
6534
</Reference>
6635
</ItemGroup>
67-
<ItemGroup>
68-
<Compile Include="Example.cs" />
69-
<Compile Include="Properties\AssemblyInfo.cs" />
70-
</ItemGroup>
71-
<ItemGroup>
72-
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
73-
<Visible>False</Visible>
74-
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
75-
<Install>true</Install>
76-
</BootstrapperPackage>
77-
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
78-
<Visible>False</Visible>
79-
<ProductName>.NET Framework 3.5 SP1</ProductName>
80-
<Install>false</Install>
81-
</BootstrapperPackage>
82-
</ItemGroup>
83-
<ItemGroup>
84-
<WCFMetadata Include="Service References\" />
85-
</ItemGroup>
86-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
87-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
88-
Other similar extension points exist, see Microsoft.Common.targets.
89-
<Target Name="BeforeBuild">
90-
</Target>
91-
<Target Name="AfterBuild">
92-
</Target>
93-
-->
94-
</Project>
36+
37+
</Project>

BrowserStackLocalExample/BrowserStackExample/Example.cs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using BrowserStack;
33
using System.Collections.Generic;
44
using OpenQA.Selenium;
5+
using OpenQA.Selenium.Chrome;
56
using OpenQA.Selenium.Remote;
67

78
namespace BrowserStackExample
@@ -10,36 +11,44 @@ class Example
1011
{
1112
static void Main(string[] args)
1213
{
14+
// Start BrowserStack Local
1315
Local local = new Local();
14-
15-
List<KeyValuePair<string, string>> options = new List<KeyValuePair<string, string>>() {
16+
var bsLocalArgs = new List<KeyValuePair<string, string>>()
17+
{
1618
new KeyValuePair<string, string>("key", BROWSERSTACK_ACCESS_KEY),
17-
//new KeyValuePair<string, string>("localIdentifier", "identifier"),
18-
//new KeyValuePair<string, string>("f", "C:\\Users\\Admin\\Desktop\\"),
19-
new KeyValuePair<string, string>("onlyAutomate", "true"),
20-
new KeyValuePair<string, string>("verbose", "true"),
2119
new KeyValuePair<string, string>("forcelocal", "true"),
22-
new KeyValuePair<string, string>("binarypath", "C:\\Users\\Admin\\Desktop\\BrowserStackLocal.exe"),
23-
new KeyValuePair<string, string>("logfile", "C:\\Users\\Admin\\Desktop\\local.log"),
20+
new KeyValuePair<string, string>("verbose", "true"),
21+
// new KeyValuePair<string, string>("binarypath", "C:\\Users\\Admin\\Desktop\\BrowserStackLocal.exe"),
22+
// new KeyValuePair<string, string>("logfile", "C:\\Users\\Admin\\Desktop\\local.log"),
2423
};
25-
local.start(options);
26-
27-
// Run WebDriver Tests
28-
IWebDriver driver;
29-
DesiredCapabilities capability = DesiredCapabilities.Chrome();
30-
capability.SetCapability("browserstack.user", BROWSERSTACK_USERNAME);
31-
capability.SetCapability("browserstack.key", BROWSERSTACK_ACCESS_KEY);
32-
//capability.SetCapability("browserstack.localIdentifier", "identifier");
33-
capability.SetCapability("browserstack.local", true);
34-
capability.SetCapability("build", "build");
24+
local.start(bsLocalArgs);
3525

36-
driver = new RemoteWebDriver(
37-
new Uri("http://hub.browserstack.com/wd/hub/"), capability
26+
// Define BrowserStack capabilities
27+
var browserstackOptions = new Dictionary<string, object>
28+
{
29+
{ "userName", BROWSERSTACK_USERNAME },
30+
{ "accessKey", BROWSERSTACK_ACCESS_KEY },
31+
{ "local", "true" },
32+
{ "build", "build" }
33+
};
34+
35+
// Set up ChromeOptions
36+
ChromeOptions chromeOptions = new ChromeOptions();
37+
chromeOptions.BrowserVersion = "latest";
38+
chromeOptions.PlatformName = "Windows 10";
39+
chromeOptions.AddAdditionalOption("bstack:options", browserstackOptions);
40+
41+
// Launch Remote WebDriver
42+
IWebDriver driver = new RemoteWebDriver(
43+
new Uri("https://hub.browserstack.com/wd/hub"),
44+
chromeOptions
3845
);
46+
47+
// Run your test
3948
driver.Navigate().GoToUrl("http://www.google.com");
4049
Console.WriteLine(driver.Title);
4150

42-
IWebElement query = driver.FindElement(By.Name("q"));
51+
var query = driver.FindElement(By.Name("q"));
4352
query.SendKeys("Browserstack");
4453
query.Submit();
4554
Console.WriteLine(driver.Title);

0 commit comments

Comments
 (0)