SeleniumHQ / seleniumhq.github.io

Official Selenium website and documentation
https://selenium.dev
Apache License 2.0
1.1k stars 1.29k forks source link

add csharpwindowscommands #1774

Closed pallavigitwork closed 3 months ago

pallavigitwork commented 3 months ago

User description

Thanks for contributing to the Selenium site and documentation! A PR well described will help maintainers to review and merge it quickly

Before submitting your PR, please check our contributing guidelines. Avoid large PRs, and help reviewers by making them as simple and short as possible.

Description

added example file and code lines for the windows csharp code

Motivation and Context

example code was missing. to improve documentation

Types of changes

Checklist


PR Type

Documentation, Enhancement


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
WindowsTest.cs
Add C# example for window handling in Selenium                     

examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs
  • Added a new test method TestWindowCommands to demonstrate window
    handling in Selenium.
  • Included examples for opening new windows and tabs, switching between
    them, and closing them.
  • Added assertions to verify the titles of the new windows and tabs.
  • +41/-1   
    Documentation
    windows.en.md
    Update English documentation for C# window handling           

    website_and_docs/content/documentation/webdriver/interactions/windows.en.md
  • Updated C# code examples to reference new lines in WindowsTest.cs.
  • Improved documentation for window handling in C#.
  • +21/-40 
    windows.ja.md
    Update Japanese documentation for C# window handling         

    website_and_docs/content/documentation/webdriver/interactions/windows.ja.md
  • Updated C# code examples to reference new lines in WindowsTest.cs.
  • Improved Japanese documentation for window handling in C#.
  • +23/-39 
    windows.pt-br.md
    Update Portuguese documentation for C# window handling     

    website_and_docs/content/documentation/webdriver/interactions/windows.pt-br.md
  • Updated C# code examples to reference new lines in WindowsTest.cs.
  • Improved Portuguese documentation for window handling in C#.
  • +18/-37 
    windows.zh-cn.md
    Update Chinese documentation for C# window handling           

    website_and_docs/content/documentation/webdriver/interactions/windows.zh-cn.md
  • Updated C# code examples to reference new lines in WindowsTest.cs.
  • Improved Chinese documentation for window handling in C#.
  • +19/-38 

    ๐Ÿ’ก PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    netlify[bot] commented 3 months ago

    Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    Latest commit e6dda929e93c09d618af0f5beaa581e8ab37afc2
    codiumai-pr-agent-pro[bot] commented 3 months ago

    PR Reviewer Guide ๐Ÿ”

    โฑ๏ธ Estimated effort to review [1-5] 3
    ๐Ÿงช Relevant tests No
    ๐Ÿ”’ Security concerns No
    โšก Key issues to review Possible Bug:
    The code does not handle exceptions that might be thrown by the WebDriver, such as NoSuchElementException or WebDriverException. This could lead to unhandled exceptions during runtime.
    Resource Management:
    The WebDriver instance is created and disposed within the same method. While this is generally okay, it might be more efficient to manage the WebDriver lifecycle at a higher level if multiple tests are run in sequence, to avoid the overhead of starting up and tearing down the WebDriver repeatedly.
    Hardcoded URL:
    The URL "https://www.selenium.dev/selenium/web/window_switching_tests/page_with_frame.html" is hardcoded in the TestWindowCommands method. It's a good practice to avoid hardcoding URLs and instead, retrieve them from configuration files or environment variables, making the tests more flexible and environment-independent.
    codiumai-pr-agent-pro[bot] commented 3 months ago

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use a try-finally block to ensure WebDriver quits properly even if an exception occurs ___ **Add a try-finally block to ensure the WebDriver quits properly even if an exception occurs
    during the test execution.** [examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs [14-46]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1774/files#diff-3761b3fb91a168a34e0539ef40b0bedbc2b0292bc516fadfbb21f7012c979ab8R14-R46) ```diff WebDriver driver = new ChromeDriver(); -driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500); -... -driver.Quit(); //close all windows +try +{ + driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500); + ... +} +finally +{ + driver.Quit(); //close all windows +} ```
    Suggestion importance[1-10]: 8 Why: This suggestion addresses a significant best practice in ensuring resources are cleaned up properly, which is crucial for preventing resource leaks.
    8
    Possible issue
    Add a check to ensure the new window handle is different from the current window handle before switching ___ **Add a check to ensure that the new window handle is different from the current window
    handle before switching to it.** [examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs [27]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1774/files#diff-3761b3fb91a168a34e0539ef40b0bedbc2b0292bc516fadfbb21f7012c979ab8R27-R27) ```diff -driver.SwitchTo().Window(windowHandles[1]); +if (windowHandles[1] != currHandle) +{ + driver.SwitchTo().Window(windowHandles[1]); +} ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: This suggestion potentially prevents a logical error where switching to the same window could occur, enhancing the robustness of the code.
    7
    Enhancement
    Use var for local variable declarations where the type is obvious to make the code more concise ___ **Use var instead of explicit type declaration for local variables where the type is obvious
    from the right-hand side to make the code more concise.** [examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs [14-29]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1774/files#diff-3761b3fb91a168a34e0539ef40b0bedbc2b0292bc516fadfbb21f7012c979ab8R14-R29) ```diff -WebDriver driver = new ChromeDriver(); -String currHandle = driver.CurrentWindowHandle; -IList windowHandles = new List(driver.WindowHandles); -String title = driver.Title; +var driver = new ChromeDriver(); +var currHandle = driver.CurrentWindowHandle; +var windowHandles = new List(driver.WindowHandles); +var title = driver.Title; ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: The suggestion improves code conciseness and readability by using type inference, although it's more of a style preference than a critical change.
    6
    Maintainability
    Add consistent spacing between tab headers and their content ___ **Ensure consistent spacing between the tab headers and their content to improve readability
    and maintainability.** [website_and_docs/content/documentation/webdriver/interactions/windows.en.md [26-28]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1774/files#diff-d17e1b64f53e4941a547e1a1f13e30d8364aa6fa0b799252aaf513124333f07aR26-R28) ```diff {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L17-L21" >}} + {{< /tab >}} ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 5 Why: The suggestion correctly identifies a minor readability improvement in the markdown documentation, but it's not a critical change.
    5
    pallavigitwork commented 3 months ago

    Thank you Harsha! @harsha509