Skip to content

Conversation

@RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Dec 1, 2025

User description

Fix nullability for NodeRemoteValue.SharedId.

Also add a test for it.

🔄 Types of changes

  • New feature (non-breaking change which adds functionality and tests!)

PR Type

Bug fix, Tests


Description

  • Fix NodeRemoteValue.SharedId nullability from nullable to non-nullable

  • Improve test assertions for NodeRemoteValue properties

  • Add helper method to retrieve element IDs for validation

  • Strengthen test coverage with explicit SharedId verification


Diagram Walkthrough

flowchart LR
  A["NodeRemoteValue<br/>SharedId parameter"] -->|"Change from<br/>string? to string"| B["Non-nullable<br/>SharedId"]
  C["CallFunctionParameterTest"] -->|"Add SharedId<br/>verification"| D["Enhanced test<br/>assertions"]
  C -->|"Add GetElementId<br/>helper"| E["Element ID<br/>reflection utility"]
Loading

File Walkthrough

Relevant files
Bug fix
RemoteValue.cs
Fix SharedId nullability to non-nullable                                 

dotnet/src/webdriver/BiDi/Script/RemoteValue.cs

  • Changed NodeRemoteValue constructor parameter SharedId from string?
    (nullable) to string (non-nullable)
  • Aligns with the fact that NodeRemoteValue implements ISharedReference
    which requires a valid SharedId
+1/-1     
Tests
CallFunctionParameterTest.cs
Enhance test assertions and add element ID helper               

dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs

  • Added using System.Runtime.CompilerServices; for unsafe accessor
    support
  • Improved CanCallFunctionToGetElement() test with explicit variable
    casting and additional assertion for SharedId
  • Added new GetElementId() helper method using unsafe accessor to
    retrieve element IDs for test validation
+14/-1   

@selenium-ci selenium-ci added the C-dotnet .NET Bindings label Dec 1, 2025
@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
No auditing: The new code performs test actions without adding or validating any audit logging of
critical actions, but this is test code and may not be subject to audit requirements.

Referred Code
public async Task CanCallFunctionToGetElement()
{
    driver.Url = UrlBuilder.WhereIs("bidi/logEntryAdded.html");

    var res = await context.Script.CallFunctionAsync("""
        () => document.getElementById("consoleLog")
        """, false);

    Assert.That(res, Is.Not.Null);
    Assert.That(res.AsSuccessResult(), Is.AssignableFrom<NodeRemoteValue>());

    var node = (NodeRemoteValue)res.AsSuccessResult();
    Assert.That(node.Value, Is.Not.Null);
    Assert.That(node.SharedId, Is.EqualTo(GetElementId(By.Id("consoleLog"))));
}

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Learned
best practice
Extract repeated test assertions

Extract common assertion and casting of RemoteValue to a reusable helper to
avoid repetition across tests and improve readability.

dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs [102-111]

 var res = await context.Script.CallFunctionAsync("""
             () => document.getElementById("consoleLog")
             """, false);
 
-Assert.That(res, Is.Not.Null);
-Assert.That(res.AsSuccessResult(), Is.AssignableFrom<NodeRemoteValue>());
-
-var node = (NodeRemoteValue)res.AsSuccessResult();
-Assert.That(node.Value, Is.Not.Null);
+var node = AssertNodeRemoteValue(res);
 Assert.That(node.SharedId, Is.EqualTo(GetElementId(By.Id("consoleLog"))));
 
+// Helper usable across tests:
+static NodeRemoteValue AssertNodeRemoteValue(ScriptEvaluateResult res)
+{
+    Assert.That(res, Is.Not.Null);
+    Assert.That(res.AsSuccessResult(), Is.AssignableFrom<NodeRemoteValue>());
+    var node = (NodeRemoteValue)res.AsSuccessResult();
+    Assert.That(node.Value, Is.Not.Null);
+    return node;
+}
+

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 6

__

Why:
Relevant best practice - Replace ad-hoc duplication with shared helpers/utilities to reduce repetition and centralize logic.

Low
General
Improve test robustness and failure reporting

In the GetElementId method, replace the direct cast of the found element with a
safe cast (as) and an assertion to provide a clearer error message if the
element is not of the expected WebElement type.

dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs [227-234]

 private string GetElementId(By selector)
 {
-    var element = (WebElement)driver.FindElement(selector);
-    return ReflectElementId(element);
+    var element = driver.FindElement(selector) as WebElement;
+    Assert.That(element, Is.Not.Null, $"Element located by '{selector}' was not found or not a WebElement.");
+    return ReflectElementId(element!);
 
     [UnsafeAccessor(UnsafeAccessorKind.Method, Name = "get_Id")]
     static extern string ReflectElementId(WebElement element);
 }
  • Apply / Chat
Suggestion importance[1-10]: 4

__

Why: The suggestion correctly identifies that a direct cast could throw an InvalidCastException and proposes using as with a null check to provide a more informative test failure message, which improves test robustness.

Low
  • More

@RenderMichael RenderMichael merged commit 2570c3d into SeleniumHQ:trunk Dec 1, 2025
12 checks passed
@RenderMichael RenderMichael deleted the nullable-NodeRemoteValue branch December 1, 2025 05:21
}

public sealed record NodeRemoteValue(string? SharedId, NodeProperties? Value) : RemoteValue, ISharedReference
public sealed record NodeRemoteValue(string SharedId, NodeProperties? Value) : RemoteValue, ISharedReference
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is nullable: https://w3c.github.io/webdriver-bidi/#cddl-type-scriptnoderemotevalue

I also asked about it here: w3c/webdriver-bidi#868

I don't know how to deal with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants