Sample CodeceptJS with WebDriverIO Automation Scripts for LambdaTest Selenium Grid and Real Device Cloud. This project supports both desktop web automation and Android real device testing.
- Node.js (v14 or higher)
- npm (Node Package Manager)
- LambdaTest Account (Sign up here)
Download & Install Node.js and npm from: https://nodejs.org/
git clone https://github.com/LambdaTest/lambdatest-codeceptjs-sample.git
cd lambdatest-codeceptjs-samplenpm installGet your Username and Access Key from LambdaTest Automation Dashboard
set LT_USERNAME=YOUR_USERNAME
set LT_ACCESS_KEY=YOUR_ACCESS_KEY$env:LT_USERNAME="YOUR_USERNAME"
$env:LT_ACCESS_KEY="YOUR_ACCESS_KEY"export LT_USERNAME="YOUR_USERNAME"
export LT_ACCESS_KEY="YOUR_ACCESS_KEY"lambdatest-codeceptjs-sample/
├── codecept.conf.js # Desktop web automation config
├── codecept.android.conf.js # Android real device config
├── googleTest_test.js # Desktop web test
├── androidTest_test.js # Android real device test
├── steps_file.js # Custom step definitions
├── steps.d.ts # TypeScript definitions
├── package.json # Project dependencies and scripts
├── jsconfig.json # JavaScript config
└── README.md # This file
Configured for desktop browser testing on LambdaTest Selenium Grid:
- Platform: Windows 10
- Browser: Chrome (latest)
- Hub: hub.lambdatest.com
Configured for Android real device testing on LambdaTest Real Device Cloud:
- Platform: Android
- Device: Configurable (Pixel, Galaxy, etc.)
- Hub: mobile-hub.lambdatest.com
desiredCapabilities: {
"lt:options": {
"w3c": true,
"platformName": "android",
"deviceName": "Galaxy S24", // Specific device
"platformVersion": "14",
"isRealMobile": true,
"build": "CodeceptJS Android Build",
"name": "Android Test",
"video": true, // Record video
"visual": true, // Visual logs
"network": true, // Network logs
"console": true // Console logs
}
}npm run test:desktopnpm run test:androidnpm testnpx codeceptjs run googleTest_test.js --steps
npx codeceptjs run androidTest_test.js --steps -c codecept.android.conf.js| Script | Description |
|---|---|
npm test |
Run desktop web tests with default config |
npm run test:desktop |
Run desktop web automation tests |
npm run test:android |
Run Android real device tests |
Create a new test file (e.g., myTest_test.js):
const { I } = inject();
Feature('My Feature');
Scenario('My test scenario', async ({ I }) => {
await I.amOnPage('https://example.com');
await I.see('Example Domain');
});Create a new test file with mobile-specific selectors:
const { I } = inject();
Feature('Mobile Feature');
Scenario('test on android device', async ({ I }) => {
await I.amOnPage('https://www.google.com');
await I.waitForElement('textarea[name="q"]', 10);
await I.fillField('textarea[name="q"]', 'LambdaTest');
await I.pressKey('Enter');
await I.wait(2);
});- Chrome, Firefox, Safari, Edge, IE
- Windows, macOS, Linux
- Multiple versions available
- Samsung Galaxy series (S24, S23, S22, etc.)
- Google Pixel series (Pixel 8, Pixel 7, etc.)
- OnePlus, Xiaomi, and more
- Android versions 9 to 14+
Generate capabilities for specific devices:
You can use regex patterns for device selection:
"deviceName": "Galaxy.*" // Any Galaxy device
"deviceName": "Pixel.*" // Any Pixel device
"deviceName": "Galaxy S24" // Specific devicedesiredCapabilities: {
name: "Test Name",
build: "Build Name",
platformName: "Windows 10",
browserName: "Chrome",
version: "latest",
resolution: "1920x1080",
video: true,
network: true,
console: true,
visual: true
}"lt:options": {
"w3c": true,
"platformName": "android",
"deviceName": "Galaxy S24",
"platformVersion": "14",
"isRealMobile": true,
"build": "Build Name",
"name": "Test Name",
"deviceOrientation": "portrait", // or "landscape"
"video": true,
"visual": true,
"network": true,
"console": true,
"geoLocation": "US",
"timezone": "UTC"
}After running tests, view results on:
Features available in dashboard:
- Video recordings
- Screenshots
- Network logs
- Console logs
- Test metadata
- Performance metrics
Issue 1: Authentication Error
Error: Invalid credentials
Solution: Verify your LT_USERNAME and LT_ACCESS_KEY environment variables are set correctly.
Issue 2: Device Not Available
Error: Device not found
Solution: Check device availability on LambdaTest platform or use regex pattern like "Galaxy.*"
Issue 3: Timeout Errors
Error: Timeout waiting for element
Solution: Increase wait time or check element selectors:
await I.waitForElement('selector', 15); // 15 secondsIssue 4: Windows Script Error
SyntaxError: missing ) after argument list
Solution: Use npx codeceptjs or just codeceptjs in scripts instead of direct path.
Run tests in debug mode with verbose output:
npx codeceptjs run --steps --debug -c codecept.android.conf.jsFor running tests in parallel, you can modify your configuration:
// codecept.conf.js
exports.config = {
// ... other config
multiple: {
parallel: {
chunks: 2,
browsers: ['chrome', 'firefox']
}
}
}- Use explicit waits instead of hard waits when possible
- Use environment variables for sensitive data
- Keep test data separate from test logic
- Use descriptive test names and scenario descriptions
- Organize tests by feature or functionality
- Clean up test data after test execution
- Use Page Objects for complex applications (optional)
- CodeceptJS Documentation
- LambdaTest Documentation
- LambdaTest Capabilities Generator
- LambdaTest Community
- WebDriverIO Documentation
LambdaTest is a cloud-based testing platform that provides:
- 3000+ Browser & OS combinations for desktop web testing
- Real Android and iOS devices for mobile app and web testing
- Selenium Grid for automated cross-browser testing
- Appium Grid for mobile automation
- Parallel testing to reduce execution time
- CI/CD integrations with Jenkins, CircleCI, Travis, GitLab, and more
- Debugging tools including video recordings, screenshots, and logs
Perfect for bringing your selenium automation testing and mobile app testing to a scalable cloud infrastructure.
For issues and questions:
ISC
Contributions are welcome! Please feel free to submit a Pull Request.
Happy Testing! 🚀