|
1 | | -# LambdaTest Codeceptjs Sample |
2 | | -Sample CodeceptJS with webdriverio Automation Scripts For LambdaTest Selenium Grid |
3 | | - |
| 1 | +# LambdaTest CodeceptJS Sample - Desktop & Android Real Device |
4 | 2 |
|
5 | | -## Install Node package manager |
6 | | -- Download & Install node package manager from |
7 | | - https://www.npmjs.com/get-npm |
| 3 | +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. |
8 | 4 |
|
9 | | -## Install Selenium codeceptjs & webdriverio |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Node.js (v14 or higher) |
| 8 | +- npm (Node Package Manager) |
| 9 | +- LambdaTest Account ([Sign up here](https://accounts.lambdatest.com/register)) |
| 10 | + |
| 11 | +## Install Node Package Manager |
| 12 | + |
| 13 | +Download & Install Node.js and npm from: |
| 14 | +https://nodejs.org/ |
| 15 | + |
| 16 | +## Project Setup |
| 17 | + |
| 18 | +### 1. Clone or Download the Repository |
| 19 | +```bash |
| 20 | +git clone https://github.com/LambdaTest/lambdatest-codeceptjs-sample.git |
| 21 | +cd lambdatest-codeceptjs-sample |
| 22 | +``` |
| 23 | + |
| 24 | +### 2. Install Dependencies |
10 | 25 | ```bash |
11 | 26 | npm install |
12 | 27 | ``` |
13 | 28 |
|
14 | | -### Configuring test. |
15 | | -- Replace {LT username} with your username in codecept.conf.js and .gitlab-ci.yml |
16 | | -- Replace {LT accesskey} with your username in codecept.conf.js |
17 | | -- List of supported platfrom, browser, version can be found at https://www.lambdatest.com/capabilities-generator/ |
| 29 | +## Configuration |
| 30 | + |
| 31 | +### Set LambdaTest Credentials |
| 32 | + |
| 33 | +Get your Username and Access Key from [LambdaTest Automation Dashboard](https://automation.lambdatest.com/) |
| 34 | + |
| 35 | +#### For Windows (Command Prompt): |
| 36 | +```bash |
| 37 | +set LT_USERNAME=YOUR_USERNAME |
| 38 | +set LT_ACCESS_KEY=YOUR_ACCESS_KEY |
| 39 | +``` |
18 | 40 |
|
19 | | -### Set LambdaTest `Username` and `Access Key` in environment variables. |
| 41 | +#### For Windows (PowerShell): |
| 42 | +```powershell |
| 43 | +$env:LT_USERNAME="YOUR_USERNAME" |
| 44 | +$env:LT_ACCESS_KEY="YOUR_ACCESS_KEY" |
| 45 | +``` |
20 | 46 |
|
21 | | - * For **Linux/macOS**: |
22 | | - ```bash |
23 | | - export LT_USERNAME="YOUR_USERNAME" export LT_ACCESS_KEY="YOUR ACCESS KEY" |
24 | | - ``` |
25 | | - * For **Windows**: |
26 | | - ```bash |
27 | | - set LT_USERNAME="YOUR_USERNAME" set LT_ACCESS_KEY="YOUR ACCESS KEY" |
28 | | - ``` |
29 | | -### Executing test |
| 47 | +#### For Linux/macOS: |
| 48 | +```bash |
| 49 | +export LT_USERNAME="YOUR_USERNAME" |
| 50 | +export LT_ACCESS_KEY="YOUR_ACCESS_KEY" |
| 51 | +``` |
| 52 | + |
| 53 | +## Project Structure |
| 54 | +``` |
| 55 | +lambdatest-codeceptjs-sample/ |
| 56 | +├── codecept.conf.js # Desktop web automation config |
| 57 | +├── codecept.android.conf.js # Android real device config |
| 58 | +├── googleTest_test.js # Desktop web test |
| 59 | +├── androidTest_test.js # Android real device test |
| 60 | +├── steps_file.js # Custom step definitions |
| 61 | +├── steps.d.ts # TypeScript definitions |
| 62 | +├── package.json # Project dependencies and scripts |
| 63 | +├── jsconfig.json # JavaScript config |
| 64 | +└── README.md # This file |
| 65 | +``` |
| 66 | + |
| 67 | +## Configuration Files |
| 68 | + |
| 69 | +### Desktop Web Automation (codecept.conf.js) |
| 70 | + |
| 71 | +Configured for desktop browser testing on LambdaTest Selenium Grid: |
| 72 | +- **Platform:** Windows 10 |
| 73 | +- **Browser:** Chrome (latest) |
| 74 | +- **Hub:** hub.lambdatest.com |
| 75 | + |
| 76 | +### Android Real Device (codecept.android.conf.js) |
| 77 | + |
| 78 | +Configured for Android real device testing on LambdaTest Real Device Cloud: |
| 79 | +- **Platform:** Android |
| 80 | +- **Device:** Configurable (Pixel, Galaxy, etc.) |
| 81 | +- **Hub:** mobile-hub.lambdatest.com |
| 82 | + |
| 83 | +#### Sample Android Capabilities: |
| 84 | +```javascript |
| 85 | +desiredCapabilities: { |
| 86 | + "lt:options": { |
| 87 | + "w3c": true, |
| 88 | + "platformName": "android", |
| 89 | + "deviceName": "Galaxy S24", // Specific device |
| 90 | + "platformVersion": "14", |
| 91 | + "isRealMobile": true, |
| 92 | + "build": "CodeceptJS Android Build", |
| 93 | + "name": "Android Test", |
| 94 | + "video": true, // Record video |
| 95 | + "visual": true, // Visual logs |
| 96 | + "network": true, // Network logs |
| 97 | + "console": true // Console logs |
| 98 | + } |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +## Running Tests |
| 103 | + |
| 104 | +### Run Desktop Web Tests |
| 105 | +```bash |
| 106 | +npm run test:desktop |
| 107 | +``` |
| 108 | + |
| 109 | +### Run Android Real Device Tests |
| 110 | +```bash |
| 111 | +npm run test:android |
| 112 | +``` |
| 113 | + |
| 114 | +### Run All Tests (Default - Desktop) |
30 | 115 | ```bash |
31 | 116 | npm test |
32 | 117 | ``` |
| 118 | + |
| 119 | +### Run Specific Test File |
| 120 | +```bash |
| 121 | +npx codeceptjs run googleTest_test.js --steps |
| 122 | +npx codeceptjs run androidTest_test.js --steps -c codecept.android.conf.js |
| 123 | +``` |
| 124 | + |
| 125 | +## Available NPM Scripts |
| 126 | + |
| 127 | +| Script | Description | |
| 128 | +|--------|-------------| |
| 129 | +| `npm test` | Run desktop web tests with default config | |
| 130 | +| `npm run test:desktop` | Run desktop web automation tests | |
| 131 | +| `npm run test:android` | Run Android real device tests | |
| 132 | + |
| 133 | +## Customizing Tests |
| 134 | + |
| 135 | +### Adding New Desktop Tests |
| 136 | + |
| 137 | +Create a new test file (e.g., `myTest_test.js`): |
| 138 | +```javascript |
| 139 | +const { I } = inject(); |
| 140 | + |
| 141 | +Feature('My Feature'); |
| 142 | + |
| 143 | +Scenario('My test scenario', async ({ I }) => { |
| 144 | + await I.amOnPage('https://example.com'); |
| 145 | + await I.see('Example Domain'); |
| 146 | +}); |
| 147 | +``` |
| 148 | + |
| 149 | +### Adding New Android Tests |
| 150 | + |
| 151 | +Create a new test file with mobile-specific selectors: |
| 152 | +```javascript |
| 153 | +const { I } = inject(); |
| 154 | + |
| 155 | +Feature('Mobile Feature'); |
| 156 | + |
| 157 | +Scenario('test on android device', async ({ I }) => { |
| 158 | + await I.amOnPage('https://www.google.com'); |
| 159 | + await I.waitForElement('textarea[name="q"]', 10); |
| 160 | + await I.fillField('textarea[name="q"]', 'LambdaTest'); |
| 161 | + await I.pressKey('Enter'); |
| 162 | + await I.wait(2); |
| 163 | +}); |
| 164 | +``` |
| 165 | + |
| 166 | +## Supported Devices and Platforms |
| 167 | + |
| 168 | +### Desktop Browsers |
| 169 | +- Chrome, Firefox, Safari, Edge, IE |
| 170 | +- Windows, macOS, Linux |
| 171 | +- Multiple versions available |
| 172 | + |
| 173 | +### Android Real Devices |
| 174 | +- Samsung Galaxy series (S24, S23, S22, etc.) |
| 175 | +- Google Pixel series (Pixel 8, Pixel 7, etc.) |
| 176 | +- OnePlus, Xiaomi, and more |
| 177 | +- Android versions 9 to 14+ |
| 178 | + |
| 179 | +### Finding Device Details |
| 180 | +Generate capabilities for specific devices: |
| 181 | +- [LambdaTest Capabilities Generator](https://www.lambdatest.com/capabilities-generator/) |
| 182 | +- [LambdaTest Real Device List](https://www.lambdatest.com/list-of-browsers) |
| 183 | + |
| 184 | +## Device Name Patterns |
| 185 | + |
| 186 | +You can use regex patterns for device selection: |
| 187 | +```javascript |
| 188 | +"deviceName": "Galaxy.*" // Any Galaxy device |
| 189 | +"deviceName": "Pixel.*" // Any Pixel device |
| 190 | +"deviceName": "Galaxy S24" // Specific device |
| 191 | +``` |
| 192 | + |
| 193 | +## Additional Capability Options |
| 194 | + |
| 195 | +### Desktop Web Capabilities |
| 196 | +```javascript |
| 197 | +desiredCapabilities: { |
| 198 | + name: "Test Name", |
| 199 | + build: "Build Name", |
| 200 | + platformName: "Windows 10", |
| 201 | + browserName: "Chrome", |
| 202 | + version: "latest", |
| 203 | + resolution: "1920x1080", |
| 204 | + video: true, |
| 205 | + network: true, |
| 206 | + console: true, |
| 207 | + visual: true |
| 208 | +} |
| 209 | +``` |
| 210 | + |
| 211 | +### Android Real Device Capabilities |
| 212 | +```javascript |
| 213 | +"lt:options": { |
| 214 | + "w3c": true, |
| 215 | + "platformName": "android", |
| 216 | + "deviceName": "Galaxy S24", |
| 217 | + "platformVersion": "14", |
| 218 | + "isRealMobile": true, |
| 219 | + "build": "Build Name", |
| 220 | + "name": "Test Name", |
| 221 | + "deviceOrientation": "portrait", // or "landscape" |
| 222 | + "video": true, |
| 223 | + "visual": true, |
| 224 | + "network": true, |
| 225 | + "console": true, |
| 226 | + "geoLocation": "US", |
| 227 | + "timezone": "UTC" |
| 228 | +} |
| 229 | +``` |
| 230 | + |
| 231 | +## Viewing Test Results |
| 232 | + |
| 233 | +After running tests, view results on: |
| 234 | +- [LambdaTest Automation Dashboard](https://automation.lambdatest.com/) |
| 235 | +- [LambdaTest Real Device Dashboard](https://appautomation.lambdatest.com/) |
| 236 | + |
| 237 | +Features available in dashboard: |
| 238 | +- Video recordings |
| 239 | +- Screenshots |
| 240 | +- Network logs |
| 241 | +- Console logs |
| 242 | +- Test metadata |
| 243 | +- Performance metrics |
| 244 | + |
| 245 | +## Troubleshooting |
| 246 | + |
| 247 | +### Common Issues |
| 248 | + |
| 249 | +**Issue 1: Authentication Error** |
| 250 | +``` |
| 251 | +Error: Invalid credentials |
| 252 | +``` |
| 253 | +**Solution:** Verify your LT_USERNAME and LT_ACCESS_KEY environment variables are set correctly. |
| 254 | + |
| 255 | +**Issue 2: Device Not Available** |
| 256 | +``` |
| 257 | +Error: Device not found |
| 258 | +``` |
| 259 | +**Solution:** Check device availability on LambdaTest platform or use regex pattern like "Galaxy.*" |
| 260 | + |
| 261 | +**Issue 3: Timeout Errors** |
| 262 | +``` |
| 263 | +Error: Timeout waiting for element |
| 264 | +``` |
| 265 | +**Solution:** Increase wait time or check element selectors: |
| 266 | +```javascript |
| 267 | +await I.waitForElement('selector', 15); // 15 seconds |
| 268 | +``` |
| 269 | + |
| 270 | +**Issue 4: Windows Script Error** |
| 271 | +``` |
| 272 | +SyntaxError: missing ) after argument list |
| 273 | +``` |
| 274 | +**Solution:** Use `npx codeceptjs` or just `codeceptjs` in scripts instead of direct path. |
| 275 | + |
| 276 | +## Debug Mode |
| 277 | + |
| 278 | +Run tests in debug mode with verbose output: |
| 279 | +```bash |
| 280 | +npx codeceptjs run --steps --debug -c codecept.android.conf.js |
| 281 | +``` |
| 282 | + |
| 283 | +## Parallel Testing |
| 284 | + |
| 285 | +For running tests in parallel, you can modify your configuration: |
| 286 | +```javascript |
| 287 | +// codecept.conf.js |
| 288 | +exports.config = { |
| 289 | + // ... other config |
| 290 | + multiple: { |
| 291 | + parallel: { |
| 292 | + chunks: 2, |
| 293 | + browsers: ['chrome', 'firefox'] |
| 294 | + } |
| 295 | + } |
| 296 | +} |
| 297 | +``` |
| 298 | + |
| 299 | +## Best Practices |
| 300 | + |
| 301 | +1. **Use explicit waits** instead of hard waits when possible |
| 302 | +2. **Use environment variables** for sensitive data |
| 303 | +3. **Keep test data separate** from test logic |
| 304 | +4. **Use descriptive test names** and scenario descriptions |
| 305 | +5. **Organize tests** by feature or functionality |
| 306 | +6. **Clean up test data** after test execution |
| 307 | +7. **Use Page Objects** for complex applications (optional) |
| 308 | + |
| 309 | +## Resources |
| 310 | + |
| 311 | +- [CodeceptJS Documentation](https://codecept.io/) |
| 312 | +- [LambdaTest Documentation](https://www.lambdatest.com/support/docs/) |
| 313 | +- [LambdaTest Capabilities Generator](https://www.lambdatest.com/capabilities-generator/) |
| 314 | +- [LambdaTest Community](https://community.lambdatest.com/) |
| 315 | +- [WebDriverIO Documentation](https://webdriver.io/) |
| 316 | + |
33 | 317 | ## About LambdaTest |
34 | 318 |
|
35 | | -[LambdaTest](https://www.lambdatest.com/) is a cloud based selenium grid infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [selenium automation testing](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel. |
| 319 | +[LambdaTest](https://www.lambdatest.com/) is a cloud-based testing platform that provides: |
| 320 | + |
| 321 | +- **3000+ Browser & OS combinations** for desktop web testing |
| 322 | +- **Real Android and iOS devices** for mobile app and web testing |
| 323 | +- **Selenium Grid** for automated cross-browser testing |
| 324 | +- **Appium Grid** for mobile automation |
| 325 | +- **Parallel testing** to reduce execution time |
| 326 | +- **CI/CD integrations** with Jenkins, CircleCI, Travis, GitLab, and more |
| 327 | +- **Debugging tools** including video recordings, screenshots, and logs |
| 328 | + |
| 329 | +Perfect for bringing your [selenium automation testing](https://www.lambdatest.com/selenium-automation) and [mobile app testing](https://www.lambdatest.com/real-device-cloud) to a scalable cloud infrastructure. |
| 330 | + |
| 331 | +## Support |
| 332 | + |
| 333 | +For issues and questions: |
| 334 | +- [GitHub Issues](https://github.com/LambdaTest/lambdatest-codeceptjs-sample/issues) |
| 335 | +- [LambdaTest Support](https://www.lambdatest.com/support/) |
| 336 | +- Email: support@lambdatest.com |
| 337 | + |
| 338 | +## License |
| 339 | + |
| 340 | +ISC |
| 341 | + |
| 342 | +## Contributing |
| 343 | + |
| 344 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 345 | + |
| 346 | +--- |
| 347 | + |
| 348 | +**Happy Testing! 🚀** |
0 commit comments