QAFlow - Report

Examples

Integration examples with various testing frameworks

Examples

This page provides examples of integrating QAFlow Reporter with various testing frameworks. These examples demonstrate how to set up reporting for your tests and how to structure your code for optimal results.

Playwright Integration

Basic Playwright Example

import { test } from '@playwright/test';
import reporter from '@qaflow/report';
 
test('Product search test', async ({ page, browser }) => {
  // Initialize the test
  reporter.createTest(
    'Product Search Test',
    'Tests the search functionality on an e-commerce site',
    { author: 'QA Tester', email: 'tester@example.com' },
    { 
      name: 'Playwright Test', 
      browser: browser.browserType().name(),
      version: browser.version(),
      os: process.platform
    }
  );
 
  try {
    // Test steps
    await reporter.step('Navigate to homepage', async () => {
      await page.goto('https://example.com');
    });
 
    await reporter.step('Click search box', async () => {
      await page.click('.search-box');
    });
 
    await reporter.step('Enter search query', async () => {
      await page.fill('.search-input', 'test product');
      await page.press('.search-input', 'Enter');
    });
 
    // Take a screenshot of the search results
    const screenshot = await page.screenshot({ encoding: 'base64' });
    
    await reporter.step('Verify search results', async () => {
      const resultCount = await page.locator('.product-item').count();
      return resultCount > 0;
    }, { screenshot });
 
    // End the test
    const result = await reporter.end();
    console.log('Test result:', result);
  } catch (error) {
    // End the test in case of error
    console.error('Test error:', error);
    await reporter.end();
    throw error;
  }
});

Playwright with Test Fixtures

You can also create custom fixtures to make QAFlow Reporter available to all your tests:

// fixtures.js
import { test as base } from '@playwright/test';
import reporter from '@qaflow/report';
 
// Define a custom fixture
export const test = base.extend({
  qaReporter: async ({ browser, page }, use) => {
    // Create a test at the start of each test
    reporter.createTest(
      test.info().title,
      test.info().annotations.find(a => a.type === 'description')?.description || '',
      { author: 'QA Tester', email: 'tester@example.com' },
      { 
        name: 'Playwright Test', 
        browser: browser.browserType().name(),
        version: browser.version(),
        os: process.platform
      }
    );
    
    // Provide the reporter to the test
    await use(reporter);
    
    // End the test after it's complete
    await reporter.end();
  }
});
 
export { expect } from '@playwright/test';

Then in your test files:

import { test, expect } from './fixtures';
 
test('User login test', async ({ page, qaReporter }) => {
  await qaReporter.step('Navigate to login page', async () => {
    await page.goto('https://example.com/login');
  });
  
  await qaReporter.step('Enter credentials', async () => {
    await page.fill('#username', 'testuser');
    await page.fill('#password', 'password123');
  });
  
  await qaReporter.step('Click login button', async () => {
    await page.click('#login-button');
  });
  
  await qaReporter.step('Verify successful login', async () => {
    await page.waitForURL('**/dashboard');
    return page.url().includes('/dashboard');
  });
});

Jest Integration

Basic Jest Example

import reporter from '@qaflow/report';
 
describe('User functions', () => {
  beforeAll(() => {
    reporter.createTest(
      'User Registration Test',
      'Tests the user registration functionality',
      { author: 'QA Tester', email: 'tester@example.com' },
      { name: 'Jest Test Environment', version: process.version, os: process.platform }
    );
  });
 
  afterAll(async () => {
    const results = await reporter.end();
    console.log('Test result:', results);
  });
 
  test('should register a new user', async () => {
    await reporter.step('Fill out registration form', () => {
      // Registration form logic
    });
 
    await reporter.step('Submit registration form', () => {
      // Form submission logic
    });
 
    await reporter.step('Verify confirmation email', () => {
      // Email verification logic
    });
  });
});

Standalone Usage Example

For standalone scripts or custom test runners:

import reporter from '@qaflow/report';
 
async function runMyCustomTest() {
  // Initialize reporter
  reporter.initialize('your-api-key-here');
  
  // Create a test
  reporter.createTest(
    'API Integration Test',
    'Tests the integration with our payment gateway',
    { author: 'API Tester', email: 'api@example.com' },
    { name: 'Node.js Script', version: process.version, os: process.platform }
  );
  
  try {
    // Test steps
    await reporter.step('Initialize API client', () => {
      console.log('Initializing API client...');
    });
    
    await reporter.step('Generate test order', async () => {
      console.log('Generating test order...');
      const order = { id: 12345, amount: 99.99 };
      return order;
    });
    
    await reporter.step('Send payment request', async () => {
      console.log('Sending payment request...');
      // Simulate API request
      return new Promise(resolve => setTimeout(() => resolve(true), 500));
    });
    
    await reporter.step('Verify payment success', async () => {
      console.log('Verifying payment success...');
    });
    
    // End the test
    const results = await reporter.end();
    console.log('Test completed!');
    console.log(results);
  } catch (error) {
    console.error('Test failed:', error);
    // Ensure test is ended even on error
    await reporter.end();
  }
}
 
runMyCustomTest().catch(console.error);

These examples should help you get started with QAFlow Reporter in your testing workflows. For more detailed API documentation, see the API Reference section.

On this page