Skip to content

added csharp code for navigation command #1696

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

Merged
merged 4 commits into from
Apr 27, 2024

Conversation

pallavigitwork
Copy link
Member

@pallavigitwork pallavigitwork commented Apr 27, 2024

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 csharp commands for navigation

Motivation and Context

added csharp code for navigation

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

Type

enhancement, documentation


Description

  • Added a new C# test class NavigationTest in the SeleniumDocs project, including methods to test basic navigation commands.
  • Implemented navigation commands such as GoToUrl, Back, Forward, and Refresh with assertions to check the page title.
  • Updated the English, Japanese, Portuguese, and Chinese documentation to reference the new C# code examples.

Changes walkthrough

Relevant files
Enhancement
NavigationTest.cs
Add C# Selenium navigation commands with tests                     

examples/dotnet/SeleniumDocs/Interactions/NavigationTest.cs

  • Added a new test class NavigationTest with methods to test navigation
    commands.
  • Implemented navigation commands such as GoToUrl, Back, Forward, and
    Refresh.
  • Added assertions to check the title after each navigation to ensure
    the correct page is loaded.
  • Initialized and quit the ChromeDriver within the test method.
  • +37/-3   
    Documentation
    navigation.en.md
    Update English navigation documentation with new CSharp examples

    website_and_docs/content/documentation/webdriver/interactions/navigation.en.md

  • Updated CSharp code examples for navigation commands to reference the
    new test methods.
  • +10/-4   
    navigation.ja.md
    Update Japanese navigation documentation with new CSharp examples

    website_and_docs/content/documentation/webdriver/interactions/navigation.ja.md

  • Updated CSharp code examples for navigation commands to reference the
    new test methods.
  • +10/-4   
    navigation.pt-br.md
    Update Portuguese navigation documentation with new CSharp examples

    website_and_docs/content/documentation/webdriver/interactions/navigation.pt-br.md

  • Updated CSharp code examples for navigation commands to reference the
    new test methods.
  • +10/-4   
    navigation.zh-cn.md
    Update Chinese navigation documentation with new CSharp examples

    website_and_docs/content/documentation/webdriver/interactions/navigation.zh-cn.md

  • Updated CSharp code examples for navigation commands to reference the
    new test methods.
  • +10/-4   

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

    Sorry, something went wrong.

    Copy link

    netlify bot commented Apr 27, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit dfc71a9

    @qodo-merge-pro qodo-merge-pro bot added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 27, 2024
    Copy link
    Contributor

    PR Description updated to latest commit (40acb57)

    Sorry, something went wrong.

    Copy link
    Contributor

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the PR involves a moderate amount of code changes across multiple files, primarily adding new functionality and updating documentation. The changes are straightforward and well-structured, making the review process relatively easy.

    🧪 Relevant tests

    Yes

    🔍 Possible issues

    Hardcoded URL: The URLs in the navigation tests are hardcoded, which could make the tests less flexible and more difficult to maintain if the URLs change in the future.

    No Cleanup in Tests: The test method TestNavigationCommands initializes a ChromeDriver but does not implement a teardown method to ensure closure if an assertion fails, potentially leaving the browser open.

    🔒 Security concerns

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link
    Contributor

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Replace implicit waits with explicit waits to enhance test reliability.

    Replace the use of ImplicitWait with explicit waits using WebDriverWait to improve the
    reliability of the test. Implicit waits can lead to unpredictable wait times and may not
    work effectively for all elements.

    examples/dotnet/SeleniumDocs/Interactions/NavigationTest.cs [15]

    -driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
    +WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    +wait.Until(d => d.FindElement(By.Id("someElement")));
     
    Add assertions after navigation commands to ensure correct page state.

    Add assertions after each navigation command to verify that the navigation has resulted in
    the expected page state change.

    examples/dotnet/SeleniumDocs/Interactions/NavigationTest.cs [25-26]

     driver.Navigate().Back();
     title = driver.Title;
    +Assert.AreEqual("Expected Title After Back", title);
     
    Enhancement
    Remove redundant navigation commands to improve code efficiency.

    Remove redundant navigation commands that navigate to the same URL twice in a row without
    any intermediate action that would change the page state.

    examples/dotnet/SeleniumDocs/Interactions/NavigationTest.cs [18-20]

     driver.Url = "https://selenium.dev";
    -driver.Navigate().GoToUrl("https://selenium.dev");
     
    Use Assert.IsTrue for better error messages in assertions.

    Use Assert.IsTrue with a more descriptive error message for better debugging and
    readability of test failures.

    examples/dotnet/SeleniumDocs/Interactions/NavigationTest.cs [22]

    -Assert.AreEqual("Selenium", title);
    +Assert.IsTrue(title == "Selenium", "The title should be 'Selenium' but was '" + title + "'");
     
    Maintainability
    Refactor WebDriver management into setup and teardown methods.

    Encapsulate the WebDriver initialization and teardown in TestInitialize and TestCleanup
    methods to enhance test structure and reuse.

    examples/dotnet/SeleniumDocs/Interactions/NavigationTest.cs [14-40]

    -IWebDriver driver = new ChromeDriver();
    -driver.Quit();
    +private IWebDriver driver;
     
    +[TestInitialize]
    +public void Setup()
    +{
    +    driver = new ChromeDriver();
    +}
    +
    +[TestCleanup]
    +public void Teardown()
    +{
    +    driver.Quit();
    +}
    +

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @pallavigitwork
    Copy link
    Member Author

    done, please check.

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    @harsha509 harsha509 merged commit e39e518 into SeleniumHQ:trunk Apr 27, 2024
    9 checks passed
    chamiz pushed a commit to chamiz/seleniumhq.github.io that referenced this pull request Apr 29, 2024
    * added csharp code for navigation command
    
    * updated csharp code fix
    
    * modified package name
    
    ---------
    
    Co-authored-by: Sri Harsha <[email protected]>
    @pallavigitwork pallavigitwork deleted the pallavi-csharpfix branch September 27, 2024 12:09
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 2
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    2 participants