tech_memo / SoapUI


tech_memo

コマンドライン実行

Groovy API

  • https://www.soapui.org/apidocs/overview-summary.html
  • 変数を展開して取得
    def currentUser = context.expand( '${#TestCase#currentUser}' )
  • testStep実行
    import eviware.soapui.model.testsuiite.TestStepResullt.TestStepStatus
    
    def testStep = testRunner.testCase.testSteps['Run TestCase']
    def result = testStep.run( testRunner, context )
    assert result.getStatus() == TestStepStatus.OK, "Result status is ${result.getStatus().toString()}"
  • Oracle接続
    import groovy.sql.Sql;
     
    com.eviware.soapui.support.GroovyUtils.registerJdbcDriver( "oracle.jdbc.OracleDriver" ) // ★ SoapUI上のGroovyの場合、JDBC登録が必要。
    def  con = Sql.newInstance("jdbc:oracle:thin:@<DB_IP>:<DB_PORT>:<SID>", "<DB_USER>", "<DB_PASS>", "oracle.jdbc.driver.OracleDriver");

SoapUI Script Libraryを使わずに共通クラスを利用する

  • SoapUIフリーではScript Libraryは使えないっぽい。
  • 参考 : http://www.spamer.me.uk/wiki/doku.php/soapui_reusable_script_library
  • クラス定義+インスタンス生成用のテストステップを作成し、そのクラスのインスタンスをcontextの変数に詰めることでどこからでも利用可能になる。
    • TestSuite?["common"] / TestCase?["common"] / TestStep?["newSample"] で定義したとする。
      class Sample {
          def name = "Hoge"
      
          def getName() {
              return name
          }
      }
      
      context.sampleInstance = new Sample()
  • 利用側のgroovy test step
    context.testCase.testSuite.project.testSuites["common"].testCase["common"].testSteps["newSample"].run(testRunner, context)
    def sample = context.sampleInstance
    log.info sample.getName