Skip to content

Commit 42472c4

Browse files
author
DavertMik
committed
Merge branch '4.x' of github.com:codeceptjs/CodeceptJS into 4.x
2 parents af8de03 + 4f0fa49 commit 42472c4

32 files changed

Lines changed: 3052 additions & 810 deletions

bin/codecept.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ if (process.versions.node && process.versions.node.split('.') && process.version
7272
program.usage('<command> [options]')
7373
program.version(Codecept.version())
7474

75-
program.command('init [path]').description('Creates dummy config in current dir or [path]').action(commandHandler('../lib/command/init.js'))
75+
program
76+
.command('init [path]')
77+
.description('Creates dummy config in current dir or [path]')
78+
.option('-y, --yes', 'skip prompts and use defaults (Playwright + chromium, BASE_URL env for url)')
79+
.action(commandHandler('../lib/command/init.js'))
7680

7781
program
7882
.command('check')

bin/codeceptq.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env node
2+
import { Command } from 'commander'
3+
import query from '../lib/command/query.js'
4+
5+
const program = new Command()
6+
7+
program
8+
.name('codeceptq')
9+
.description('Query HTML with CodeceptJS locators (CSS, XPath, fuzzy text, semantic).\n\nReads HTML from stdin or --file and prints matching elements with line numbers.')
10+
.argument('<locator>', 'locator string (CSS, XPath, or text for semantic match)')
11+
.argument('[context]', 'scope locator — restrict matches to descendants of context')
12+
.option('--field', 'treat locator as form field (input/textarea/select)')
13+
.option('--click', 'treat locator as clickable element (link, button, role=button, ...)')
14+
.option('--clickable', 'alias for --click')
15+
.option('--checkable', 'treat locator as checkbox/radio')
16+
.option('--select', 'treat locator as <option> visible text')
17+
.option('--xpath', 'force XPath interpretation')
18+
.option('--css', 'force CSS interpretation')
19+
.option('--file <path>', 'read HTML from file instead of stdin')
20+
.option('--limit <n>', 'cap matches printed', '20')
21+
.option('--snippet <chars>', 'truncate outerHTML per match to N characters', '500')
22+
.option('--full', 'print full outerHTML (no truncation)')
23+
.option('--json', 'output JSON')
24+
.addHelpText(
25+
'after',
26+
`
27+
Examples:
28+
cat trace/0001_page.html | codeceptq './/input'
29+
cat trace/0001_page.html | codeceptq 'Username' --field
30+
cat trace/0001_page.html | codeceptq 'Username' '.form' --field
31+
codeceptq './/button' --file trace/0001_page.html
32+
codeceptq 'Login' --click --file page.html
33+
34+
Exit codes:
35+
0 matches found
36+
1 no matches
37+
2 invalid input or XPath
38+
`,
39+
)
40+
.action(async (locator, context, options) => {
41+
try {
42+
await query(locator, context, options)
43+
} catch (err) {
44+
console.error(`codeceptq: ${err.message}`)
45+
process.exitCode = 2
46+
}
47+
})
48+
49+
program.parseAsync(process.argv)

0 commit comments

Comments
 (0)