start-process "chrome.exe" '--profile-directory="Default"'
当我运行这个命令几次时,它会在单独的窗口中打开我的默认配置文件的Chrome浏览器。当我的默认配置文件的Chrome浏览器已经打开时,我该怎么办才能打开新标签页?
start-process "chrome.exe" '--profile-directory="Default"'
start-process "chrome.exe" "http://localhost:9876/debug.html",'--profile-directory="Default"'
然而,如果您只想刷新一个页面(就像您在评论中所说),您也可以使用 Powershell 中的小型 Windows 脚本来执行此操作:
# * Get a WindowsScript Shell
$WindowsScriptShell = New-Object -ComObject wscript.shell
# * Check if Chrome is running and activate it
if ($WindowsScriptShell.AppActivate('Chrome')) {
# * Take a nap to give Windows time to focus Chrome
Sleep 2
# * Refresh the page by sending the F5 Key
$WindowsScriptShell.SendKeys('{F5}')
}
# * If Chrome isn't there, tell us
Else {
Write-Output "Chrome is not started!"
}
这个是否接近您的需求?
使用VBScript,您还可以使用CTRL+<数字>
组合键在刷新前切换到特定的标签页。因此,在按下F5键之前,您需要添加$vbscriptShell.SendKeys('^2')
。我还尝试使用CTRL+T
(在VBScript中为'^T')打开一个新标签页,但由于某种原因,它会打开一个新窗口然后再打开一个新标签页...
$WindowsScriptShell.SendKeys('^1'); Sleep 2; $WindowsScriptShell.SendKeys('{F5}')
,看起来还不错,但是有点棘手,而且我必须始终将我的测试选项卡作为第一个选项卡,IE通过powershell更易于控制,但是... :) 最后我使用PhantomJS
在后台运行测试,在cmd中打印报告,并添加了npm脚本以在需要时运行chrome html报告,无论如何感谢您的帮助。 - Paweł
Start-Process
是否能够帮助你实现目标。你可能需要对现有的 Chrome 进程进行一些操作。 - litStart-Process -FilePath "http://google.com"
。 - Sam Martinhttp://localhost:9876/debug.html
在 Karma 中调试测试,但是一直弹出 Chrome 窗口让我很烦恼。在运行测试时只需刷新一个打开的选项卡会很不错。我想尝试以某种方式通过.sh
文件运行 Chrom 来达到这一点。 - Paweł