我用TypeScript编写Codeceptjs框架的自动测试,在项目中添加了额外的模块之后,以及在使用以下命令更新存储库之后:
npx codeceptjs def
智能感知开始为我工作,我开始看到我可以使用的方法。例如,我看到这样的模块的方法:JSON响应、数据库助手、ChaiWrapper. image
我还安装了Playwright和REST。但是对于这些模块,Intelisense不起作用。
codecept.conf.ts
import { setHeadlessWhen, setCommonPlugins } from '@codeceptjs/configure';
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);
const env = require('dotenv').config({
path: '.env.test'
})
if (env.error && env.error.code === 'ENOENT') {
throw new Error('Please, recreate env.test file')
}
const base_url = process.env.URL
const currentBrowser = process.env.profile ?? 'chromium'; // 'firefox', 'webkit'
// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();
export const config: CodeceptJS.MainConfig = {
tests: './tests/\*\_test.ts',
output: './output',
helpers: {
ChaiWrapper: {
require: "codeceptjs-chai"
},
Playwright: {
url: base_url,
show: true,
browser: currentBrowser
},
REST: {
endpoint: base_url,
},
JSONResponse: {},
DbHelper: {
"require": "codeceptjs-dbhelper"
}
},
include: {
"I": "./common/custom_steps",
},
plugins: {
tryTo: {
enabled: true
}
},
name: 'test',
fullPromiseBased: false
}
package.json
{
"name": "codeceptjs-tests",
"version": "0.1.0",
"private": true,
"scripts": {
"codeceptjs": "codeceptjs run --steps",
"codeceptjs:headless": "HEADLESS=true codeceptjs run --steps",
"codeceptjs:ui": "codecept-ui --app",
"codeceptjs:demo": "codeceptjs run --steps -c node_modules/@codeceptjs/examples",
"codeceptjs:demo:headless": "HEADLESS=true codeceptjs run --steps -c node_modules/@codeceptjs/examples",
"codeceptjs:demo:ui": "codecept-ui --app -c node_modules/@codeceptjs/examples"
},
"devDependencies": {
"@codeceptjs/configure": "^0.10.0",
"@codeceptjs/examples": "^1.2.1",
"@codeceptjs/ui": "^0.4.7",
"@types/node": "^18.11.12",
"codeceptjs": "^3.3.7",
"playwright": "^1.28.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
},
"dependencies": {
"codeceptjs-chai": "^2.3.3",
"codeceptjs-dbhelper": "^1.2.2",
"database-js-mssql": "^0.3.0",
"database-js-mysql": "^1.1.3",
"dateformat": "^5.0.3",
"dotenv": "^16.0.3",
"faker": "^6.6.6",
"object-hash": "^3.0.0",
"randexp": "^0.5.3",
"random-date-generator": "^1.0.2",
"random-mobile-numbers": "^1.0.1",
"underscore": "^1.13.6",
"unique-names-generator": "^4.7.1"
}
}
重新安装模块没有帮助。
1条答案
按热度按时间w41d8nur1#
我找到了解决方案。在steps.d.ts中,您需要添加将方法转移到WithTranslation
代替
interface I extends ReturnType<steps_file>, WithTranslation<ChaiWrapper>, WithTranslation<JSONResponse>, WithTranslation<DbHelper> {}
我们将添加
interface I extends ReturnType<steps_file>, WithTranslation<Methods> {}