756582322f8a53fef19e8c24ba902e353ba3623f chmalee Thu Aug 27 14:38:34 2026 -0700 uiTest: shared browser UI test harness, plus an hgTracks example, refs #38188 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> diff --git src/hg/utils/uiTest/lib/pages.js src/hg/utils/uiTest/lib/pages.js new file mode 100644 index 00000000000..8692e1c56c9 --- /dev/null +++ src/hg/utils/uiTest/lib/pages.js @@ -0,0 +1,29 @@ +// pages.js -- find a CGI's page object. +// +// A test says page('hgTracks') and gets the selectors for hgTracks, wherever the +// kent tree happens to be checked out. Nobody writes ../../.. by hand, and a +// test in one CGI can borrow another CGI's page object when it has to cross +// between them. + +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const { configError } = require('./env'); + +// .../src/hg/utils/uiTest/lib -> .../src +const kentSrc = path.resolve(__dirname, '..', '..', '..', '..'); + +function pageFile(cgi) { + return path.join(kentSrc, 'hg', cgi, 'tests', 'pages', `${cgi}.js`); +} + +function page(cgi) { + const f = pageFile(cgi); + if (!fs.existsSync(f)) { + throw configError(`no page object for ${cgi}: expected ${f}`); + } + return require(f); +} + +module.exports = { page, pageFile, kentSrc };