How to Generate and Save Tests with Qodo Gen in PyCharm

Writing tests manually can be repetitive and time-consuming. With Qodo Gen, a powerful AI assistant, generating tests for your Python code becomes fast, simple, and intelligent.

In this post, you’ll learn how to use Qodo Gen to automatically create and save tests for an OrangeHRM login automation class in PyCharm.


πŸ§‘β€πŸ’» 1. Open the OrangeHRM Login Automation File

Start by opening your login_page.py file, which contains the LoginPage class and its methods. For example:

from selenium.webdriver.common.by import By

class LoginPage:
    def __init__(self, driver):
        self.driver = driver

    def set_username(self, username):
        field = self.driver.find_element(By.NAME, "username")
        field.clear()
        field.send_keys(username)

    def set_password(self, password):
        field = self.driver.find_element(By.NAME, "password")
        field.clear()
        field.send_keys(password)

    def click_login(self):
        self.driver.find_element(By.XPATH, "//button[normalize-space()='Login']").click()

    def is_login_successful(self):
        return self.driver.find_element(By.XPATH, "//span[@class='oxd-text oxd-text--span oxd-main-menu-item--name'][normalize-space()='Dashboard']")

    def get_error_message(self):
        return self.driver.find_element(By.XPATH, "//p[@class='oxd-text oxd-text--p oxd-alert-content-text']")

These methods are perfect candidates for automated test generation.


βš™οΈ 2. Activate Qodo Gen

Depending on your IDE:

  • In PyCharm: Click the Qodo Gen icon from the sidebar.
  • In VS Code: Open the Qodo Gen panel from the extensions bar.

πŸ”‘ Note: If prompted, sign in to your Qodo account.


🎯 3. Select the Target Code

  • Highlight the class or method you want to test (e.g., the LoginPage class).
  • Alternatively, just place your cursor inside the method or class.

✨ 4. Trigger Test Generation

Open the Qodo Gen chat panel and type:

/test

Then hit Enter to initiate the test generation process.


πŸ§ͺ 5. Walk Through the Qodo Test Wizard

You’ll be guided through a step-by-step wizard to customize your test generation:

βœ… Select Test Location

Choose where you want to save the test:

  • Create a new file
  • Add to an existing test file (e.g., test_login.py)

πŸ§ͺ Choose Testing Framework

Select your preferred test framework. For most Python projects, pytest is a popular choice.

🧠 Select Behaviors to Test

Qodo may automatically suggest behaviors like:

  • Valid login
  • Invalid login
  • Missing credentials

You can pick and choose based on your project needs.

πŸ” Review Test Summary

Qodo will show you a summary of the test logic it’s about to generate. Confirm if everything looks correct.


πŸ’Ύ 6. Review & Save Tests

Once tests are generated:

  • They appear in a new tab in your editor.
  • Review the logic and assertions Qodo created.
  • Save the file by clicking Accept All, or manually hit:
Ctrl + S

And that’s it β€” your tests are ready!


βœ… Final Thoughts

Qodo Gen removes the repetitive grind of writing boilerplate test code. In just a few clicks, you can generate, review, and save well-structured tests for your Selenium automation code or any Python logic.

If you’re working with test-heavy codebases or practicing TDD, this tool will quickly become your best AI-powered ally inside PyCharm or VS Code.

Recent Post