Skip to content

Commit 868f62e

Browse files
committed
Bidi Input support
1 parent 2d9d620 commit 868f62e

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -573,36 +573,6 @@
573573
"FAIL"
574574
]
575575
},
576-
{
577-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
578-
"testIdPattern": "[injected.spec] *",
579-
"platforms": [
580-
"darwin",
581-
"linux",
582-
"win32"
583-
],
584-
"parameters": [
585-
"webDriverBiDi"
586-
],
587-
"expectations": [
588-
"FAIL"
589-
]
590-
},
591-
{
592-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
593-
"testIdPattern": "[input.spec] *",
594-
"platforms": [
595-
"darwin",
596-
"linux",
597-
"win32"
598-
],
599-
"parameters": [
600-
"webDriverBiDi"
601-
],
602-
"expectations": [
603-
"FAIL"
604-
]
605-
},
606576
{
607577
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
608578
"testIdPattern": "[jshandle.spec] *.evaluateHandle*",

lib/PuppeteerSharp/Bidi/BidiElementHandle.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// * SOFTWARE.
2222

23+
using System.IO;
2324
using System.Linq;
2425
using System.Threading.Tasks;
2526
using PuppeteerSharp.QueryHandlers;
@@ -51,7 +52,24 @@ public static IJSHandle From(RemoteValue value, BidiRealm realm)
5152
return new BidiElementHandle(value, realm);
5253
}
5354

54-
public override Task UploadFileAsync(bool resolveFilePaths, params string[] filePaths) => throw new System.NotImplementedException();
55+
public override async Task UploadFileAsync(bool resolveFilePaths, params string[] filePaths)
56+
{
57+
// Resolve file paths to absolute paths if needed
58+
if (resolveFilePaths)
59+
{
60+
filePaths = filePaths.Select(file =>
61+
{
62+
if (Path.IsPathRooted(file))
63+
{
64+
return file;
65+
}
66+
67+
return Path.GetFullPath(file);
68+
}).ToArray();
69+
}
70+
71+
await BidiFrame.SetFilesAsync(this, filePaths).ConfigureAwait(false);
72+
}
5573

5674
public override async Task<IFrame> ContentFrameAsync()
5775
{

lib/PuppeteerSharp/Bidi/BidiFrame.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,13 @@ internal static BidiFrame From(BidiPage parentPage, BidiFrame parentFrame, Brows
398398
return parentFrame;
399399
}
400400

401+
internal async Task SetFilesAsync(BidiElementHandle element, string[] files)
402+
{
403+
await BrowsingContext.SetFilesAsync(
404+
element.Value.ToSharedReference(),
405+
files).ConfigureAwait(false);
406+
}
407+
401408
/// <inheritdoc />
402409
protected internal override DeviceRequestPromptManager GetDeviceRequestPromptManager() => throw new System.NotImplementedException();
403410

lib/PuppeteerSharp/Bidi/Core/BrowsingContext.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,17 @@ internal async Task SetOfflineModeAsync(bool enabled)
234234
await Session.Driver.Emulation.SetNetworkConditions(parameters).ConfigureAwait(false);
235235
}
236236

237+
internal async Task SetFilesAsync(WebDriverBiDi.Script.SharedReference element, string[] files)
238+
{
239+
var parameters = new SetFilesCommandParameters(Id, element);
240+
foreach (var file in files)
241+
{
242+
parameters.Files.Add(file);
243+
}
244+
245+
await Session.Driver.Input.SetFilesAsync(parameters).ConfigureAwait(false);
246+
}
247+
237248
protected virtual void OnBrowsingContextCreated(BidiBrowsingContextEventArgs e) => BrowsingContextCreated?.Invoke(this, e);
238249

239250
private void Initialize()

0 commit comments

Comments
 (0)