Skip to content

WebdriverIO

Integrate WebdriverIO (TypeScript) with AgentQ AI for AI-driven automation and automated reporting.

AgentQ WebdriverIO Integration

Installation & Usage

Setup from scratch (sample project)

  1. Clone the repository:
bash
git clone https://github.com/agentq-ai/webdriverio_typescript.git
  1. Install dependencies:
bash
npm install
  1. Install AgentQ package:
bash
npm install agentq-webdriverio

Configuration

1. AgentQ Config

Create agentq.config.json in your root directory:

json
{
  "TOKEN": "YOUR_API_KEY"
}

2. Environment Variables

Create a .env file with your AgentQ credentials:

env
AGENTQ_PROJECT_ID=your_project_id
AGENTQ_TESTRUN_ID=your_testrun_id
AGENTQ_EMAIL=your_email
AGENTQ_PASSWORD=your_password

3. WebdriverIO Config (wdio.conf.ts)

Update your wdio.conf.ts to include AgentQ hooks for initialization and artifact uploads:

typescript
import { initAgentQ, handleTestConclusion, uploadArtifact } from 'agentq-webdriverio';
import fs from 'fs';
import path from 'path';

const testResultIds: { [key: string]: string } = {};

export const config: WebdriverIO.Config = {
    // ... other config

    // Initialize AgentQ before the session starts
    before: function (capabilities, specs) {
        initAgentQ(browser);
    },

    // Report results and capture screenshots after each test
    afterTest: async function(test, context, { error, result, duration, passed, retries }) {
        const testResult = await handleTestConclusion(test.title, passed);
        
        if (testResult && testResult.id && process.env.AGENTQ_TESTRUN_ID) {
            testResultIds[test.title] = testResult.id;

            // Capture and upload screenshot
            try {
                const timestamp = new Date().toISOString().replace(/:/g, '-');
                const screenshotPath = path.join('./test-results', `screenshot_${test.title}_${timestamp}.png`);
                await browser.saveScreenshot(screenshotPath);
                
                await uploadArtifact(
                    process.env.AGENTQ_TESTRUN_ID,
                    testResult.id,
                    'screenshot',
                    screenshotPath
                );
            } catch (err) {
                console.warn(`[AgentQ] Failed to capture/upload screenshot: ${err.message}`);
            }
        }
    },

    // Batch upload videos after the spec file is finished
    after: async function (result, capabilities, specs) {
        // Wait for video reporter to finalize files
        await new Promise(resolve => setTimeout(resolve, 10000));

        const resultsDir = './test-results';
        if (fs.existsSync(resultsDir)) {
            const files = fs.readdirSync(resultsDir);
            for (const title of Object.keys(testResultIds)) {
                const sanitizedTitle = title.replace(/\s+/g, '-').replace(/[()]/g, '');
                const matchingFiles = files
                    .filter(f => f.startsWith(sanitizedTitle) && f.endsWith('.webm'))
                    .map(f => ({ name: f, time: fs.statSync(path.join(resultsDir, f)).mtime.getTime() }))
                    .sort((a, b) => b.time - a.time);

                if (matchingFiles.length > 0 && process.env.AGENTQ_TESTRUN_ID) {
                    await uploadArtifact(
                        process.env.AGENTQ_TESTRUN_ID,
                        testResultIds[title],
                        'video',
                        path.join(resultsDir, matchingFiles[0].name)
                    );
                }
            }
        }
    }
};

Usage

AI-Driven Test Example

Import q and test from agentq-webdriverio. Prefix titles with Case IDs (e.g., 17-) for dashboard mapping.

typescript
import { q, test } from 'agentq-webdriverio';

describe('AI Automation Flow', () => {
    test('17-should login using AI instructions', async () => {
        await browser.url('https://the-internet.herokuapp.com/login');

        // Execute actions using natural language
        await q('user fill username tomsmith');
        await q('user fill password SuperSecretPassword!');
        await q('user click login button');

        // Standard assertions
        const flashAlert = await $('#flash');
        await expect(flashAlert).toHaveText(
            expect.stringContaining('You logged into a secure area!')
        );
    });
});

Running Tests

Run with environment variables:

bash
source .env && npx wdio run ./wdio.conf.ts

CLI Tools

Pull test cases or suites directly into your project:

bash
npx agentq-pull-testcase -- --tcid=YOUR_TESTRUN_ID{{1}}       
npx agentq-pull-testsuite -- --testrunid=YOUR_TESTRUN_ID{{57e67dc7-c54d-42bc-a90d-409add62acce}}

Plans and Rate Limits

For details on Free or Enterprise plans, visit www.agentq.id or contact [email protected].

Released under the MIT License.