简体   繁体   English

从SOAPUI访问服务器(PUTTY)上的日志

[英]Access logs on server (PUTTY) from SOAPUI

I have to create one SOAPUI test case. 我必须创建一个SOAPUI测试用例。

This test case is named: "Login in the app with OTP (one time password)". 该测试用例名为:“使用OTP(一次性密码)登录应用程序”。

  1. At first I send POST request. 首先,我发送POST请求。
  2. Then server generates OTP and send it to the phone number. 然后,服务器生成OTP并将其发送到电话号码。
  3. Now, I need to connect to the server (PUTTY) and find a log, where the OTP is saved. 现在,我需要连接到服务器(PUTTY)并找到保存OTP的日志。
  4. Then I need to insert the OTP to the next POST request. 然后,我需要将OTP插入下一个POST请求。

I created simple Groovy script as SOAPUI test step, which opens connection in PUTTY. 我创建了简单的Groovy脚本作为SOAPUI测试步骤,该脚本在PUTTY中打开连接。

def command = "C:/path/to/putty.exe -ssh user@IP -pw pass"
def proc = command.execute()
proc.waitFor()

Then I need to write some commands in PUTTY and get OTP variable from log file. 然后,我需要在PUTTY中编写一些命令,并从日志文件中获取OTP变量。

But I don´t know how to execute the commands via Groovy script. 但是我不知道如何通过Groovy脚本执行命令。

Can anyone help me, please. 谁能帮我。 Thank you 谢谢

EDIT 编辑

Thanks to Eric Darchis, I had created simple sh. 感谢Eric Darchis,我创建了简单的sh。 file, which I can run from Groovy script. 文件,可以从Groovy脚本运行。

#!/bin/bash
TODAY=`date '+%Y-%m-%d'`
MSISDN="604883196"
OTP=`grep "Your password for phone number: "$MSISDN" is: " /path/to/log/file-"$TODAY".log | rev | cut -c -6 | rev`
echo "$OTP"
sleep 2​

In Putty this sh. 在腻子里。 file writes just the OTP value: "123456". 文件仅写入OTP值:“ 123456”。

But now I need to pass that value from Putty to SOAPUI (Groovy). 但是现在我需要将该值从Putty传递给SOAPUI(Groovy)。 And I don't know how the "consumeProcessOutput" works. 而且我不知道“ consumeProcessOutput”是如何工作的。 Do I have to write also some commands in shell script? 我是否还必须在Shell脚本中编写一些命令? Or I had to write just something like that in groovy: 或者我必须用Groovy编写类似的内容:

def sout = new StringBuilder()
def serr = new StringBuilder()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(30000)

And how do I get that value to SOAPUI? 以及如何使SOAPUI获得该价值? Thank you 谢谢

You should use -m local_command_file.sh in the putty command line. 您应该在腻子命令行中使用-m local_command_file.sh This .sh file would contain the list of commands to run to extract the information you want on the server. 该.sh文件将包含要运行的命令列表,以提取所需的服务器信息。

To process the output of the command, you can use: 要处理命令的输出,可以使用:

proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(30000)

sout would contain the standard output of the command, extracting the info you actually need should be pretty straightforward. sout将包含命令的标准输出,提取您实际需要的信息应该非常简单。

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

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