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

Installation & Usage
Setup from scratch (sample project)
- Clone the repository:
git clone https://github.com/agentq-ai/webdriverio_typescript.git- Install dependencies:
npm install- Install AgentQ package:
npm install agentq-webdriverioConfiguration
1. AgentQ Config
Create agentq.config.json in your root directory (this is the same company API key from your account profile, also used as AGENTQ_API_KEY below):
{
"TOKEN": "YOUR_API_KEY"
}2. Environment Variables
Create a .env file (or set CI variables) with your AgentQ credentials:
AGENTQ_API_KEY=your_api_key # same API key as TOKEN in agentq.config.json
AGENTQ_PROJECT_ID=your_project_id
AGENTQ_TESTRUN_ID=your_testrun_id
AGENTQ_EMAIL=your_email # optional: results show this member as "Created By" (owner or invited member of the key's company)With AGENTQ_API_KEY set, no password is needed — test results, screenshots, and videos are pushed to your test run using the API key directly. Add AGENTQ_EMAIL (any member of your company — owner or invited) if you want pushed results attributed to that person instead of the API key.
Legacy fallback: if
AGENTQ_API_KEYis not set, the library falls back toAGENTQ_EMAILandAGENTQ_PASSWORDlogin.
Tip for CI (e.g. GitHub Actions): store
AGENTQ_API_KEYas a secret and export it in the workflow — API key auth skips the login endpoint entirely.
3. WebdriverIO Config (wdio.conf.ts)
Update your wdio.conf.ts to include AgentQ hooks for initialization and artifact uploads:
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 ? 'passed' : 'failed',
Date.now() - duration,
error?.message
);
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.
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:
source .env && npx wdio run ./wdio.conf.tsCLI Tools
Pull test cases or suites directly into your project:
npx agentq-pull-testcase -- --tcid=YOUR_TC_ID # e.g. --tcid=1
npx agentq-pull-testsuite -- --testrunid=YOUR_TESTRUN_ID # e.g. --testrunid=57e67dc7-c54d-42bc-a90d-409add62accePlans and Rate Limits
For details on Free or Enterprise plans, visit www.agentq.id or contact support@agentq.id.
