简体   繁体   English

是否可以使用groovy脚本从文本文件读取python函数输出?

[英]Is it possible to read python function output from text file with groovy script?

I have situation where I need to update my token every 12 hours. 我遇到需要每12小时更新一次令牌的情况。 I have python script below which done this for me and saves it to new file. 我下面有python脚本,它为我完成了此操作并将其保存到新文件中。 I was wondering is it possible to run this python script with groovy and after that read the value from the file and save it to variable for future use? 我想知道是否可以用groovy运行此python脚本,然后从文件中读取值并将其保存到变量中以备将来使用?

pw = WarehouseApi.from_credentials('username','password',29)
fh = open('C:\\Users\\SebastianAiraksinen\\Testi\\token.txt', 'w')
fh.write(str(pw._session.cookies))
fh.close()

In your comments, you state that this is running in Jenkins. 在您的评论中,您声明它正在Jenkins中运行。 So, automated. 因此,自动化。 Both Python script and SoapUI execution is happening from commandline...? Python脚本和SoapUI的执行都从命令行执行...? (Like from inside a .BAT file or something like that) (就像来自.BAT文件中的文件一样)

I think you may be able to make a .BAT file yourself, that runs both the Python Script AND your SoapUI project right after each other. 我认为您也许可以自己制作一个.BAT文件,该文件可以同时运行Python脚本和SoapUI项目。

The Python script should return the token. Python脚本应返回令牌。

Your .BAT file should catch that in a variable. 您的.BAT文件应将其捕获到变量中。

Pass that variable to the execution of your SoapUI project. 将该变量传递给您的SoapUI项目的执行。

Assuming the execution of your SoapUI project looks something like this: 假设您的SoapUI项目的执行如下所示:

testrunner.bat your-soapui-project.xml -Ptoken=%tokenVariable% 

The -Ptoken=%tokenVariable% part will set a Project variable inside your SoapUI project named "token", that you may use with ${#Project#token} when running. -Ptoken =%tokenVariable%部分将在SoapUI项目中设置一个名为“ token”的Project变量,您可以在运行时将其与$ {#Project#token}一起使用。 Like when setting your header values etc. 就像设置标题值时一样。

I hope that made sense. 我希望这是有道理的。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM