Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Replace usage of deprecated GetAttribute method in tests #14872

Open
wants to merge 36 commits into
base: trunk
Choose a base branch
from

Conversation

nvborisenko
Copy link
Member

@nvborisenko nvborisenko commented Dec 7, 2024

User description

Description

Use another method instead of GetAttribute().

Motivation and Context

GetAttribute() will be removed soon, we should not rely on it.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Tests


Description

  • Replaced deprecated GetAttribute method with GetDomProperty and GetDomAttribute in various test files.
  • Updated assertions to use GetDomProperty for value checks and GetDomAttribute for id and name checks.
  • Ensured compatibility with upcoming changes by removing reliance on deprecated methods.

Changes walkthrough 📝

Relevant files
Tests
15 files
DefaultKeyboardTest.cs
Update value assertions to use GetDomProperty                       

dotnet/test/common/BiDi/Input/DefaultKeyboardTest.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +2/-2     
    ChildrenFindingTest.cs
    Use GetDomAttribute for id and name assertions                     

    dotnet/test/common/ChildrenFindingTest.cs

  • Replaced GetAttribute with GetDomAttribute for id and name assertions.

  • +11/-11 
    ClearTest.cs
    Update value assertions to use GetDomProperty                       

    dotnet/test/common/ClearTest.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +4/-4     
    CorrectEventFiringTest.cs
    Update value assertions to use GetDomProperty                       

    dotnet/test/common/CorrectEventFiringTest.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +1/-1     
    ElementAttributeTest.cs
    Use GetDomAttribute and GetDomProperty for assertions       

    dotnet/test/common/ElementAttributeTest.cs

  • Replaced GetAttribute with GetDomAttribute and GetDomProperty for
    various assertions.
  • +11/-11 
    ElementFindingTest.cs
    Use GetDomAttribute and GetDomProperty for assertions       

    dotnet/test/common/ElementFindingTest.cs

  • Replaced GetAttribute with GetDomAttribute and GetDomProperty for id
    and value assertions.
  • +28/-28 
    ElementSelectingTest.cs
    Use GetDomAttribute for id assertions                                       

    dotnet/test/common/ElementSelectingTest.cs

    • Replaced GetAttribute with GetDomAttribute for id assertions.
    +1/-1     
    ExecutingAsyncJavascriptTest.cs
    Update value assertions to use GetDomProperty                       

    dotnet/test/common/ExecutingAsyncJavascriptTest.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +2/-2     
    FormHandlingTests.cs
    Update value assertions to use GetDomProperty                       

    dotnet/test/common/FormHandlingTests.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +19/-19 
    FrameSwitchingTest.cs
    Update value assertions to use GetDomProperty                       

    dotnet/test/common/FrameSwitchingTest.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +5/-5     
    I18Test.cs
    Update value assertions to use GetDomProperty                       

    dotnet/test/common/I18Test.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +3/-3     
    BasicKeyboardInterfaceTest.cs
    Update value assertions to use GetDomProperty                       

    dotnet/test/common/Interactions/BasicKeyboardInterfaceTest.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +9/-9     
    BasicMouseInterfaceTest.cs
    Update value assertions to use GetDomProperty                       

    dotnet/test/common/Interactions/BasicMouseInterfaceTest.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +3/-3     
    CombinedInputActionsTest.cs
    Update value assertions to use GetDomProperty                       

    dotnet/test/common/Interactions/CombinedInputActionsTest.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +3/-3     
    JavascriptEnabledBrowserTest.cs
    Update value assertions to use GetDomProperty                       

    dotnet/test/common/JavascriptEnabledBrowserTest.cs

  • Replaced GetAttribute with GetDomProperty for value assertions.
  • +4/-4     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 7, 2024

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Code Consistency
    The tests are mixing GetDomProperty and GetDomAttribute calls for checking element attributes. Should standardize on using GetDomProperty for 'value' checks and GetDomAttribute for 'id' and 'name' checks.

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 7, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    ✅ Fix incorrect variable reference in assertion that checks wrong element

    Fix incorrect assertion target in EmptyTextBoxesShouldReturnAnEmptyStringNotNull
    test - second assertion is checking the textbox again instead of the textarea.

    dotnet/test/common/FormHandlingTests.cs [293-294]

    -IWebElement emptyTextArea = driver.FindElement(By.Id("emptyTextArea"));
    -Assert.That(emptyTextBox.GetDomProperty("value"), Is.Empty);
    +IWebElement emptyTextArea = driver.FindElement(By.Id("emptyTextArea")); 
    +Assert.That(emptyTextArea.GetDomProperty("value"), Is.Empty);

    [Suggestion has been applied]

    Suggestion importance[1-10]: 9

    Why: Critical bug fix - the test is asserting the wrong element's value (emptyTextBox instead of emptyTextArea), which defeats the purpose of testing both elements and could mask actual issues.

    9

    💡 Need additional feedback ? start a PR chat

    @nvborisenko
    Copy link
    Member Author

    nvborisenko commented Dec 7, 2024

    Points to discuss:

    1. nowrap

    In Chrome:

    <div id="unwrappable" nowrap="">Unwrappable text</div>
    element5.GetDomAttribute("nowrap"); // "true"

    In Firefox:

    <div id="unwrappable" nowrap="">Unwrappable text</div>
    element5.GetDomAttribute("nowrap"); // ""

    EDIT:
    Seems there are 2 tests: for GetAttribute and GetDomAttribute, where Firefox's behavior is expected (Chrome is ignored).

    2. checked

    checkbox.GetAttribute("checked"); // "true"
    

    What is an alternative?

    EDIT:

    checkbox.GetDomProperty("checked"); // "True" or "False"

    3. selected

    initiallySelected.GetAttribute("selected"); // "true"
    

    What is an alternative?

    EDIT:

    selected dom property is actually checked.

    Assert.That(initiallySelected.GetDomProperty("checked"), Is.EqualTo("True")); // it works

    EDIT 2:

    There is special method to verify whether an element is selected:

    Assert.That(initiallySelected.Selected, Is.True); // it works

    @nvborisenko
    Copy link
    Member Author

    OK, now I should seat and carefully de-duplicate ElementAttributeTests.

    @nvborisenko nvborisenko changed the title WIP [dotnet] Replace usage of deprecated GetAttribute method in tests [dotnet] Replace usage of deprecated GetAttribute method in tests Dec 8, 2024
    @nvborisenko
    Copy link
    Member Author

    Ready for review.

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

    Successfully merging this pull request may close these issues.

    1 participant