Skip to content

Commit 25b39a5

Browse files
committed
[dotnet] fix: test
1 parent 85b4eeb commit 25b39a5

5 files changed

Lines changed: 25 additions & 11 deletions

File tree

examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using System;
22
using System.IO;
33
using System.Linq;
4+
using System.Runtime.InteropServices;
45
using System.Text.RegularExpressions;
6+
using System.Threading.Tasks;
57
using Microsoft.VisualStudio.TestTools.UnitTesting;
68
using OpenQA.Selenium;
9+
using OpenQA.Selenium.BiDi;
10+
using OpenQA.Selenium.BiDi.WebExtension;
711
using OpenQA.Selenium.Chrome;
812
using OpenQA.Selenium.Chromium;
913

@@ -22,7 +26,7 @@ public void Cleanup()
2226
{
2327
File.Delete(_logLocation);
2428
}
25-
driver.Quit();
29+
driver?.Quit();
2630
}
2731

2832
[TestMethod]
@@ -58,17 +62,27 @@ public void SetBrowserLocation()
5862
}
5963

6064
[TestMethod]
61-
public void InstallExtension()
65+
public async Task InstallExtension()
6266
{
63-
var options = new ChromeOptions();
64-
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
65-
var extensionFilePath = Path.Combine(baseDir, "../../../Extensions/webextensions-selenium-example.crx");
67+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
68+
{
69+
Assert.Inconclusive("Extension install via BiDi is not supported on Windows");
70+
return;
71+
}
6672

67-
options.AddExtension(extensionFilePath);
68-
options.AddArgument("--disable-features=DisableLoadExtensionCommandLineSwitch");
73+
var options = new ChromeOptions();
74+
options.UseWebSocketUrl = true;
75+
options.AddArgument("--remote-debugging-pipe");
76+
options.AddArgument("--enable-unsafe-extension-debugging");
6977

7078
driver = new ChromeDriver(options);
7179

80+
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
81+
var extensionDir = Path.GetFullPath(Path.Combine(baseDir, "../../../Extensions/webextensions-selenium-example"));
82+
83+
var bidi = await driver.AsBiDiAsync();
84+
await bidi.WebExtension.InstallAsync(new ExtensionPath(extensionDir));
85+
7286
driver.Url = "https://www.selenium.dev/selenium/web/blank.html";
7387

7488
IWebElement injected = driver.FindElement(By.Id("webextensions-selenium-example"));

website_and_docs/content/documentation/webdriver/browsers/chrome.en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Add an extension to options:
118118
{{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L40">}}
119119
{{% /tab %}}
120120
{{< tab header="CSharp" >}}
121-
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L62-67" >}}
121+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L73-L84" >}}
122122
{{< /tab >}}
123123
{{< tab header="Ruby" >}}
124124
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L38" >}}

website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ The `extensions` パラメータはcrxファイルを受け入れます。解凍
117117
{{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L40">}}
118118
{{% /tab %}}
119119
{{< tab header="CSharp" >}}
120-
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L62-67" >}}
120+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L73-L84" >}}
121121
{{< /tab >}}
122122
{{< tab header="Ruby" >}}
123123
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L36" >}}

website_and_docs/content/documentation/webdriver/browsers/chrome.pt-br.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Adicionar uma extensão:
117117
{{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L40">}}
118118
{{% /tab %}}
119119
{{< tab header="CSharp" >}}
120-
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L62-67">}}
120+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L73-L84">}}
121121
{{< /tab >}}
122122
{{< tab header="Ruby" >}}
123123
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L34" >}}

website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Chrome浏览器的特有功能可以在谷歌的页面找到: [Capabilities & Ch
117117
{{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L40">}}
118118
{{% /tab %}}
119119
{{< tab header="CSharp" >}}
120-
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L62-67" >}}
120+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L73-L84" >}}
121121
{{< /tab >}}
122122
{{< tab header="Ruby" >}}
123123
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L34" >}}

0 commit comments

Comments
 (0)