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

added code for frames for csharp #1961

Merged
merged 3 commits into from
Sep 26, 2024

Conversation

pallavigitwork
Copy link
Member

@pallavigitwork pallavigitwork commented Sep 23, 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 code for frames for csharp

Motivation and Context

added code for frames for csharp as example code was missing

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.

PR Type

enhancement, documentation


Description

  • Added a new C# test class FramesTest to demonstrate handling frames in Selenium.
  • Updated the documentation across multiple languages (English, Japanese, Portuguese, Chinese) to reference the new C# example file.
  • Improved the clarity and consistency of C# code examples in the documentation by linking to the actual code file.

Changes walkthrough 📝

Relevant files
Enhancement
FramesTest.cs
Add C# example for handling frames in Selenium                     

examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs

  • Added a new test class FramesTest for handling frames.
  • Implemented methods to switch frames using web elements, names, and
    indices.
  • Included assertions to verify frame content.
  • Managed browser session with driver.Quit().
  • +67/-2   
    Documentation
    frames.en.md
    Update C# frame handling examples in English documentation

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

  • Updated C# code examples to use new FramesTest class.
  • Replaced inline code with references to the C# example file.
  • +12/-35 
    frames.ja.md
    Update C# frame handling examples in Japanese documentation

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

  • Updated C# code examples to use new FramesTest class.
  • Replaced inline code with references to the C# example file.
  • +12/-35 
    frames.pt-br.md
    Update C# frame handling examples in Portuguese documentation

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

  • Updated C# code examples to use new FramesTest class.
  • Replaced inline code with references to the C# example file.
  • +12/-28 
    frames.zh-cn.md
    Update C# frame handling examples in Chinese documentation

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

  • Updated C# code examples to use new FramesTest class.
  • Replaced inline code with references to the C# example file.
  • +8/-24   

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

    Copy link

    netlify bot commented Sep 23, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit cee77f2

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

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Code Smell
    The TestFrames method is too long and does multiple things. It should be split into smaller, more focused test methods.

    Possible Bug
    The test switches to the same frame twice using different methods, which may lead to unexpected behavior.

    Copy link
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Ensure proper resource disposal by using a 'using' statement for the WebDriver instance

    Use a using statement to ensure proper disposal of the WebDriver instance.

    examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs [33-37]

    -WebDriver driver = new ChromeDriver();
    -driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
    +using (WebDriver driver = new ChromeDriver())
    +{
    +    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
    +    
    +    // Navigate to Url
    +    driver.Url= "https://www.selenium.dev/selenium/web/iframes.html";
     
    -// Navigate to Url
    -driver.Url= "https://www.selenium.dev/selenium/web/iframes.html";
    -
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: This suggestion ensures proper resource management and disposal of the WebDriver instance, which is crucial for preventing resource leaks and improving code reliability.

    9
    Use more specific locator strategies for improved test reliability

    Consider using a more specific locator strategy instead of By.Id("email") for better
    reliability.

    examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs [44-46]

    -IWebElement emailE = driver.FindElement(By.Id("email"));
    +IWebElement emailE = driver.FindElement(By.CssSelector("input#email[type='email']"));
     emailE.SendKeys("[email protected]");
     emailE.Clear();
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: While using a more specific locator can improve test reliability, the current locator is already quite specific, so the improvement is minor.

    6
    Enhancement
    Add explicit waits for frame availability before switching to improve test stability

    Consider adding a wait condition before switching to the frame to ensure it's
    available.

    examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs [51-53]

    -driver.FindElement(By.Name("iframe1-name"));
    -//Switch to the frame
    -driver.SwitchTo().Frame(iframe);
    +WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    +wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Name("iframe1-name")));
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding an explicit wait condition before switching to a frame improves test stability by ensuring the frame is available, which is a significant enhancement for test reliability.

    8
    Simplify boolean assertions by using the appropriate assertion method

    Use Assert.IsTrue() instead of Assert.AreEqual(true, ...) for boolean assertions.

    examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs [42]

    -Assert.AreEqual(true, driver.PageSource.Contains("We Leave From Here"));
    +Assert.IsTrue(driver.PageSource.Contains("We Leave From Here"));
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using Assert.IsTrue() simplifies the code and makes the intention clearer when performing boolean assertions, enhancing code readability.

    7

    💡 Need additional feedback ? start a PR chat

    @pallavigitwork pallavigitwork requested review from titusfortner and harsha509 and removed request for titusfortner September 23, 2024 12:00
    Copy link
    Member

    @harsha509 harsha509 left a comment

    Choose a reason for hiding this comment

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

    Thank you @pallavigitwork !

    @harsha509 harsha509 merged commit 71e6c1e into SeleniumHQ:trunk Sep 26, 2024
    9 checks passed
    selenium-ci added a commit that referenced this pull request Sep 26, 2024
    added code for frames for csharp
    
    Co-authored-by: Sri Harsha <[email protected]> 71e6c1e
    @pallavigitwork
    Copy link
    Member Author

    Thank you @harsha509 :)

    @pallavigitwork pallavigitwork deleted the pallavi-frame-csharp 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.

    2 participants