我们可以在Java-Cucumber项目中使用Python代码吗
我必须将巨大的划界文件转换为XLSX文件。 Python使此任务变得容易。因此,我可以在Cucumber-Java框架中为此转换编写一个Python脚本。 此Python代码只会将文件转换为XLSX,然后将其用于Cucumber-Java框架的其余文件。 如果这是正确的方法,请指定如何实现这一目标?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短答案:您可以使用过程类。我包括了一个超链接,因此您可以熟悉此API。在Java中运行过程的一般形式如下:
exec
方法内部,您需要为需要运行的可执行过程提供详细信息。产生过程
的另一种方法是使用 ProcessBuilder 类。对我来说,这是一个更清晰的方法:可以在单个字符串中表示命令,也可以在逗号分隔的参数列表中表示。例如:
或者
对您来说,这看起来可能是这样的:
一旦保存XLSX,Cucumber方案就应该能够转到该文件位置并以任何目的使用XLSX文件。当然,为了能够运行Python脚本,您需要安装它并从任何目录中调用Python命令,您需要将Python放在路径中。
The short answer: You can run (execute) any process from a Java application using the Process class. I included a hyperlink so you can get familiarized with this API. The general form for running a process in Java is as follows:
Inside the
exec
method, you need to provide the details for the executable process you need to run. Another way to spawn aProcess
is by using the ProcessBuilder class. To me, this is a much clearer approach:A command can be represented in a single String, or a comma-separated list of arguments. For example:
or
For you, this could look something like this:
Once you save your XLSX, your Cucumber scenario should be able to go to that file location and use the XLSX file for whichever purpose. OF COURSE, in order to be able to run Python scripts, you need to have it installed and to invoke the python command from any directory, you need to have Python in your path.