11using System ;
22using System . IO ;
33using System . Linq ;
4+ using System . Runtime . InteropServices ;
45using System . Text . RegularExpressions ;
6+ using System . Threading . Tasks ;
57using Microsoft . VisualStudio . TestTools . UnitTesting ;
68using OpenQA . Selenium ;
9+ using OpenQA . Selenium . BiDi ;
10+ using OpenQA . Selenium . BiDi . WebExtension ;
711using OpenQA . Selenium . Chrome ;
812using 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" ) ) ;
0 commit comments