Groovyコード(SOAPUIを使用しています)を取得しようとしていますが、問題が発生しています。Groovyと変数型の問題
このコードでは、プロパティファイルを読み込み、SOAPUIでいくつかのプロパティを設定します。これをSOAPUIテストケースのGroovyスクリプトテストステップに入れ、実行するたびに別のファイル名から読み込みたいので、テストケースcur_request_numberとmax_request_numberの2つの追加プロパティがあります。
このコードでは、毎回cur_request_numberをインクリメントしてmax_request_numberに達したかどうかを確認し、そうであればcur_request_numberを1に戻します。これは動作しますが、max_request_numberが9以下の場合に限ります。それが10以上であれば、9または10に達したとき、cur_request_number ++はそれを文字列値、例えばセミコロンにインクリメントしているように見える。言い換えれば
、(各サイクルで)読むことを仮定しています:
testprop1.txt
testprop2.txt
.
.
私は以下掲示していたコードが実際にtextpropX.txtファイルを読んで、まだ、ちょうどそのファイル名を印刷していません私はまだデバッグしているので、それを読んでいます。
私は本当にGroovyを新しくしています。だから私はこだわっています。私はtoInteger()を追加しようとしましたが、別の問題が発生します。
def cur_request_number = testRunner.testCase.getPropertyValue("cur_request_number");
def max_request_number = testRunner.testCase.getPropertyValue("max_request_number");
log.info "INITIAL cur_request_number=[" + cur_request_number + "]"
log.info "INITIAL max_request_number=[" + max_request_number + "]"
cur_request_number++;
log.info "BUMPED cur_request_number=[" + cur_request_number + "]"
if (cur_request_number == max_request_number) {
log.info "In the IF about to reset cur_request_number to 1";
cur_request_number = "1";
}
// set the cur_request_number property (either the incremented one, or "1")
testRunner.testCase.setPropertyValue("cur_request_number", cur_request_number);
cur_request_filename = "E:/SOAPUI-PROPS/testprops" + cur_request_number.toString() +".txt";
log.info "READING FROM Request file [" + cur_request_filename + "]"
props = new java.util.Properties()
file = new File("E:/SOAPUI-PROPS/testprops.txt")
if(!file.exists()) {
log.info "No file found at E:/SOAPUI-PROPS/testprops.txt"
}
else {
log.info "max_request_number=[" + max_request_number + "]"
log.info "In the ELSE, cur_request_number=[" + cur_request_number + "]"
//testRunner.testCase.setPropertyValue("cur_request_number", cur_request_number);
log.info "Found E:/SOAPUI-PROPS/testprops.txt"
fis = new FileInputStream (file)
props.load (fis)
requestid = props.getProperty ("requestid")
log.info "requestid = [" + requestid + "]"
dnstring = props.getProperty ("dnstring")
log.info "dnstring= [" + dnstring + "]"
testRunner.testCase.setPropertyValue("requestid", requestid);
context.requestid = requestid;
log.info "Finished setting 'requestid' property"
testRunner.testCase.setPropertyValue("dnstring", dnstring);
context.dnstring = dnstring;
log.info "Finished setting 'dnstring' property"
}
私が間違っていることを誰かが教えてもらえれば、本当に感謝しています。
おかげで、 ジム
ありがとうございました。私はそれを試みます。その間に、私は最終的に別の、おそらく本当に醜い方法ではありましたが、それを働かせました。私がしなければならなかったことは、基本的に対応する整数変数を作成することでした。 def cur_request_number_INTを設定し、cur_request_number_INT = cur_request_number.toInteger()を使用して整数値に設定し、max_request_numberおよびmax_request_number_INTも同じ値に設定します。 – user555303
私はあなたの提案を試みました、そして、(1)それは動作し、(2)私のコードを間違いなくクリーンアップします。私はまだいくつかのtoString()変換を使用しなければなりませんでしたが、今はもっと良くなっています!ジム – user555303