Typescript 运行量角器测试,不使用“量角器”;webdriver管理器启动“;

Typescript 运行量角器测试,不使用“量角器”;webdriver管理器启动“;,typescript,webdriver,protractor,automated-tests,Typescript,Webdriver,Protractor,Automated Tests,我可以运行量角器测试而不在命令行“webdriver manager start”中手动写入吗?如何在代码中运行“webdriver manager启动”? 我是用打字脚本写的。您可以定义“吞咽任务”。使用npm安装gulp并创建一个gulpfile.js 有关更多信息,请参阅my github repo: 将评论扩展为答案 带有“&&”的NPM脚本 一个想法是使用NPM脚本块,基本上只生成一个运行的命令,该命令将启动服务器,然后启动测试。您只需运行这个命令,webdriver就会启动,然后您的

我可以运行量角器测试而不在命令行“webdriver manager start”中手动写入吗?如何在代码中运行“webdriver manager启动”?
我是用打字脚本写的。

您可以定义“吞咽任务”。使用npm安装gulp并创建一个gulpfile.js

有关更多信息,请参阅my github repo:

将评论扩展为答案

带有“&&”的NPM脚本

一个想法是使用NPM脚本块,基本上只生成一个运行的命令,该命令将启动服务器,然后启动测试。您只需运行这个命令,webdriver就会启动,然后您的测试就会执行——如果需要,您可以在控制台窗口中完成测试后,按CTRL+C组合键启动服务器

时机

Webdriver Manager可能需要一些时间来启动服务器。如果第一个脚本对您不起作用,请尝试第二个脚本,并注意到包含了“sleep()”以创建webdriver的启动延迟


(启动>预测试>测试)package.json

{
  "name": "protractorautomation",
  "version": "1.0.0",
  "description": "Protractor Typescript automation framework",
  "main": "config.js",
  "dependencies": {
    "protractor": "^4.0.11"
  },
  "devDependencies": {},
  "scripts": {
    "pretest": "npm run tsc",
    "test": "protractor ConvertedJSFiles/config.js",
    "tsc": "tsc",
    "webdriver:start": "webdriver-manager start",
    "webdriver:update": "webdriver-manager update",
    "dev": "npm run webdriver:start && npm run pretest && npm run test"
  },
  "keywords": [
    "Protractor",
    "Typescript"
  ],
  "license": "ISC"
}
{
  "name": "protractorautomation",
  "version": "1.0.0",
  "description": "Protractor Typescript automation framework",
  "main": "config.js",
  "dependencies": {
    "protractor": "^4.0.11"
  },
  "devDependencies": {
    "sleep": "*"
  },
  "scripts": {
    "pretest": "npm run tsc",
    "test": "protractor ConvertedJSFiles/config.js",
    "tsc": "tsc",
    "sleep": "node sleep.js",
    "webdriver:start": "webdriver-manager start",
    "webdriver:update": "webdriver-manager update",
    "dev": "npm run webdriver:start && npm run sleep && npm run pretest && npm run test"
  },
  "keywords": [
    "Protractor",
    "Typescript"
  ],
  "license": "ISC"
}
(启动>睡眠/延迟>预测试>测试)package.json

{
  "name": "protractorautomation",
  "version": "1.0.0",
  "description": "Protractor Typescript automation framework",
  "main": "config.js",
  "dependencies": {
    "protractor": "^4.0.11"
  },
  "devDependencies": {},
  "scripts": {
    "pretest": "npm run tsc",
    "test": "protractor ConvertedJSFiles/config.js",
    "tsc": "tsc",
    "webdriver:start": "webdriver-manager start",
    "webdriver:update": "webdriver-manager update",
    "dev": "npm run webdriver:start && npm run pretest && npm run test"
  },
  "keywords": [
    "Protractor",
    "Typescript"
  ],
  "license": "ISC"
}
{
  "name": "protractorautomation",
  "version": "1.0.0",
  "description": "Protractor Typescript automation framework",
  "main": "config.js",
  "dependencies": {
    "protractor": "^4.0.11"
  },
  "devDependencies": {
    "sleep": "*"
  },
  "scripts": {
    "pretest": "npm run tsc",
    "test": "protractor ConvertedJSFiles/config.js",
    "tsc": "tsc",
    "sleep": "node sleep.js",
    "webdriver:start": "webdriver-manager start",
    "webdriver:update": "webdriver-manager update",
    "dev": "npm run webdriver:start && npm run sleep && npm run pretest && npm run test"
  },
  "keywords": [
    "Protractor",
    "Typescript"
  ],
  "license": "ISC"
}
sleep.js

require('sleep').sleep([n seconds to sleep])

假设你'在重新使用NPM时,您始终可以向package.json脚本字段添加一个启动webdriver并运行测试的命令,比如--“test”:“webdriver manager启动和量角器prot.conf.js”。然后您可以使用“npm start test”从终端运行已定义的命令,我应该在代码中更改/写入什么?{“名称”:“量角器自动化”,“版本”:“1.0.0”,“描述”:“量角器类型脚本自动化框架”,“主”:“config.js”,“依赖项”:{“量角器”:“^4.0.11”},“devdependences”:{},“脚本”:{“预测试”:“npm运行tsc”,“测试”:“量角器转换JSFiles/config.js”,“tsc”:“tsc”},“关键字”:[“量角器”、“Typescript”]、“许可证”:“ISC”}添加了一个答案,以便更轻松地回复您@Jacob。希望有帮助!require('sleep')应该放在哪里。sleep()?