Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

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.

First, define the page elements in locators.yml:

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"

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"

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"
# Good: Clear and specific
Scenario: User receives email confirmation after successful registration
# Avoid: Vague or technical
Scenario: Test user registration
# Good: Descriptive and hierarchical
checkoutPage:
billingSection: ".billing-details"
shippingSection: ".shipping-details"
paymentSection: ".payment-details"
continueButton: ".continue-to-payment"
# Avoid: Generic or unclear names
page1:
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!