我也有这个问题。我通过在我的 testSetup() 方法中杀死任何正在运行的 chromedriver.exe 实例来修复它。我使用了一个 VBScript 和一些 Groovy 代码来运行这些脚本。对不起,这个答案有点长。
我的设置中有这个):
if (wshsc.isRunningByCommandLineContents("chromedriver.exe"))
wshsc.killProcessByCommandLineContents("chromedriver.exe")
isRunningByCommandLine 内容:
If WScript.Arguments.Count = 1 Then
strCmdLine = WScript.Arguments.Item(0)
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("WScript.Shell")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process")
If colProcessList.Count > 0 Then
For Each objItem in colProcessList
If (InStr(objItem.CommandLine, strCmdLine)) Then
If (InStr(objItem.CommandLine, "cscript")) Then
Else
WScript.StdOut.Write "A process is running with " + strCmdLine + " in its command line = " + objItem.Name
End If
End If
Next
End If
End If
killProcessByCommandLine 内容:
If WScript.Arguments.Count = 1 Then
strProcess = WScript.Arguments.Item(0)
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("WScript.Shell")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process")
If colProcessList.Count > 0 Then
For Each objItem in colProcessList
If InStr(objItem.CommandLine, strProcess) Then
If (InStr(objItem.CommandLine, "cscript")) Then
Else
WScript.StdOut.Write objItem.Name + " "
objItem.Terminate()
End If
End If
Next
Else
WScript.StdOut.Write "No instances found running"
End If
Else
WScript.StdOut.Write "Bad Arguments"
End If
而“运行脚本部分”:
public void killProcessByCommandLineContents(String contents) {
List<String> arg = new ArrayList<String>()
arg.add(contents)
String [] args = arg.toArray()
runScript("killByCmdLineContents.vbs", args, true)
}
public boolean isRunningByCommandLineContents(String contents) {
List<String> arg = new ArrayList<String>()
arg.add(contents)
String [] args = arg.toArray()
String returnData = runScript("IsRunningByCmdLineContents.vbs", args, true)
if (returnData.contains(contents)) {
return true
} else {
return false
}
}
public String runScript(String name, String [] args, boolean returnOutput) {
String s = null;
List<String> cmdLine = new ArrayList<String>()
cmdLine.add("C://Windows//System32//cscript.exe")
cmdLine.add(dir + "dir//src//com//misc//wshScripts//" + name)
int index = 0
args.each() {
cmdLine.add(args[index])
index++
}
try {
String [] cmdLineArray = cmdLine.toArray()
Process p = Runtime.getRuntime().exec(cmdLineArray, null);
if (returnOutput) {
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String dataToReturn
Log.logger.info("Standard output: ");
while ((s = stdInput.readLine()) != null) {
Log.logger.info(s)
dataToReturn = s // should get last line
}
Log.logger.info("Standard error: ");
while ((s = stdError.readLine()) != null) {Log.logger.info(s);}
return dataToReturn
} else {
return ""
}
}
catch (IOException e) {
Log.logger.info(e.message, e);
}
}