Write First Test
Now that your RocketQA project is ready, it’s time to write your first real-world test.
Let’s walk through creating a comprehensive login test. This example will introduce you to the core concepts of RocketQA and show how natural language scenarios map directly to automated testing.
Simple Login page tests
Section titled “Simple Login page tests”Step 1: Update Locators
Section titled “Step 1: Update Locators”First, define the page elements in locators.yml
:
loginPage: usernameField: "#username" passwordField: "#password" loginButton: "[type='submit']" errorMessage: ".error-message" forgotPasswordLink: ".forgot-password"
dashboard: welcomeMessage: ".welcome-user" userProfile: "[data-testid='user-profile']" logoutButton: ".logout-btn"
homepage: logo: ".site-logo" loginLink: ".login-link"
Step 2: Create the Feature File
Section titled “Step 2: Create the Feature File”Create features/authentication.feature
:
Feature: User Authentication Scenario: Successful login with valid credentials When navigate to "https://your-app.com" And click $homepage.loginLink And type "john.doe@example.com" into $loginPage.usernameField And type "SecurePassword123!" into $loginPage.passwordField And click $loginPage.loginButton Then $dashboard.welcomeMessage is visible And $dashboard.userProfile is visible
Scenario: Login fails with invalid credentials When navigate to "https://your-app.com/login" And type "invalid@example.com" into $loginPage.usernameField And type "wrongpassword" into $loginPage.passwordField And click $loginPage.loginButton Then $loginPage.errorMessage is visible And $loginPage.errorMessage contains text "Invalid credentials"
Scenario: User can access forgot password When navigate to "https://your-app.com/login" And click $loginPage.forgotPasswordLink Then page title contains "Reset Password" And page url contains "/forgot-password"
Using Shared Scenarios
Section titled “Using Shared Scenarios”Create reusable scenarios in features/shared.feature
:
Feature: Shared Test Scenarios
Scenario: Login as standard user When navigate to "https://your-app.com/login" And type "testuser@example.com" into $loginPage.usernameField And type "password123" into $loginPage.passwordField And click $loginPage.loginButton Then $dashboard.welcomeMessage is visible
Scenario: Open product catalog When navigate to "https://your-app.com" And click $navigation.catalogLink Then $catalog.productGrid is visible And page title contains "Products"
Then reference them in other features:
Feature: Shopping Cart
Scenario: User can add item to cart When run scenario {Login as standard user} And run scenario {Open product catalog} When click $catalog.firstProduct And click $product.addToCartButton Then $cart.itemCount contains text "1"
Best Practices for Writing Tests
Section titled “Best Practices for Writing Tests”1. Write Clear, Descriptive Scenarios
Section titled “1. Write Clear, Descriptive Scenarios”# Good: Clear and specificScenario: User receives email confirmation after successful registration
# Avoid: Vague or technicalScenario: Test user registration
2. Use Meaningful Locator Names
Section titled “2. Use Meaningful Locator Names”# Good: Descriptive and hierarchicalcheckoutPage: billingSection: ".billing-details" shippingSection: ".shipping-details" paymentSection: ".payment-details" continueButton: ".continue-to-payment"
# Avoid: Generic or unclear namespage1: button1: ".btn-1" input2: "#field2"
🎉 Great job! You’ve mastered the basics of writing RocketQA tests. Now let’s run your tests and see them in action!