3

私が試してみました:

//${__FileToString(C:\\QC\\qa\\Testlink\\Jmeter\\Expected\\test.xml,ASCII,${xmlFile})};

見つかったエラー メッセージ: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``//<?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/At . . . '' Encountered "<" at line 2, column 1.

また、試してみた${__StringFromFile}ところ、同じエラーメッセージが表示され、次のbeanshellスクリプトでも表示されました。

import org.apache.jmeter.services.FileServer;

  //Open the file  
  FileInputStream fstream = new FileInputStream("C://QC//qa//Testlink//Jmeter//Expected//test.xml");  
  //Get the object of DataInputStream  
  DataInputStream instream = new DataInputStream(fstream);  
  BufferedReader br = new BufferedReader(new InputStreamReader(instream));
4

1 に答える 1

5

次のことを試してください。

  1. テスト計画にBeanshell Samplerを追加する
  2. 次のコードをサンプラーの「スクリプト」領域に挿入します。

    import org.apache.commons.io.FileUtils;
    
    try {
        String content = FileUtils.readFileToString(new File("C:/QC/qa/Testlink/Jmeter/Expected/test.xml"));
        vars.put("content", content);
    
    } catch (Throwable ex) {
        log.info("Failed to read \"test.xml\" file", ex);
        throw ex;
    }
    
  3. Debug SamplerおよびView Results Treeリスナーをテスト計画に追加します。

  4. テストを実行する
  5. Beanshell Sampler が緑色で、${content}変数が設定されていることを確認します。そうでない場合は、jmeter.logファイルを調べて、その行を探しますFailed to read "test.xml" file。この行の下の例外スタックトレースで何もわからない場合は、ここに投稿してください。

JMeter テストで Beanshellを使用する方法の詳細については、BeanShell の使用方法: JMeter のお気に入りの組み込みコンポーネントガイドを参照してください。

于 2016-02-16T06:29:14.720 に答える