Back to Repositories

Testing Global Environment Management Workflow in Insomnia

This test suite validates the global environments functionality in Insomnia, focusing on environment creation and management. It covers both creating new environments and importing existing ones, ensuring proper environment variable handling and integration.

Test Coverage Overview

The test suite provides comprehensive coverage of global environment operations in Insomnia.

Key areas tested include:
  • Creating new global environments
  • Environment duplication functionality
  • Importing environments from collections
  • Environment variable validation
  • Integration with request operations

Implementation Analysis

The tests utilize Playwright’s page object model for UI interaction testing. The implementation follows a structured approach with discrete test cases for environment creation and import scenarios.

Technical patterns include:
  • Fixture-based test data loading
  • Clipboard integration for imports
  • Action sequence automation
  • UI element interaction verification

Technical Details

Testing infrastructure includes:
  • Playwright test framework
  • Custom fixture loading utility
  • YAML-based test data
  • Page object selectors
  • Custom app evaluation methods
  • Clipboard manipulation utilities

Best Practices Demonstrated

The test suite exemplifies strong testing practices through modular test organization and robust verification methods.

Notable practices include:
  • Isolated test scenarios
  • Reusable fixture loading
  • Clear test case separation
  • Descriptive test naming
  • Comprehensive UI interaction coverage

kong/insomnia

packages/insomnia-smoke-test/tests/smoke/global-environments.test.ts

            
import { loadFixture } from '../../playwright/paths';
import { test } from '../../playwright/test';

test.describe('Global Environments', async () => {

    test('create a new global environment', async ({ page }) => {
        await page.getByLabel('Create in project').click();
        await page.getByLabel('Create', { exact: true }).getByText('Environment').click();
        await page.getByRole('button', { name: 'Create', exact: true }).click();
        await page.getByTestId('CreateEnvironmentDropdown').click();
        await page.getByText('Private environment').click();
        await page.getByLabel('Project Actions').click();
        await page.getByText('Duplicate').click();
        await page.getByText('New Environment (Copy)').click();
    });

    test('import and use a global environment from a collection', async ({ app, page }) => {
        await loadFixtureFile('collection-for-global-environments.yaml', app, page);
        await loadFixtureFile('global-environment.yaml', app, page);

        await page.getByRole('link', { name: 'collection-for-global-' }).click();
        await page.getByTestId('New Request').getByLabel('GET New Request', { exact: true }).click();
        await page.getByRole('button', { name: 'Send' }).click();
        await page.getByRole('heading', { name: '2 environment variables are' }).click();
        await page.getByRole('button', { name: 'Cancel' }).click();
        await page.getByLabel('Manage Environments').click();
        await page.getByPlaceholder('Choose a global environment').click();
        await page.getByRole('option', { name: 'global-environment' }).click();
        await page.getByText('New Environment').click();
        await page.getByTestId('underlay').click();
        await page.getByRole('button', { name: 'Send' }).click();
        await page.getByRole('tab', { name: 'Console' }).click();
        await page.locator('pre').filter({ hasText: '| 4444' }).click();
        await page.locator('pre').filter({ hasText: '| 55555' }).click();
    });

});
async function loadFixtureFile(fixture: string, app, page) {
    const text = await loadFixture(fixture);
    await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
    await page.getByLabel('Import').click();
    await page.locator('[data-test-id="import-from-clipboard"]').click();
    await page.getByRole('button', { name: 'Scan' }).click();
    await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
}