CodeCraft AI Testing Automation

Automated testing solution for CodeCraft AI application using Python and Selenium WebDriver

Project Overview

This Selenium automation project tests the complete workflow of CodeCraft AI, including code generation, copying to clipboard, and feedback submission. The script implements robust waiting strategies and error handling for reliable test execution.

Key Features

Smart Waits

Uses explicit waits with WebDriverWait for reliable element interaction

Form Testing

Comprehensive testing of input fields, dropdowns and text areas

Error Handling

Robust try-catch blocks to handle potential UI changes

End-to-End Flow

Tests complete user journey from code generation to feedback submission

Test Script

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
import time

class CodeCraftAITester:
    def __init__(self):
        # Initialize Chrome browser with options
        self.options = Options()
        self.options.add_argument("--start-maximized")
        self.driver = webdriver.Chrome(
            service=Service(ChromeDriverManager().install()),
            options=self.options
        )
        self.wait = WebDriverWait(self.driver, 20)
        self.long_wait = WebDriverWait(self.driver, 60)

    def run_tests(self):
        try:
            # Test Case 1: Open application
            self.driver.get("https://codehavens.netlify.app/codecraftai")
            print("✅ Application loaded successfully")

            # Test Case 2: Fill task input
            task_input = self.wait.until(
                EC.presence_of_element_located((By.XPATH, "//input[@id='task']"))
            )
            task_input.send_keys("Two Sum")
            print("✅ Task input filled")

            # Test Case 3: Select language
            lang_dropdown = Select(self.wait.until(
                EC.presence_of_element_located((By.XPATH, "//select[@id='language']"))
            ))
            lang_dropdown.select_by_visible_text("Python")
            print("✅ Language selected")

            # Test Case 4: Generate code
            generate_btn = self.wait.until(
                EC.element_to_be_clickable((By.XPATH, "//button[normalize-space()='Generate Code']"))
            )
            generate_btn.click()
            print("✅ Generate button clicked")

            # Test Case 5: Verify code generation
            code_element = self.long_wait.until(
                EC.presence_of_element_located((By.XPATH, "//pre"))
            )
            self.long_wait.until(
                lambda d: "Generating your code" not in code_element.text
            )
            print("✅ Code generation completed")

            # Test Case 6: Copy code
            copy_button = self.wait.until(
                EC.element_to_be_clickable((By.XPATH, "//button[normalize-space()='Copy']"))
            )
            copy_button.click()
            print("✅ Code copied to clipboard")

            # Test Case 7: Submit feedback
            self.submit_feedback()
            
        except Exception as e:
            print(f"❌ Test failed: {str(e)}")
        finally:
            self.driver.quit()

    def submit_feedback(self):
        try:
            # Open Feedback form
            feedback_btn = self.wait.until(
                EC.element_to_be_clickable((By.XPATH, "//button[@id='feedbackBtn']"))
            )
            feedback_btn.click()
            time.sleep(2)  # Wait for modal animation
            print("✅ Feedback modal opened")

            # Fill feedback form
            username = self.wait.until(
                EC.presence_of_element_located((By.XPATH, "//input[@id='username']"))
            )
            username.send_keys("AutomatedTester")
            
            category_select = Select(self.wait.until(
                EC.presence_of_element_located((By.XPATH, "//select[@id='category']"))
            ))
            category_select.select_by_visible_text("Bug Report")
            
            feedback_area = self.wait.until(
                EC.presence_of_element_located((By.XPATH, "//textarea[@id='feedback']"))
            )
            feedback_area.send_keys("This is an automated test feedback submission")
            print("✅ Feedback form filled")

            # Submit feedback
            submit_btn = self.wait.until(
                EC.element_to_be_clickable((By.XPATH, "//button[normalize-space()='Submit Feedback']"))
            )
            submit_btn.click()
            
            # Verify submission
            self.wait.until(
                EC.invisibility_of_element((By.ID, "feedbackModal"))
            )
            print("✅ Feedback submitted successfully")

        except Exception as e:
            print(f"❌ Feedback submission failed: {str(e)}")

if __name__ == "__main__":
    tester = CodeCraftAITester()
    tester.run_tests()

Test Execution Flow

1

Initialize Browser

Set up Chrome WebDriver with maximized window using ChromeDriverManager

2

Load Application

Navigate to CodeCraft AI application URL

3

Input Task

Enter coding problem description in task input field

4

Select Language

Choose programming language from dropdown

5

Generate Code

Click generate button and wait for code completion

6

Copy Code

Verify code copy functionality

7

Submit Feedback

Complete and submit feedback form

View Live Application View on GitHub