Forum Discussion

ebudihar's avatar
ebudihar
Occasional Contributor
7 years ago

my test step running infinite

dear all,

 

I have a test step, when I run manually, it runs well.

But when I ran it from a groovy script it is running infinite.

here is my groovy script:

//this code is working
//grasping data from excel
import org.apache.poi.ss.usermodel.*
import org.apache.poi.hssf.usermodel.*
import org.apache.poi.xssf.usermodel.*
import org.apache.poi.ss.util.*

//myTestCase contains the test case
def myTestCase = context.testCase

//open an excel file
def fs = new FileInputStream ("/Users/xxx/Documents/soapUIworkspace/xxx/logindata.xlsx")

//def a workbook
Workbook wb = WorkbookFactory.create(fs)

//def the worksheet location in the excel file
def ws = wb.getSheet("Sheet1")

//count the rows
def r = ws.getPhysicalNumberOfRows()

// get the Property TestStep object
propTestStep = myTestCase.getTestStepByName("Property - addingAccount")

project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("xxxx")
testSuite = project.getTestSuiteByName("testSuite");
testCase = testSuite.getTestCaseByName("TestCase");




//read the cell
for (def i=0; i<r; i++) {
    def row = ws.getRow(i)
    def c = row.getPhysicalNumberOfCells()

    log.info "row "+i
    //if (!(i == 0)) {
    //    runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);
    //}
    
    for(def j=0; j<c;j++) {
        def cell = row.getCell(j)
        if (j == 0) {
            log.info j
            user = cell.getStringCellValue()
            propTestStep.setPropertyValue("name", user) //the value is saved in the property
            log.info user
            //log.info cell.getStringCellValue()
        } else {
            log.info j
            pass = cell.getStringCellValue()
            propTestStep.setPropertyValue("value", pass) //the value is saved in the property
            log.info pass
            //log.info cell.getStringCellValue()
        }
    }
    runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), true);
    //Thread.sleep(3000)
}
log.info r
 
wb.close()

 

thank you.

  • JHunt's avatar
    JHunt
    Community Hero

    It looks like you're updating properties on a Test Step which belongs to this TestCase, and then running your mysteriously named Test Case in "xxxx" project. So I just thought I'd check... our script isn't also belonging to that mysteriously named Test Case, right?

     

    Perhaps you meant just to run a Test Step inside this Test Case, rather than running the whole Test Case? I have my scripts run individual test steps all the time.

     

    If that's not the problem, try to see if its really in an infinite loop or just looping a large amount of times. Get the value for r before you start looping. Sometimes Excel files can end up saved with a bunch of blank columns to the right of your data. In that case you can try deleting the extra columns, or select your data and copy it on to a new sheet, and delete the old one.

    • JHunt's avatar
      JHunt
      Community Hero

      I got your message with your project layout and actual names.

       

      Your have one project with one test case, and the steps are:

       

      1. SOAP Request Test Step

      2. Properties Test Step

      3. Groovy Script Test Step

      4. Property Transfer Test Step

       

      What is happening is that each time your script runs this test case, it is going through all of the steps, including re-running your groovy script, when runs all of the test steps again, including re-running your groovy script, and so on.

       

      You only really need the SOAP Request Test Step and the Groovy Script. Delete the others. Disable the SOAP Request Test Step, which means that it won't run as a normal sequence of Test Steps but it can still run when called by a script.

       

      import org.apache.poi.ss.usermodel.*
      import org.apache.poi.hssf.usermodel.*
      import org.apache.poi.xssf.usermodel.*
      import org.apache.poi.ss.util.*

      def soapTestStep = testRunner.testCase.getTestStepByName("addingAccount")

      def fs = new FileInputStream ("/Users/xxx/Documents/soapUIworkspace/xxx/logindata.xlsx")
      Workbook wb = WorkbookFactory.create(fs)
      def ws = wb.getSheet("Sheet1")
      def r = ws.getPhysicalNumberOfRows()

      for (def i=0; i<r; i++) {
          def row = ws.getRow(i)
          def c = row.getPhysicalNumberOfCells()
          for(def j=0; j<c;j++) {
              def cell = row.getCell(j)
              if (j == 0) {
                  user = cell.getStringCellValue()
                  testRunner.testCase.setPropertyValue("name", user) //the value is saved in the property
              } else {
                  pass = cell.getStringCellValue()
                  testRunner.testCase.setPropertyValue("value", pass) //the value is saved in the property
              }
          }
          testRunner.runTestStep(soapTestStep)
          //Thread.sleep(3000)
      }
       
      wb.close()

      The last thing to do is to make sure that your properties are read from the Test Case, which is assumed by the above script. It wasn't clear from what you sent me where you reading the properties from. The new property expansions (in your SOAP Request) would just be:

       

      ${#TestCase#user}
      ${#TestCase#pass}