javascript - 如何在量角器测试中执行 powershell 脚本?
问题描述
我正在尝试在量角器测试中执行 powershell 脚本
量角器规格
it("Should Execute Powershell Script", async () => {
browser.get('http://mywebsite.com')
var spawn = require('child_process').spawn;
var child = spawn('powershell.exe', ['-noexit', './test.ps1']);
});
测试.ps1
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Chrome')
$wshell.SendKeys('Ganesh Hegde')
$wshell.SendKeys("{ENTER}")
powershell脚本没有被执行你能帮我吗?
解决方案
这是我如何使它与async
.
添加SELENIUM_PROMISE_MANAGER: false
到您的配置中。
然后使用spawnSync
而不是spawn
.
const { browser } = require('protractor');
const { spawnSync } = require('child_process');
describe('spawn test', () => {
it('should execute powershell script', async () => {
await browser.get('https://google.com')
await spawnSync('powershell.exe', ['-noexit', './test.ps1']);
});
});
这运行了脚本,但看起来-noexit
不起作用。我可以看到输入到搜索输入中的文本,结果仅弹出一秒钟,然后脚本退出。
推荐阅读
- python - 有没有办法将 colorsys.rgb_to_hsv 应用于熊猫数据框?
- r - 来自密度表面的样本点概率
- mysql - 从表中选择具有最大列值的单个条目,其中多个条目具有该值
- excel - VBA Excel根据创建的上一个工作表添加带有编号的新工作表
- python - 如何在 Python 中触发 onClick 事件
- c - 在c中使用高斯模糊模糊图像
- azure-synapse - Azure SQL 数据仓库 (Synapse Analytics) 可以安装在本地吗?
- kubernetes - 使用 Minikube 和 AWS ECS 构建本地测试环境
- apache-spark - Apache Airflow 在* Spark 作业中编排 DAG?
- c - fpclassify(x) == FP_NAN 在功能上是否等同于 isnan(x)?