Forum Discussion

asnaeb's avatar
asnaeb
New Contributor
3 years ago

Reseting datasource to first row

Hello,

 

I have a functional test in which I am using same datasource step in two different loops. First loop is to create a data, second loop to validate. However I am unable to loop the datasource second time - it "loops" only the last row.

 

I have tried to create a groovy script between these loops to validate whether "ds.getRestartOnRun()" and "ds.setRestartShared()" are true and yes, they both are true for that datasource step.

 

Why the datasource is not reseting by itself when those two params are set to true? Is there any way to trigger the reset from script or set the current row?

 

Thanks

  • Hi,

     

    You're only missing a second Datasource test step.

     

    Insert a new Datasource step either before Step 5 for Step 6.  Call the step itself something different, like "Datasource - validate"  I suspect before Step 6 is the place.

     

    Then update DataSourceLoop2 to point at the "Datasource - valdidate" datasource step.

     

    Why did it not work?  The Datasource step keeps track of the current row whilst the testing is running.  When the test runs again, it resets, but it doesn't reset in the context of the same test running.  That's why the second loop is on the last row.

  • richie's avatar
    richie
    Community Hero
    Hey asnaeb,

    Can you send a screenshot of your testcase please? Im struggling to visualise what youre doing, but without engaging my brain too much (ive had no sleep since Monday), im guessing your issue might be linked to trying to do too many things witha single datasource object....especially if youve got 2 datasource loop objects in your test.

    If i can see your testcase object hierarchy that will probably help me.

    Cheers,

    Rich
    • asnaeb's avatar
      asnaeb
      New Contributor

      Hello,

       

      sorry for just a brief description, will try to explain more:

       

      I have a two separate loops, one after another, no nesting. Something like ChrisAdams's second example, but with just one datasource.

       

      This my test case (screenshot_61.jpg):

      - Step1: GetList (REST request)

      - Step2: DataSource (from JSON response of Step1 (GetList) - 73rows)

      -- Step3: CreateData (REST request in loop. uses ${DataSource#data}. it gets executed 73 times.)

      -- Step4: DataSourceLoop1 (Data Source Step: DataSource, Target Step: CreateData)

      - Step5: GetAnotherList (REST request.)

      -- Step6: ValidateItemInList (Assertion. uses ${DataSource#data} and validates against GetAnotherList.response. it gets executed only 1 time (for last row of DataSource)) 

      -- Step7: DataSourceLoop2 (Data Source Step: DataSource, Target Step: ValidateItemInList)

       

      So the problem is step 6/7. I would expected the loop for that datasource go again from row 1 to row 73, but it only executes the 73th row.

       

      Transaction log: Screenshot_62.jpg .

       

      P.S. I have set testcase to continue on errors.

      • ChrisAdams's avatar
        ChrisAdams
        Champion Level 3

        Hi,

         

        You're only missing a second Datasource test step.

         

        Insert a new Datasource step either before Step 5 for Step 6.  Call the step itself something different, like "Datasource - validate"  I suspect before Step 6 is the place.

         

        Then update DataSourceLoop2 to point at the "Datasource - valdidate" datasource step.

         

        Why did it not work?  The Datasource step keeps track of the current row whilst the testing is running.  When the test runs again, it resets, but it doesn't reset in the context of the same test running.  That's why the second loop is on the last row.

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    Hi,

     

    If your loops are nested, e.g.

    DatasourceStepOne
    
    ---- DatasourceStepOne
    
    ---- DatasourceLoopTwo
    
    DatasourceLoopOne

    Then I cannot see how it would work.

     

    In your description, you say Create, then Validate and I read this as two loops.  e.g.

    // Let's create out data.
    CreateStuff-Datasource
    
       SomeCallToCreateDate - REST Request
    
    CreateStuff-DatasourceLoop
    
    //Data created, wait a bit.
    delay(1000)
    
    // Let's validate
    ValidateStuff-Datasource
    
        SomeValidateStep - REST Request
    
    ValidateStuff-DatasourceLoop
    

     

    This would be perfectly valid.  There's no reason why the same file cannot be used in two different datasource steps.  But, as richie suggested, some screenshots would help.