wdio-lambdatest-service-sdk 5.0.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +339 -36
- package/bin/cli.js +86 -0
- package/bin/generate-config.js +14 -166
- package/bin/setup.js +14 -128
- package/bin/wdio-lt.js +39 -0
- package/bun.lock +875 -0
- package/index.js +4 -5
- package/lib/cli/generate.js +526 -0
- package/lib/cli/setup.js +174 -0
- package/lib/cli/style.js +57 -0
- package/package.json +24 -4
- package/src/launcher.js +52 -29
- package/src/service.js +36 -40
package/README.md
CHANGED
|
@@ -1,38 +1,317 @@
|
|
|
1
1
|
# WDIO LambdaTest Service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
WebdriverIO service and CLI for running Appium and browser tests on [LambdaTest](https://www.lambdatest.com). This SDK handles authentication, test status updates on the LambdaTest dashboard, and provides an interactive CLI to generate and setup WDIO configs that connect directly to LambdaTest automation.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Features](#features)
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [Try the SDK / CLI with the Sample Project](#try-the-sdk--cli-with-the-sample-project)
|
|
12
|
+
- [Steps to Run the Sample Project](#steps-to-run-the-sample-project)
|
|
13
|
+
- [Specs Folder & Code Design](#specs-folder--code-design)
|
|
14
|
+
- [Generate Config That Connects to LT Automation](#generate-config-that-connects-to-lt-automation)
|
|
15
|
+
- [CLI Commands](#cli-commands)
|
|
16
|
+
- [Automated Setup](#automated-setup)
|
|
17
|
+
- [Config Generator](#config-generator)
|
|
18
|
+
- [Manual Configuration](#manual-configuration)
|
|
19
|
+
- [Development](#development)
|
|
20
|
+
- [License](#license)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **Authentication**: Pass `username` and `accessKey` in the service options or via the CLI.
|
|
27
|
+
- **Test Status Updates**: Automatically marks tests as Passed/Failed on the LambdaTest dashboard using Lambda Hooks.
|
|
28
|
+
- **Logs**: Clean, colorful status logs in the terminal.
|
|
29
|
+
- **CLI**: Interactive config generator and setup tool (Commander, Chalk, Inquirer; runs with Bun or Node.js).
|
|
30
|
+
- **Multi-select**: Choose multiple test types, device types, platforms, and app/website targets in one config.
|
|
31
|
+
|
|
32
|
+
---
|
|
8
33
|
|
|
9
34
|
## Installation
|
|
10
35
|
|
|
11
36
|
```bash
|
|
12
37
|
npm install wdio-lambdatest-service --save-dev
|
|
38
|
+
# or with Bun
|
|
39
|
+
bun add wdio-lambdatest-service --dev
|
|
13
40
|
```
|
|
14
41
|
|
|
15
|
-
|
|
42
|
+
---
|
|
16
43
|
|
|
17
|
-
##
|
|
44
|
+
## Try the SDK / CLI with the Sample Project
|
|
45
|
+
|
|
46
|
+
To verify the SDK and CLI work end-to-end, clone the official LambdaTest sample project and run tests using this service.
|
|
47
|
+
|
|
48
|
+
### 1. Clone the Sample Repository
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
git clone https://github.com/LambdaTest/LT-appium-nodejs-webdriverio
|
|
52
|
+
cd LT-appium-nodejs-webdriverio
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This repo contains:
|
|
56
|
+
|
|
57
|
+
- **android-sample/** – WebdriverIO + Appium configs and scripts for Android (real/virtual).
|
|
58
|
+
- **ios-sample/** – WebdriverIO + Appium configs and scripts for iOS.
|
|
59
|
+
- **specs/** – Shared test specs (e.g. `android-test.js`, `ios-test.js`) used by both samples.
|
|
60
|
+
|
|
61
|
+
### 2. Install the WDIO LambdaTest Service (SDK)
|
|
62
|
+
|
|
63
|
+
From the **repo root** (or from inside `android-sample` / `ios-sample` if you prefer):
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# From repo root – install SDK as dev dependency
|
|
67
|
+
npm install ./wdio-lambdatest-service --save-dev
|
|
68
|
+
# or, if the SDK is published:
|
|
69
|
+
npm install wdio-lambdatest-service
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 3. Set LambdaTest Credentials
|
|
73
|
+
|
|
74
|
+
Export your [LambdaTest](https://accounts.lambdatest.com) username and access key:
|
|
75
|
+
|
|
76
|
+
**Linux / macOS:**
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
export LT_USERNAME="your_username"
|
|
80
|
+
export LT_ACCESS_KEY="your_access_key"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Windows (CMD):**
|
|
84
|
+
|
|
85
|
+
```cmd
|
|
86
|
+
set LT_USERNAME=your_username
|
|
87
|
+
set LT_ACCESS_KEY=your_access_key
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Windows (PowerShell):**
|
|
91
|
+
|
|
92
|
+
```powershell
|
|
93
|
+
$env:LT_USERNAME = "your_username"
|
|
94
|
+
$env:LT_ACCESS_KEY = "your_access_key"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 4. Run the Sample Project
|
|
98
|
+
|
|
99
|
+
See [Steps to Run the Sample Project](#steps-to-run-the-sample-project) below for detailed run commands (single/parallel, Android/iOS).
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Steps to Run the Sample Project
|
|
104
|
+
|
|
105
|
+
After cloning [LT-appium-nodejs-webdriverio](https://github.com/LambdaTest/LT-appium-nodejs-webdriverio) and setting credentials:
|
|
106
|
+
|
|
107
|
+
### Android
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
cd android-sample
|
|
111
|
+
npm install
|
|
112
|
+
# Single test
|
|
113
|
+
npm run SingleAndroidApp
|
|
114
|
+
# Or run parallel (if defined in package.json)
|
|
115
|
+
npm run parallel
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### iOS
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
cd ios-sample
|
|
122
|
+
npm install
|
|
123
|
+
# Single test (script name may vary, e.g. SingleIosApp)
|
|
124
|
+
npm run single
|
|
125
|
+
# Or run parallel
|
|
126
|
+
npm run parallel
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Note:** Ensure config files in `android-sample` and `ios-sample` point to the correct spec paths (e.g. `../specs/android-test.js`, `../specs/ios-test.js`) and that the WDIO LambdaTest service is registered in `services` in those configs. Test results appear in the terminal and on the [LambdaTest App Automation Dashboard](https://appautomation.lambdatest.com/).
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Specs Folder & Code Design
|
|
134
|
+
|
|
135
|
+
The sample repo uses a **shared `specs/` folder** at the root so both Android and iOS (and any generated configs) can reuse the same test files.
|
|
136
|
+
|
|
137
|
+
Recommended layout (align with the sample repo):
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
LT-appium-nodejs-webdriverio/
|
|
141
|
+
├── android-sample/
|
|
142
|
+
│ ├── conf/ # or *.conf.js in root of android-sample
|
|
143
|
+
│ │ └── android.conf.js
|
|
144
|
+
│ ├── package.json
|
|
145
|
+
│ └── ...
|
|
146
|
+
├── ios-sample/
|
|
147
|
+
│ ├── conf/
|
|
148
|
+
│ │ └── ios.conf.js
|
|
149
|
+
│ ├── package.json
|
|
150
|
+
│ └── ...
|
|
151
|
+
├── specs/ # Shared test specs
|
|
152
|
+
│ ├── android-test.js
|
|
153
|
+
│ ├── ios-test.js
|
|
154
|
+
│ └── (your own specs)
|
|
155
|
+
├── wdio-lambdatest-service/ # This SDK (if developed locally)
|
|
156
|
+
└── package.json
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Design guidelines:**
|
|
160
|
+
|
|
161
|
+
- **One spec file per flow or platform** (e.g. `android-test.js`, `ios-test.js`, `web-test.js`) so configs can reference them clearly.
|
|
162
|
+
- **Use `specs: ["../specs/android-test.js"]`** (or similar relative path) in configs under `android-sample` so they point to the shared `specs/` folder.
|
|
163
|
+
- **Keep assertions and page interactions in the specs**; keep capabilities and environment in the config files.
|
|
164
|
+
- **Reuse the same spec** across different configs (e.g. single device vs parallel) by only changing the config, not the spec.
|
|
165
|
+
|
|
166
|
+
Following this structure makes it easy to add new configs (including those generated by `wdio-lt generate`) that point to the same `specs/` folder.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Generate Config That Connects to LT Automation
|
|
171
|
+
|
|
172
|
+
Use the CLI to generate a WDIO config that is **already wired to LambdaTest** (hostname, path, services, and capabilities).
|
|
173
|
+
|
|
174
|
+
### 1. Install the CLI
|
|
175
|
+
|
|
176
|
+
If the SDK is in the repo:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
cd LT-appium-nodejs-webdriverio
|
|
180
|
+
npm install ./wdio-lambdatest-service --save-dev
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Or install from npm (when published):
|
|
18
184
|
|
|
19
|
-
|
|
185
|
+
```bash
|
|
186
|
+
npm install wdio-lambdatest-service --save-dev
|
|
187
|
+
```
|
|
20
188
|
|
|
21
|
-
|
|
189
|
+
### 2. Run the Config Generator
|
|
22
190
|
|
|
23
191
|
```bash
|
|
24
|
-
#
|
|
25
|
-
|
|
192
|
+
# With Bun (recommended)
|
|
193
|
+
bun wdio-lt generate
|
|
26
194
|
|
|
27
|
-
#
|
|
28
|
-
|
|
195
|
+
# With Node.js
|
|
196
|
+
npx wdio-lt generate
|
|
29
197
|
```
|
|
30
198
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
199
|
+
### 3. Follow the Prompts
|
|
200
|
+
|
|
201
|
+
- **Test name** – Used for build name and config filename.
|
|
202
|
+
- **LambdaTest Username & Access Key** – Stored in the generated config (or use env vars and leave blank if you rely on `LT_USERNAME` / `LT_ACCESS_KEY`).
|
|
203
|
+
- **Test type(s)** – App Testing (Mobile) and/or Browser Testing (Desktop). You can select multiple.
|
|
204
|
+
- **Device type(s)** – Real Device, Virtual Device (for App Testing). Multi-select.
|
|
205
|
+
- **Platform(s)** – Android, iOS. Multi-select.
|
|
206
|
+
- **What do you want to test?** – Application (Native App), Website (Mobile Browser). Multi-select.
|
|
207
|
+
- **App ID(s)** – If you chose native app, enter the App URL (e.g. `lt://APP123456789`) per platform; you can use sample apps (e.g. `lt://proverbial-android`, `lt://proverbial-ios`).
|
|
208
|
+
- **Parallel threads** – 0 for sequential, or a number for parallel.
|
|
209
|
+
- **Spec file path** – Path to your test file, e.g. `./specs/test.js` or `../specs/android-test.js` relative to the generated config location.
|
|
210
|
+
|
|
211
|
+
### 4. Generated Output
|
|
212
|
+
|
|
213
|
+
The CLI writes:
|
|
214
|
+
|
|
215
|
+
- **Config file:** `LT_Test/<TestName>.conf.js` – Ready to run against LambdaTest (hostname, path, services, and capabilities set).
|
|
216
|
+
- **Package script:** In `LT_Test/package.json`, a script like `test:<TestName>` is added.
|
|
217
|
+
|
|
218
|
+
### 5. Run the Generated Config
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
cd LT_Test
|
|
222
|
+
npm install # if needed
|
|
223
|
+
npm run test:<TestName>
|
|
224
|
+
# or
|
|
225
|
+
npx wdio <TestName>.conf.js
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
To follow the same code design as the sample repo, set the **spec file path** during `wdio-lt generate` to your existing `specs/` folder, e.g. `../specs/android-test.js`, so the generated config reuses your shared specs.
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## CLI Commands
|
|
233
|
+
|
|
234
|
+
| Command | Description |
|
|
235
|
+
|--------|-------------|
|
|
236
|
+
| `wdio-lt setup [path]` | Inject LambdaTest service into existing WDIO config files |
|
|
237
|
+
| `wdio-lt generate` | Interactively generate a new WDIO config for LambdaTest |
|
|
238
|
+
| `wdio-lt init` | Alias for `generate` |
|
|
239
|
+
| `wdio-lt --help` | Show help |
|
|
240
|
+
| `wdio-lt --version` | Show version |
|
|
241
|
+
|
|
242
|
+
### Examples
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
# Setup – inject service into all .conf.js files in a directory
|
|
246
|
+
wdio-lt setup ./android-sample
|
|
247
|
+
|
|
248
|
+
# Setup – interactive mode (prompts for directory)
|
|
249
|
+
wdio-lt setup
|
|
250
|
+
|
|
251
|
+
# Generate – create a new config interactively
|
|
252
|
+
wdio-lt generate
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Running with Bun
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
curl -fsSL https://bun.sh/install | bash # Install Bun
|
|
259
|
+
bun wdio-lt setup ./android-sample
|
|
260
|
+
bun wdio-lt generate
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Running with Node.js
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
npx wdio-lt setup ./android-sample
|
|
267
|
+
npx wdio-lt generate
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Legacy Commands (backward compatible)
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
wdio-lambdatest-setup ./android-sample
|
|
274
|
+
wdio-lambdatest-generator
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## Automated Setup
|
|
280
|
+
|
|
281
|
+
The `setup` command updates existing WebdriverIO config files (`*.conf.js`) to use this SDK:
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
wdio-lt setup ./path/to/your/project
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
It will:
|
|
288
|
+
|
|
289
|
+
- Scan for `.conf.js` files recursively.
|
|
290
|
+
- Inject the service configuration.
|
|
291
|
+
- Set `logLevel` to `error` for cleaner output.
|
|
292
|
+
- Comment out hardcoded credentials so the SDK can use env vars or service options.
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## Config Generator
|
|
297
|
+
|
|
298
|
+
The `generate` command creates a new WDIO config with interactive prompts:
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
wdio-lt generate
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Features:
|
|
305
|
+
|
|
306
|
+
- Test name with validation
|
|
307
|
+
- LambdaTest username and access key (secure input)
|
|
308
|
+
- **Multi-select:** Test type(s), Device type(s), Platform(s), What to test (App / Website)
|
|
309
|
+
- App ID(s) per platform when testing native apps
|
|
310
|
+
- Parallel threads and spec file path with smart resolution
|
|
311
|
+
|
|
312
|
+
Generated configs are saved to `./LT_Test/<testName>.conf.js`.
|
|
313
|
+
|
|
314
|
+
---
|
|
36
315
|
|
|
37
316
|
## Manual Configuration
|
|
38
317
|
|
|
@@ -42,39 +321,63 @@ Add the service to your `wdio.conf.js`:
|
|
|
42
321
|
const path = require('path');
|
|
43
322
|
|
|
44
323
|
exports.config = {
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
logLevel: 'error', // Recommended to reduce noise
|
|
50
|
-
|
|
324
|
+
// user / key can be omitted if using service options or env
|
|
325
|
+
logLevel: 'error',
|
|
326
|
+
|
|
51
327
|
services: [
|
|
52
|
-
['lambdatest', {
|
|
53
|
-
|
|
54
|
-
|
|
328
|
+
[path.join(__dirname, 'node_modules/wdio-lambdatest-service'), {
|
|
329
|
+
user: process.env.LT_USERNAME,
|
|
330
|
+
key: process.env.LT_ACCESS_KEY
|
|
55
331
|
}]
|
|
56
332
|
],
|
|
57
333
|
// ...
|
|
58
334
|
};
|
|
59
335
|
```
|
|
60
336
|
|
|
61
|
-
If
|
|
337
|
+
If using the SDK from a local path (e.g. repo root):
|
|
62
338
|
|
|
63
339
|
```javascript
|
|
64
340
|
services: [
|
|
65
|
-
[path.join(__dirname, '
|
|
66
|
-
|
|
67
|
-
|
|
341
|
+
[path.join(__dirname, '../wdio-lambdatest-service'), {
|
|
342
|
+
user: process.env.LT_USERNAME,
|
|
343
|
+
key: process.env.LT_ACCESS_KEY
|
|
68
344
|
}]
|
|
69
345
|
],
|
|
70
346
|
```
|
|
71
347
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
- **Automatic Status Updates**: Checks test results in `afterTest` (Mocha/Jasmine) or `afterScenario` (Cucumber) and updates the LambdaTest job status.
|
|
75
|
-
- **Credential Management**: Can inject credentials if not already present in the main config.
|
|
76
|
-
- **Async Support**: Works seamlessly with both Sync and Async WebdriverIO execution modes.
|
|
348
|
+
---
|
|
77
349
|
|
|
78
350
|
## Development
|
|
79
351
|
|
|
80
|
-
This package
|
|
352
|
+
This package provides a **Service** (worker) and a **Launcher** (main process) for WebdriverIO.
|
|
353
|
+
|
|
354
|
+
### Project Structure
|
|
355
|
+
|
|
356
|
+
```
|
|
357
|
+
wdio-lambdatest-service/
|
|
358
|
+
├── bin/
|
|
359
|
+
│ ├── cli.js # Main CLI entry (Commander)
|
|
360
|
+
│ ├── setup.js # Setup command wrapper
|
|
361
|
+
│ └── generate-config.js # Generate command wrapper
|
|
362
|
+
├── lib/
|
|
363
|
+
│ └── cli/
|
|
364
|
+
│ ├── style.js # Chalk style utilities
|
|
365
|
+
│ ├── setup.js # Setup logic
|
|
366
|
+
│ └── generate.js # Generate logic (Inquirer prompts)
|
|
367
|
+
├── src/
|
|
368
|
+
│ ├── launcher.js # WDIO Launcher
|
|
369
|
+
│ └── service.js # WDIO Service
|
|
370
|
+
├── index.js # Main entry point
|
|
371
|
+
└── package.json
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### Requirements
|
|
375
|
+
|
|
376
|
+
- **Node.js**: >= 18.0.0
|
|
377
|
+
- **Bun**: >= 1.0.0 (optional, for faster CLI)
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
## License
|
|
382
|
+
|
|
383
|
+
ISC
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* LambdaTest WDIO CLI - Unified command-line interface.
|
|
4
|
+
* Powered by Commander, Chalk, and Inquirer.
|
|
5
|
+
* Runs with Bun (fast) or Node.js.
|
|
6
|
+
*/
|
|
7
|
+
const { Command } = require('commander');
|
|
8
|
+
const chalk = require('chalk');
|
|
9
|
+
const { runSetup } = require('../lib/cli/setup');
|
|
10
|
+
const { runGenerate } = require('../lib/cli/generate');
|
|
11
|
+
const pkg = require('../package.json');
|
|
12
|
+
|
|
13
|
+
const program = new Command();
|
|
14
|
+
|
|
15
|
+
// ASCII Art Logo
|
|
16
|
+
const logo = `
|
|
17
|
+
${chalk.cyan('╔═══════════════════════════════════════════════════════════╗')}
|
|
18
|
+
${chalk.cyan('║')} ${chalk.bold.white('🚀 LambdaTest WDIO CLI')} ${chalk.cyan('║')}
|
|
19
|
+
${chalk.cyan('║')} ${chalk.dim('Fast, powerful WebdriverIO configuration tool')} ${chalk.cyan('║')}
|
|
20
|
+
${chalk.cyan('╚═══════════════════════════════════════════════════════════╝')}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
program
|
|
24
|
+
.name('wdio-lt')
|
|
25
|
+
.description(chalk.dim('LambdaTest WebdriverIO CLI - Setup and configure WDIO projects'))
|
|
26
|
+
.version(pkg.version, '-v, --version', 'Display version number')
|
|
27
|
+
.helpOption('-h, --help', 'Display help for command')
|
|
28
|
+
.addHelpText('before', logo)
|
|
29
|
+
.addHelpText('after', `
|
|
30
|
+
${chalk.bold('Examples:')}
|
|
31
|
+
${chalk.green('$')} wdio-lt setup ./android-sample ${chalk.dim('# Inject service into configs')}
|
|
32
|
+
${chalk.green('$')} wdio-lt setup ${chalk.dim('# Interactive mode')}
|
|
33
|
+
${chalk.green('$')} wdio-lt generate ${chalk.dim('# Create new config')}
|
|
34
|
+
${chalk.green('$')} wdio-lt init ${chalk.dim('# Alias for generate')}
|
|
35
|
+
|
|
36
|
+
${chalk.bold('Documentation:')}
|
|
37
|
+
${chalk.cyan('https://github.com/LambdaTest')}
|
|
38
|
+
`);
|
|
39
|
+
|
|
40
|
+
// Setup command
|
|
41
|
+
program
|
|
42
|
+
.command('setup [path]')
|
|
43
|
+
.description('Inject LambdaTest service into existing WDIO config files')
|
|
44
|
+
.action(async (targetPath) => {
|
|
45
|
+
try {
|
|
46
|
+
await runSetup(targetPath);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(chalk.red.bold('\n✖ Error:'), e.message);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Generate command
|
|
54
|
+
program
|
|
55
|
+
.command('generate')
|
|
56
|
+
.alias('gen')
|
|
57
|
+
.description('Interactively generate a new WDIO config for LambdaTest')
|
|
58
|
+
.action(async () => {
|
|
59
|
+
try {
|
|
60
|
+
await runGenerate();
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error(chalk.red.bold('\n✖ Error:'), e.message);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Init command (alias for generate)
|
|
68
|
+
program
|
|
69
|
+
.command('init')
|
|
70
|
+
.description('Create a new WDIO config (alias for generate)')
|
|
71
|
+
.action(async () => {
|
|
72
|
+
try {
|
|
73
|
+
await runGenerate();
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error(chalk.red.bold('\n✖ Error:'), e.message);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Parse arguments
|
|
81
|
+
program.parse();
|
|
82
|
+
|
|
83
|
+
// Show help if no command provided
|
|
84
|
+
if (!process.argv.slice(2).length) {
|
|
85
|
+
program.outputHelp();
|
|
86
|
+
}
|
package/bin/generate-config.js
CHANGED
|
@@ -1,167 +1,15 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
key: '',
|
|
16
|
-
type: '', // 'app' or 'browser'
|
|
17
|
-
subType: '', // 'real', 'virtual', 'desktop', 'mobile-virtual', 'mobile-real'
|
|
18
|
-
parallel: 0,
|
|
19
|
-
specPath: ''
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const outputDir = path.resolve(process.cwd(), 'LT_Test');
|
|
23
|
-
|
|
24
|
-
// Ensure output dir exists
|
|
25
|
-
if (!fs.existsSync(outputDir)) {
|
|
26
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function ask(question, defaultVal) {
|
|
30
|
-
return new Promise((resolve) => {
|
|
31
|
-
rl.question(`${question}${defaultVal ? ` (${defaultVal})` : ''}: `, (answer) => {
|
|
32
|
-
resolve(answer.trim() || defaultVal);
|
|
33
|
-
});
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* LambdaTest WDIO Config Generator - Backward-compatible entry point.
|
|
4
|
+
* Delegates to lib/cli/generate.js
|
|
5
|
+
*
|
|
6
|
+
* Usage: wdio-lambdatest-generator
|
|
7
|
+
*/
|
|
8
|
+
const chalk = require('chalk');
|
|
9
|
+
const { runGenerate } = require('../lib/cli/generate');
|
|
10
|
+
|
|
11
|
+
runGenerate()
|
|
12
|
+
.catch((e) => {
|
|
13
|
+
console.error(chalk.red.bold('\n✖ Error:'), e.message);
|
|
14
|
+
process.exit(1);
|
|
34
15
|
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function run() {
|
|
38
|
-
console.log('\n--- LambdaTest WDIO Config Generator ---\n');
|
|
39
|
-
|
|
40
|
-
config.testName = await ask('Enter Test Name (e.g. AndroidAppTest)', 'AndroidAppTest');
|
|
41
|
-
config.filename = `${config.testName}.conf.js`;
|
|
42
|
-
|
|
43
|
-
config.username = await ask('Enter LambdaTest Username', process.env.LT_USERNAME || 'YOUR_USERNAME');
|
|
44
|
-
config.key = await ask('Enter LambdaTest Access Key', process.env.LT_ACCESS_KEY || 'YOUR_ACCESS_KEY');
|
|
45
|
-
|
|
46
|
-
const typeInput = await ask('Test Type (1: App, 2: Browser)', '1');
|
|
47
|
-
config.type = typeInput === '1' || typeInput.toLowerCase() === 'app' ? 'app' : 'browser';
|
|
48
|
-
|
|
49
|
-
if (config.type === 'app') {
|
|
50
|
-
const subTypeInput = await ask('Device Type (1: Real Device, 2: Virtual Device)', '1');
|
|
51
|
-
config.subType = subTypeInput === '1' ? 'real' : 'virtual';
|
|
52
|
-
} else {
|
|
53
|
-
console.log('Browser Options: 1: Desktop, 2: Mobile Browser (Virtual), 3: Mobile Browser (Real)');
|
|
54
|
-
const subTypeInput = await ask('Select Option', '1');
|
|
55
|
-
if (subTypeInput === '2') config.subType = 'mobile-virtual';
|
|
56
|
-
else if (subTypeInput === '3') config.subType = 'mobile-real';
|
|
57
|
-
else config.subType = 'desktop';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const parallelInput = await ask('Number of Parallel Threads (0 or empty for no parallel)', '0');
|
|
61
|
-
config.parallel = parseInt(parallelInput) || 0;
|
|
62
|
-
|
|
63
|
-
config.specPath = await ask('Path to Spec File (e.g. ./specs/test.js)', './specs/android-test.js');
|
|
64
|
-
|
|
65
|
-
// Generate Config Content
|
|
66
|
-
let capabilities = [];
|
|
67
|
-
const commonCaps = {
|
|
68
|
-
build: `LT_WDIO_${config.testName}_${new Date().toISOString().split('T')[0]}`,
|
|
69
|
-
name: config.testName,
|
|
70
|
-
visual: true,
|
|
71
|
-
console: true
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
if (config.type === 'app') {
|
|
75
|
-
const cap = {
|
|
76
|
-
"lt:options": {
|
|
77
|
-
w3c: true,
|
|
78
|
-
platformName: "Android",
|
|
79
|
-
deviceName: config.subType === 'real' ? ".*" : "Pixel 4",
|
|
80
|
-
platformVersion: config.subType === 'real' ? undefined : "11",
|
|
81
|
-
isRealMobile: config.subType === 'real',
|
|
82
|
-
app: process.env.LT_APP_ID || "lt://proverbial-android", // Default app
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
capabilities.push(cap);
|
|
86
|
-
} else {
|
|
87
|
-
if (config.subType === 'desktop') {
|
|
88
|
-
capabilities.push({
|
|
89
|
-
browserName: "chrome",
|
|
90
|
-
browserVersion: "latest",
|
|
91
|
-
"lt:options": {
|
|
92
|
-
platformName: "Windows 10"
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
} else {
|
|
96
|
-
// Mobile Browser
|
|
97
|
-
capabilities.push({
|
|
98
|
-
"lt:options": {
|
|
99
|
-
w3c: true,
|
|
100
|
-
platformName: "Android",
|
|
101
|
-
deviceName: config.subType === 'mobile-real' ? ".*" : "Pixel 4",
|
|
102
|
-
platformVersion: config.subType === 'mobile-real' ? undefined : "11",
|
|
103
|
-
isRealMobile: config.subType === 'mobile-real',
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Prepare template
|
|
110
|
-
const template = `const path = require('path');
|
|
111
|
-
|
|
112
|
-
exports.config = {
|
|
113
|
-
// Authentication handled by SDK
|
|
114
|
-
// user: "${config.username}",
|
|
115
|
-
// key: "${config.key}",
|
|
116
|
-
|
|
117
|
-
updateJob: false,
|
|
118
|
-
specs: ["${config.specPath}"],
|
|
119
|
-
exclude: [],
|
|
120
|
-
|
|
121
|
-
maxInstances: ${config.parallel > 0 ? config.parallel : 1},
|
|
122
|
-
|
|
123
|
-
commonCapabilities: ${JSON.stringify(commonCaps, null, 4)},
|
|
124
|
-
|
|
125
|
-
capabilities: ${JSON.stringify(capabilities, null, 4)},
|
|
126
|
-
|
|
127
|
-
logLevel: 'error',
|
|
128
|
-
coloredLogs: true,
|
|
129
|
-
screenshotPath: "./errorShots/",
|
|
130
|
-
baseUrl: "https://mobile-hub.lambdatest.com",
|
|
131
|
-
waitforTimeout: 10000,
|
|
132
|
-
connectionRetryTimeout: 90000,
|
|
133
|
-
connectionRetryCount: 3,
|
|
134
|
-
path: "/wd/hub",
|
|
135
|
-
hostname: "mobile-hub.lambdatest.com",
|
|
136
|
-
port: 80,
|
|
137
|
-
|
|
138
|
-
services: [
|
|
139
|
-
[path.join(__dirname, '../wdio-lambdatest-service'), {
|
|
140
|
-
user: "${config.username}",
|
|
141
|
-
key: "${config.key}"
|
|
142
|
-
}]
|
|
143
|
-
],
|
|
144
|
-
|
|
145
|
-
framework: "mocha",
|
|
146
|
-
mochaOpts: {
|
|
147
|
-
ui: "bdd",
|
|
148
|
-
timeout: 20000,
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
exports.config.capabilities.forEach(function (caps) {
|
|
153
|
-
for (var i in exports.config.commonCapabilities)
|
|
154
|
-
caps[i] = caps[i] || exports.config.commonCapabilities[i];
|
|
155
|
-
});
|
|
156
|
-
`;
|
|
157
|
-
|
|
158
|
-
const outputPath = path.join(outputDir, config.filename);
|
|
159
|
-
fs.writeFileSync(outputPath, template);
|
|
160
|
-
|
|
161
|
-
console.log(`\nSuccessfully created configuration file at:\n${outputPath}`);
|
|
162
|
-
console.log(`\nRun it with:\n./node_modules/.bin/wdio ${path.relative(process.cwd(), outputPath)}`);
|
|
163
|
-
|
|
164
|
-
rl.close();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
run();
|