Skip to content

LambdaTest/lambdatest-codeceptjs-sample

Repository files navigation

LambdaTest CodeceptJS Sample - Desktop & Android Real Device

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.

Prerequisites

  • Node.js (v14 or higher)
  • npm (Node Package Manager)
  • LambdaTest Account (Sign up here)

Install Node Package Manager

Download & Install Node.js and npm from: https://nodejs.org/

Project Setup

1. Clone or Download the Repository

git clone https://github.com/LambdaTest/lambdatest-codeceptjs-sample.git
cd lambdatest-codeceptjs-sample

2. Install Dependencies

npm install

Configuration

Set LambdaTest Credentials

Get your Username and Access Key from LambdaTest Automation Dashboard

For Windows (Command Prompt):

set LT_USERNAME=YOUR_USERNAME
set LT_ACCESS_KEY=YOUR_ACCESS_KEY

For Windows (PowerShell):

$env:LT_USERNAME="YOUR_USERNAME"
$env:LT_ACCESS_KEY="YOUR_ACCESS_KEY"

For Linux/macOS:

export LT_USERNAME="YOUR_USERNAME"
export LT_ACCESS_KEY="YOUR_ACCESS_KEY"

Project Structure

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

Configuration Files

Desktop Web Automation (codecept.conf.js)

Configured for desktop browser testing on LambdaTest Selenium Grid:

  • Platform: Windows 10
  • Browser: Chrome (latest)
  • Hub: hub.lambdatest.com

Android Real Device (codecept.android.conf.js)

Configured for Android real device testing on LambdaTest Real Device Cloud:

  • Platform: Android
  • Device: Configurable (Pixel, Galaxy, etc.)
  • Hub: mobile-hub.lambdatest.com

Sample Android Capabilities:

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
  }
}

Running Tests

Run Desktop Web Tests

npm run test:desktop

Run Android Real Device Tests

npm run test:android

Run All Tests (Default - Desktop)

npm test

Run Specific Test File

npx codeceptjs run googleTest_test.js --steps
npx codeceptjs run androidTest_test.js --steps -c codecept.android.conf.js

Available NPM Scripts

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

Customizing Tests

Adding New Desktop 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');
});

Adding New Android Tests

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);
});

Supported Devices and Platforms

Desktop Browsers

  • Chrome, Firefox, Safari, Edge, IE
  • Windows, macOS, Linux
  • Multiple versions available

Android Real Devices

  • Samsung Galaxy series (S24, S23, S22, etc.)
  • Google Pixel series (Pixel 8, Pixel 7, etc.)
  • OnePlus, Xiaomi, and more
  • Android versions 9 to 14+

Finding Device Details

Generate capabilities for specific devices:

Device Name Patterns

You can use regex patterns for device selection:

"deviceName": "Galaxy.*"     // Any Galaxy device
"deviceName": "Pixel.*"      // Any Pixel device
"deviceName": "Galaxy S24"   // Specific device

Additional Capability Options

Desktop Web Capabilities

desiredCapabilities: {
  name: "Test Name",
  build: "Build Name",
  platformName: "Windows 10",
  browserName: "Chrome",
  version: "latest",
  resolution: "1920x1080",
  video: true,
  network: true,
  console: true,
  visual: true
}

Android Real Device Capabilities

"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"
}

Viewing Test Results

After running tests, view results on:

Features available in dashboard:

  • Video recordings
  • Screenshots
  • Network logs
  • Console logs
  • Test metadata
  • Performance metrics

Troubleshooting

Common Issues

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 seconds

Issue 4: Windows Script Error

SyntaxError: missing ) after argument list

Solution: Use npx codeceptjs or just codeceptjs in scripts instead of direct path.

Debug Mode

Run tests in debug mode with verbose output:

npx codeceptjs run --steps --debug -c codecept.android.conf.js

Parallel Testing

For running tests in parallel, you can modify your configuration:

// codecept.conf.js
exports.config = {
  // ... other config
  multiple: {
    parallel: {
      chunks: 2,
      browsers: ['chrome', 'firefox']
    }
  }
}

Best Practices

  1. Use explicit waits instead of hard waits when possible
  2. Use environment variables for sensitive data
  3. Keep test data separate from test logic
  4. Use descriptive test names and scenario descriptions
  5. Organize tests by feature or functionality
  6. Clean up test data after test execution
  7. Use Page Objects for complex applications (optional)

Resources

About LambdaTest

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.

Support

For issues and questions:

License

ISC

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


Happy Testing! 🚀

About

Sample CodeceptJS with webdriverio Automation Scripts For LambdaTest Selenium Grid

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors