gpt4 book ai didi

typescript - 在没有 "webdriver-manager start"的情况下运行 Protractor 测试

转载 作者:搜寻专家 更新时间:2023-10-30 21:49:06 25 4
gpt4 key购买 nike

如果不在命令行“webdriver-manager start”中手动编写,我可以运行 Protractor 测试吗?如何在代码中运行“webdriver-manager start”?我用 TypeScript 编写。

最佳答案

将评论扩展为答案

带有“&&”的 NPM 脚本

一个想法是使用 NPM 脚本 block 来基本上只创建一个您运行的命令,该命令将启动您的服务器,然后启动您的测试。您只需运行此命令,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"
}

(bootup > sleep/delay > pretest > test) package.json

{
"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])

关于typescript - 在没有 "webdriver-manager start"的情况下运行 Protractor 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49167554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com