Forum Discussion

shaijujanardhan's avatar
shaijujanardhan
Occasional Contributor
4 years ago

Is it possible to use contents from a file within setup/teardown

I have a testsuite where I need to do a setup and teardown for each of the testcases. Currently I have the same code copy pasted in all the tests. But from a maintenance point of view this is not scalable. Is there a way I can load contents of an external groovy script from disk and then use it within setup or teardown?

    • shaijujanardhan's avatar
      shaijujanardhan
      Occasional Contributor

      Hi nmrao ,

       

      I am trying to do auto reporting to Xray as when tests get executed. So before the test runs I add them to an execution as shown below

       

      def execution_id = testCase.testSuite.project.getPropertyValue( "execution_id" )
      def test_id = testCase.getLabel().split('_')[0]
      ProcessBuilder pb = new ProcessBuilder("batch script to invoke xray api")
      Process process = pb.start()
      BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()))
      def serr = null
      while ((serr = stdError.readLine()) != null) {
      log.info(serr)
      }

      Thanks for pointing me to the events page. But I also would like to know how to load external files within setup/teardown 

       

      • nmrao's avatar
        nmrao
        Champion Level 3
        If it is event then you will need to copy the script only once.