如何在 SOAP UI 的 groovy 脚本中显示 folder/directory 选择器弹出窗口?
How to display folder/directory selector pop up in groovy script in SOAP UI?
我正在编写 groovy 脚本进行 SOAP UI 测试。在一处,我必须使用 groovy 弹出目录选择器。我知道如何弹出普通消息 windows。但我不知道显示目录选择器的弹出窗口。
有人可以建议我实现此目标的方法吗?
由于groovy可以执行java代码,您可以简单地使用java swing组件JFileChooser
来执行。您可以在 groovy 脚本 testStep 中使用以下代码到 select 目录并将其返回到您的代码中:
import javax.swing.JFileChooser
// create the file chooser
JFileChooser chooser = new JFileChooser()
// set whatever directory you want where to start looking for your directory
chooser.setCurrentDirectory(new java.io.File("."))
chooser.setDialogTitle("select directory")
// filter to show only directories
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
// get the user action
int returnVal = chooser.showOpenDialog()
// if the user selects a directory
if(returnVal == JFileChooser.APPROVE_OPTION) {
// get the directory and start your logic
File selectedDirectory = chooser.getSelectedFile()
// sample print directory path
log.info('Selected directory: ' + selectedDirectory.getAbsolutePath())
// sample print all files inside selected directory
selectedDirectory.listFiles().each{ file ->
log.info(file.getAbsolutePath())
}
}
我不知道在 SOAPUI API 中是否有更具体的内容适合您的情况,但是这段代码可以解决问题。
希望对您有所帮助,
我正在编写 groovy 脚本进行 SOAP UI 测试。在一处,我必须使用 groovy 弹出目录选择器。我知道如何弹出普通消息 windows。但我不知道显示目录选择器的弹出窗口。
有人可以建议我实现此目标的方法吗?
由于groovy可以执行java代码,您可以简单地使用java swing组件JFileChooser
来执行。您可以在 groovy 脚本 testStep 中使用以下代码到 select 目录并将其返回到您的代码中:
import javax.swing.JFileChooser
// create the file chooser
JFileChooser chooser = new JFileChooser()
// set whatever directory you want where to start looking for your directory
chooser.setCurrentDirectory(new java.io.File("."))
chooser.setDialogTitle("select directory")
// filter to show only directories
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
// get the user action
int returnVal = chooser.showOpenDialog()
// if the user selects a directory
if(returnVal == JFileChooser.APPROVE_OPTION) {
// get the directory and start your logic
File selectedDirectory = chooser.getSelectedFile()
// sample print directory path
log.info('Selected directory: ' + selectedDirectory.getAbsolutePath())
// sample print all files inside selected directory
selectedDirectory.listFiles().each{ file ->
log.info(file.getAbsolutePath())
}
}
我不知道在 SOAPUI API 中是否有更具体的内容适合您的情况,但是这段代码可以解决问题。
希望对您有所帮助,