首页 > 解决方案 > 如何在量角器测试中执行 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脚本没有被执行你能帮我吗?

标签: javascriptnode.jstypescriptprotractor

解决方案


这是我如何使它与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不起作用。我可以看到输入到搜索输入中的文本,结果仅弹出一秒钟,然后脚本退出。


推荐阅读