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

[Kotlin] Added sample using_selenium code #2224

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

Tahanima
Copy link
Contributor

@Tahanima Tahanima commented Mar 17, 2025

User description

Description

This PR adds a sample Kotlin code that can be used to fill missing Kotlin codes in the Organizing and Executing Selenium Code page.

Motivation and Context

I've added the necessary Kotlin file to provide the missing code examples.

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

Tests


Description

  • Added a new Kotlin test example for Selenium.

  • Demonstrates basic Selenium operations in Kotlin.

  • Includes setup, test execution, and teardown methods.


Changes walkthrough 📝

Relevant files
Tests
UsingSeleniumTest.kt
Add Kotlin test example for Selenium usage                             

examples/kotlin/src/test/kotlin/dev/selenium/getting_started/UsingSeleniumTest.kt

  • Added a Kotlin test class UsingSeleniumTest.
  • Demonstrates Selenium usage with ChromeDriver.
  • Includes a test for form interaction and validation.
  • Implements setup and teardown methods for WebDriver.
  • +43/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    netlify bot commented Mar 17, 2025

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit 95bfe8b

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Deprecated Method

    The code uses the deprecated method getText() on the WebElement. The recommended approach is to use the text property instead.

    val value = message.getText()
    Unused Variable

    The variable textBox is redeclared with var but never reassigned. Consider using val instead to make it immutable.

    var textBox = driver.findElement(By.name("my-text"))

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 17, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix property access syntax

    In Selenium WebElement, the method to get text is text property in Kotlin, not
    getText(). The current code will likely cause a compilation error.

    examples/kotlin/src/test/kotlin/dev/selenium/getting_started/UsingSeleniumTest.kt [35]

    -val value = message.getText()
    +val value = message.text
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: This suggestion fixes a critical issue that would cause a compilation error. In Kotlin, WebElement properties are accessed directly with dot notation rather than using Java-style getter methods.

    High
    General
    Use immutable reference

    Use val instead of var for the textBox variable since it's not being reassigned
    anywhere in the method. This follows Kotlin best practices of preferring
    immutable references.

    examples/kotlin/src/test/kotlin/dev/selenium/getting_started/UsingSeleniumTest.kt [28]

    -var textBox = driver.findElement(By.name("my-text"))
    +val textBox = driver.findElement(By.name("my-text"))
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    __

    Why: Using 'val' instead of 'var' for variables that aren't reassigned is a Kotlin best practice that improves code clarity and prevents accidental reassignment. This is a good style improvement but not critical for functionality.

    Low
    • Update

    @Tahanima Tahanima force-pushed the feature/kotlin-example branch from 3508ebd to 95bfe8b Compare March 17, 2025 17:54
    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