Forum Discussion

wpar's avatar
New Contributor
5 years ago

Running a branch in parallel



Obligatory "first post here, so please be gentle."


I'm attempting to run two test cases in parallel but only after a specific test step has been run in my first test case. The APIs I'm testing require a dynamic authorization token in the header that changes every 60 seconds after a specific API request has been sent. Presently I have a groovy script in the first test case to run a groovy script in second test case that contains a while loop to continuously run the second test case while the first test case is running (there is a groovy script at the end of TestCase1 to set the 'running' property to 'false' to stop the loop). However, the first test case comes to a halt as it waits on the second test case's loop instead of branching to start the second test case in parallel while continuing with the first. 


Is it possible to accomplish this task within the confines of the program? 


Test case 1's script: 

def hello = testRunner.testCase.testSuite.project.getTestSuiteByName('BaseClientPortalTesting').getTestCaseByName('HeartbeatFlow').getTestStepByName('startLoop'), context);

Test case 2's script

def thread = Thread.start{

def running = context.expand('${#TestSuite#RUNNING}').asBoolean();
def runTimes = 0; while (running){ runTimes++;;

running = context.expand('${#TestSuite#RUNNING}').asBoolean();
def Response = context.expand('${Heartbeat#Response}'); if (Response != "true"){ testRunner.runTestStepByName("RefreshToken"); sleep (1000); testRunner.runTestStepByName("TransferRefreshedToken"); } else { sleep (60000); } } } thread.join();


3 Replies

  • nmrao's avatar
    Champion Level 3
    This is how it can achieved if the objective is to fire the request x no of times with a delay of y seconds which uses out of the box functionality.
    Have simple test case with required test step (no scripts involved), create a load test as described in the below documentation and execute it (either from the tool or from the command line, I prefer the later to execute).

    Please see if this approach is suitable for your case.
    • sonya_m's avatar
      SmartBear Alumni (Retired)

      Great advice nmrao!


      wpar did the suggestion work? 

    • wpar's avatar
      New Contributor

      So from the looks of it this isn't the exact route I was attempting to go (though that could just be because I'm so new to the program), but it did make me realize another way to write the test cases that would allow me to use the method you mention.


      So thank you!