在Node 8.x上,我无法调试Typescript(可将其编译为JS for Protractor)。 7.x使用browser.pause(),但由于已弃用,因此不再是一种选择。
我正在使用最新版本的VSCode。
package.json
{
"name": "bond",
"version": "1.0.0",
"description": "bond e2e automation tests",
"author": "bond",
"main": "./config.ts",
"license": "bond",
"scripts": {
"webdriver-update": "npx webdriver-manager update",
"prestart": "npm run build",
"build": "tsc",
"tsc": "tsc",
"test": "npm run tsc && protractor tmp/config.js"
},
"dependencies": {
"@types/jasmine": "^2.8.9",
"@types/jasminewd2": "^2.0.4",
"@types/node": "^10.12.0",
"adm-zip": "0.4.7",
"chance": "^1.0.16",
"chromedriver": "^2.41",
"colors": "1.1.2",
"geckodriver": "1.8.1",
"jasmine": "^2.99.0",
"jasmine-reporters": "2.2.1",
"jasmine-spec-reporter": "4.2.1",
"mocha": "^5.2.0",
"protractor": "^5.4.1",
"protractor-jasmine2-screenshot-reporter": "0.4.0",
"selenium-server": "^3.13.0",
"selenium-webdriver": "^4.0.0-alpha.1",
"ts-node": "^7.0.1",
"webdriver-manager": "^12.0.6",
"xml2js": "~0.4.19"
},
"devDependencies": {
"@types/jasmine": "^2.8.9",
"@types/jasminewd2": "^2.0.4",
"protractor-beautiful-reporter": "^1.2.6",
"ts-node": "^7.0.1",
"typescript": "^2.9.2",
"yarn": "^1.10.1"
}
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "XPIA",
"stopOnEntry": false, //debug exp
"program": "${workspaceFolder}\\config.ts",
// "program": "${workspaceRoot}\\tmp\\",
"preLaunchTask": "npm: build",
"sourceMaps": true,
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"protocol": "auto",
"args": ["${workspaceRoot}/config.js"],
"outFiles": [
"${workspaceFolder}/tmp/**/*.js"
]
}]
}
这只是在浪费我的大部分时间,因为我经常切换到Node 7.x并使用效率低下的浏览器。pause()
编辑1:
根据下面的建议,从视频中,我正在使用Node 8.x,Selenium Promise Manager是false并针对es2017,但出现了此错误。
我的编译代码位于tmp文件夹中,而不是node_modules / protractor / bin
config.ts
import { Config } from 'protractor';
import { Environment } from './environment';
import { StandardSetup } from './Standard-setup';
var HtmlReporter = require('protractor-beautiful-reporter');
export let config: Config = {
framework: 'jasmine2',
SELENIUM_PROMISE_MANAGER: false,
directConnect: true,
capabilities: {
'browserName': (process.env.TEST_BROWSER_NAME || 'chrome'),
'version': (process.env.TEST_BROWSER_VERSION || 'ANY'),
'shardTestFiles': true,
'unexpectedAlertBehaviour': 'accept',
'loggingPrefs': {
'performance': 'ALL',
},
'chromeOptions': {
'args': ['--disable-notifications', '--disable-infobars', '--start-maximized'],
prefs: {
download: {
'prompt_for_download': false,
'directory_upgrade': true,
}
}
},
},
specs: ['specs/proj/*test-spec.js'],
seleniumAddress: 'http://10.10.113.153:4444/wd/hub',
jasmineNodeOpts: {
isVerbose: true,
showColors: true,
defaultTimeoutInterval: 999999, //longer timeout for debugging
print: function () { }
},
/**
* @returns logs to console on page load
*/
async onPrepare(): Promise<void> {
let setup = new StandardSetup(),
env = new Environment();
setup.setSpecReporter();
await setup.setjasmineReporters();
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'reports/screenshots'
}).getJasmine2Reporter());
return await env.setGlobals();
}
};
编辑2:
我正在使用的命令是:
node --inspect-brk ./tmp/config.js
现在我可以在开发工具中看到配置文件。但是,当我按F8键时,脚本不会在“调试器”处暂停;在规格文件中。我所看到的是这样的:
要在VSCode(F10)上进行调试,我更改了launch.json:
"program": "${workspaceRoot}\\tmp\\config.js",
同样,我最终进入了配置,并且没有接近规范文件。
我要去哪里错了?