LoadRunner and Performance Center Blog
cancel

How to create a new performance test using PC REST API

How to create a new performance test using PC REST API

Micro Focus Expert

This post was written by Alex Geifman from the Performance Center Quality Teamalex_geifman_web.jpg

 

 

In my previous article, I explained the principles of REST and provided basic examples for working with the PC REST API.

In this article, I will concentrate on the create and update performance test REST calls. Due to the many possible configurations, the test entity XML supplied in the body of these calls can look quite formidable and confusing at first. I will try to make it clearer.

Part 1 - Creating a performance test

The syntax of a test creation REST call is as follows:

POST /LoadTest/rest/domains/{domainName}/projects/{projectName}/tests

Header: Content-Type: application/xml

Cookies: LWSSO_COOKIE_KEY={LwssoCookie};QCSession={QCSessionCookie};

 

The test configuration should be passed in the request body as test entity XML.

Hint: As a first step in acquaintance with the structure of test entity XML, perform GET of the load test created manually and inspect the response. The test entity in the body of the response can be used as a basis for updating the test or creating a new one.

 

As you can see in the documentation, there are the following available elements:

 

rest1.png 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I will just concentrate on the mandatory parts (marked in bold in the image above).

This is a simplified example of the test entity XML: 

<Test xmlns="http://www.hp.com/PC/REST/API">

   <Name>Test1</Name>

   <TestFolderPath>Subject\folderName</TestFolderPath>

        <Content

           <WorkloadType>

                   <Type>. . .</Type>

                   <SubType>. . .</SubType>

               . . .

           </WorkloadType

           <LGDistribution>

                   <Type>. . .</Type>

           </LGDistribution>

                . . .                 

           <Groups>

                   <Group>

                      . . .     

                   </Group>         

                   <Group>

                       . . .

                   </Group>

           </Groups>          

            <Scheduler>

                   <Actions>

                          <Action>

                               . . .

                          </Action>

                          <Action>

                                . . .

                          </Action>

                                 . . .

                     </Actions>

           </Scheduler>

   </Content>

</Test>

 

 

<Name> and <TestFolderPath> are self-explanatory elements.

Let’s look at the four main elements in the <Content> element: <WorkloadType>, <LGDistribution>, <Groups>, and <Scheduler>. 

<WorkloadType>

You are familiar with the workload types from the Performance Center user interface when creating a new test:

Createtest.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

There are three workload types: “Basic,” “Real-World,” and “Goal-Oriented.” “Basic” and “Real-World” types contain two subtypes: “By Test” and “By Group.”

 

The following diagram shows all the valid sub-element configurations inside the <WorkloadType> element:

Workload.png

 

 

Examples of the different workload types:

Real world:

<WorkloadType>

           <Type>real-world</Type>

           <SubType>by group</SubType>

 </WorkloadType>

          

 Basic:

<WorkloadType>

                <Type>basic</Type>

               <SubType>by test</SubType>

               <VusersDistributionMode>by number</VusersDistributionMode>

</WorkloadType>

          

 Goal Oriented:

<WorkloadType>

               <Type>goal oriented</Type>

           </WorkloadType>

             

<LGDistribution>

There are two types of load generator distributions: assign “all to each group” or “manual” distribution.LGDiost.png

 

 

 

 

 

 

 

 

If you use the assign “all to each group” type, you need to enter the number of load generators.

For “manual” distribution, you must add the <Groups> element (described below).

Example of “assign all to each group” distribution:

        <LGDistribution>

           <Type>all to each group</Type>                           

           <Amount>3</Amount>

        </LGDistribution>

 

Example of “manual” distribution:

        <LGDistribution>

           <Type>manual</Type>                       

        </LGDistribution>

 

<Groups>

The <Groups> element contains one or multiple <Group> sub-elements, in which all the group-related data is contained.

If <LGDistribution> type is set to “manual,” the <Group> also includes the list of hosts, with a host <Type> for each host in the group:Groups.png

 

 

 

Example 1
 An example of a <Groups> section with two <Group> elements, each containing a <Hosts> section. The first <Group> element also contains an <RTS> section:

<LGDistribution>

           <Type>manual</Type>                       

        </LGDistribution>

         . . .

           <Groups>

                   <Group>

                          <Name>web</Name>

                          <Vusers>41</Vusers>

                  <Script>

                       <ID>12</ID>

                  </Script>

                  <Hosts>

                       <Host>

                             <Name>Lab_machine_12232</Name>

                             <Type>specific</Type>

                       </Host>

                       <Host>

                             <Name>Lab_machine_30559</Name>

                             <Type>specific</Type>

                       </Host>

                  </Hosts>

                          <RTS>

                       <Pacing>

                              <NumberOfIterations>1</NumberOfIterations>

                              <StartNewIterationType="immediately" />

                       </Pacing>

                       <ThinkTimeType="replay" />

                       <LogType="disable" />

                     </RTS>

              </Group>

             <Group>

                  <Name>some_script</Name>

                  <Vusers>67</Vusers>

                  <Script>

                       <ID>26</ID>

                  </Script>

                          <Hosts>

                       <Host>

                          <Name>Lab_machine_30559</Name>

                          <Type>specific</Type>

                       </Host>

                       <Host>

                          <Name>LG1</Name>

                          <Type>automatch</Type>

                       </Host>

                      </Hosts>

          </Group>

            </Groups>

       

Example 2
An example of a <Group> element containing a <Scheduler> element:

<Groups>

        <Group>

               <Name>auto_group</Name>

               <Vusers>2</Vusers>

               <Script>

                       <ID>42</ID>

               </Script>

               <Scheduler>

                 <Actions>

                       <Action>

                               <StartGroup Type="immediately"></StartGroup>

                       </Action>

                     <Action>

                       <Initialize Type="just before vuser runs">

                               <Vusers>0.0</Vusers>

                       </Initialize>

                 </Action>

                 <Action>

                       <StartVusers Type="simultaneously">

                               <Vusers>2</Vusers>

                       </StartVusers>

                 </Action>

                 <Action>

                          <Duration Type="run for">

                         <TimeInterval>

<Days>0</Days>

<Hours>0</Hours>

<Minutes>2</Minutes>

<Seconds>0</Seconds>

       </TimeInterval>

</Duration>

</Action>

               <Action>

                       <StopVusers Type="simultaneously">

                       </StopVusers>

               </Action>

               </Actions>

            </Scheduler>

        </Group>

 </Groups>

 

 

<Scheduler>

You use the scheduler to create a schedule that distributes load in a performance test in a controlled manner. The scheduler displays the actions that correspond to the selected workload type.

For a “Basic” or “Real-World” workload type, you use the <Scheduler> type; this is a Global Scheduler. <Scheduler> can appear as a separate element, or under Groups/Group/Scheduler.

For a “Goal-Oriented” workload type, you use the <GoalScheduler> type (introduced in PC 12.60). When using a goal-oriented scheduler, Performance Center automatically builds a schedule for you based on the goal you set for your test to achieve.WL2.png

 

 

 

 

 

 

 

 

 

 

 

 

Example 1

An example of a Goal Oriented which tests whether the application can run a specified number of Vusers simultaneously:

<Test xmlns="http://www.hp.com/PC/REST/API">

<Name>TESTNAME</Name>

<TestFolderPath>Subject\Tests</TestFolderPath>

<Content>

     <WorkloadType>

        <Type>goal oriented</Type>

     </WorkloadType>

         . . .

        <GoalScheduler>

               <GoalProfileName>GoalVusers30</GoalProfileName>

               <GoalType>VirtualUsers</GoalType>

                <GoalVirtualUsers>

                   <TargetVusersNumber>30</TargetVusersNumber>

               </GoalVirtualUsers>

               <DoNotChangeScriptThinkTime>true</DoNotChangeScriptThinkTime>

               <ScenarioSettings>

                   <GoalCannotBeReachedAction>

                       ContinueWithoutReaching

                   </GoalCannotBeReachedAction>

                   <RunTimeAfterGoalAchieved>

                       <Minutes>30</Minutes>

                  </RunTimeAfterGoalAchieved>

                 <ReceiveNotification>true</ReceiveNotification>

               </ScenarioSettings>

        </GoalScheduler>

        …

 

 

Example 2

An example of a global scheduler is provided below:

<Test xmlns="http://www.hp.com/PC/REST/API">

<Name>TESTNAME</Name>

<TestFolderPath>Subject\Tests</TestFolderPath>

<Content>

     <WorkloadType>

        <Type>real-world</Type>

        <SubType>by group</SubType>

     </WorkloadType>

        …. 

           <Scheduler>

               <Actions>

                  <Action>

                       <InitializeType="just before vuser runs" />

                  </Action>

                  <Action>

                       <StartVusersType="simultaneously" />

                  </Action>

                  <Action>

                       <DurationType="until completion" />

                  </Action>

               </Actions>

           </Scheduler>

 

 

 Now that you are familiar with the main elements, I will provide examples of complete test entity XMLs. You can use them as a basis for developing your own REST API calls.

Example 1
Create a “Real-World (by test)” test that starts and stops Vusers simultaneously.

<Test xmlns="http://www.hp.com/PC/REST/API">
      <Name>test_3</Name>
      <TestFolderPath>Subject\testA</TestFolderPath>
      <Content>
            <WorkloadType>
                  <Type>real-world</Type>
                  <SubType>by test</SubType>
                  <VusersDistributionMode>by number</VusersDistributionMode>

            </WorkloadType>
            <LGDistribution>
                  <Type>manual</Type>
                  <Amount>1</Amount>
            </LGDistribution>
            <Groups>
                  <Group>
                        <Name>auto_group</Name>
                        <Vusers>2</Vusers>
                        <Script>
                              <ID>23</ID>
                        </Script>
                  </Group>
                  <Group>
                        <Name>group_2</Name>
                        <Vusers>5</Vusers>
                        <Script>
                              <ID>23</ID>
                        </Script>
                  </Group>
            </Groups>
            <Scheduler>
                  <Actions>
                  <Action>
                        <Initialize Type="just before vuser runs">
                        <Vusers>0.0</Vusers>
                        </Initialize>
                        </Action>
                        <Action>
                              <StartVusers Type="simultaneously">
                                    <Vusers>2</Vusers>
                              </StartVusers>
                        </Action>
                        <Action>
                              <Duration Type="run for">
                                    <TimeInterval>
                                          <Days>0</Days>
                                          <Hours>0</Hours>
                                          <Minutes>2</Minutes>
                                          <Seconds>0</Seconds>
                                    </TimeInterval>
                              </Duration>
                        </Action>
                        <Action><StopVusers Type="simultaneously"></StopVusers>
                        </Action>
                  </Actions>
            </Scheduler>
      </Content>
</Test>

 

Example 2
Create a “Real-World (by group)” test that starts and stops Vusers simultaneously. 

<Test xmlns="http://www.hp.com/PC/REST/API">
      <Name>n4</Name>
      <TestFolderPath>Subject\folder_a</TestFolderPath>
      <Content>
            <WorkloadType>
                  <Type>real-world</Type>
                  <SubType>by group</SubType>
            </WorkloadType>
            <LGDistribution>
                  <Type>all to each group</Type>
                  <Amount>3</Amount>
            </LGDistribution>
            <Groups>
                  <Group>
                        <Name>auto_group</Name>
                        <Vusers>2</Vusers>
                        <Script>
                              <ID>42</ID>
                        </Script>
                        <Scheduler>
                              <Actions>
                                    <Action>
                                          <StartGroup Type="immediately"></StartGroup>
                                    </Action>                                
                                    <Action>
                                          <Initialize Type="just before vuser runs"><Vusers>0.0</Vusers></Initialize>
                                    </Action>
                                    <Action>
                                          <StartVusers Type="simultaneously">                                          

                                                        <Vusers>2</Vusers>
                                          </StartVusers>
                                    </Action>
                                    <Action>
                                          <Duration Type="run for">
                                                <TimeInterval>
                                                <Days>0</Days>
                                                <Hours>0</Hours>
                                                <Minutes>2</Minutes>
                                                <Seconds>0</Seconds>
                                                </TimeInterval>
                                          </Duration>
                                    </Action>
                                    <Action>
                                           <StopVusers Type="simultaneously">
                                          </StopVusers>
                                    </Action>
                              </Actions>
                        </Scheduler>
                  </Group>
                  <Group>
                        <Name>group sec</Name>
                        <Vusers>12</Vusers>
                        <Script>
                              <ID>41</ID>
                        </Script>
                        <Scheduler>
                              <Actions>
                                    <Action>
                                    <StartGroup Type="when group finishes">
                                          <Name>auto_group</Name>
                                    </StartGroup>
                                    </Action>  
                                    <Action>
                              <Initialize Type="just before vuser runs">
                                    <Vusers>0.0</Vusers>
                              </Initialize>
                                    </Action>
                                    <Action>
                                          <StartVusers Type="simultaneously">
                                                <Vusers>2</Vusers>
                                          </StartVusers>
                                    </Action>
                                    <Action>
                                          <Duration Type="run for">
                                                <TimeInterval>
                                                <Days>0</Days>
                                                <Hours>0</Hours>
                                                <Minutes>12</Minutes>
                                                <Seconds>0</Seconds>
                                                </TimeInterval>
                                          </Duration>
                                    </Action>
                                    <Action>
                                          <StopVusers Type="simultaneously">
                                          </StopVusers>
                                    </Action>
                              </Actions>
                        </Scheduler>
                  </Group>               
            </Groups>
      </Content>
</Test>

 

 Example 3
Create a “Goal-Oriented” test with goal-type: Transactions Per Second. 

<Test xmlns="http://www.hp.com/PC/REST/API">
  <Name>transactions_new22</Name>
  <TestFolderPath>Subject\a_goal</TestFolderPath>
  <Content>
    <WorkloadType>
      <Type>goal oriented</Type>
    </WorkloadType>
    <LGDistribution>
      <Type>all to each group</Type>
      <Amount>1</Amount>
    </LGDistribution>
       <Groups>
      <Group>
        <Name>name1</Name>
        <Vusers>100</Vusers>
        <Script>
          <ID>39</ID>
        </Script>
         <RTS>
          <Pacing>
            <NumberOfIterations>1</NumberOfIterations>
            <StartNewIteration Type="fixed delay">
              <DelayOfSeconds>60</DelayOfSeconds>
            </StartNewIteration>
          </Pacing>
          <ThinkTime Type="replay" />
          <Log Type="disable" />
        </RTS>
      </Group>
      <Group>
        <Name>name2</Name>
        <Script>
          <ID>66</ID>
        </Script>
         <RTS>
          <Pacing>
            <NumberOfIterations>1</NumberOfIterations>
            <StartNewIteration Type="fixed delay">
              <DelayOfSeconds>60</DelayOfSeconds>
            </StartNewIteration>
          </Pacing>
          <ThinkTime Type="replay" />
          <Log Type="disable" />
        </RTS>
      </Group>
    </Groups>
    <GoalScheduler>
       <GoalProfileName></GoalProfileName>
       <GoalType>TransactionsPerSecond</GoalType>
       <GoalTransactionsPerSecond>
            <TargetTransactionsPerSecond>2</TargetTransactionsPerSecond>
                          <TransactionName>T01_sleep_5_seconds</TransactionName>
                    <MinVusers>400</MinVusers>
                    <MaxVusers>500</MaxVusers>
       </GoalTransactionsPerSecond>
             <DoNotChangeScriptThinkTime>true</DoNotChangeScriptThinkTime>
            <ScenarioSettings>
                  <GoalCannotBeReachedAction>ContinueWithoutReaching</GoalCannotBeReachedAction>
              <RunTimeAfterGoalAchieved>
                      <Seconds>01</Seconds>                               
              </RunTimeAfterGoalAchieved>
              <ReceiveNotification>true</ReceiveNotification>
       </ScenarioSettings>
    </GoalScheduler>
  </Content>
</Test>

 

 

 

 Part 2 - How to update a performance test using PC REST API

The syntax of a test update REST call is as follows:

PUT /LoadTest/rest/domains/{domainName}/projects/{projectName}/tests/{testID}

Header: Content-Type: application/xml

Cookies: LWSSO_COOKIE_KEY={LwssoCookie};QCSession={QCSessionCookie};

 

An XML describing the data to be updated in the test should be passed in the request body as in test entity XML.

NOTES:

  • In addition to the updated element, the following elements must always appear: <WorkloadType>, <LGDistribution>, <Groups>, and <Scheduler>/<GoalScheduler>.
  • Test name and location of the test cannot be changed, so these element are not used in the update.
  • The easiest way to update a test is to perform GET on the test and use the response test entity XML as a basis for the test entity XML in the update rest call.
  • The root xml element is not <test> but <Content>:content.png

 

 

 

 

 

 

 

 

 

 

 

 

Example of PUT request which updates the test

PUT http://<PcServer>/LoadTest/rest/domains/TEST_DOMAIN/projects/TEST_PROJECT/tests/123

Content-Type: application/xml

Body:
<Content xmlns="http://www.hp.com/PC/REST/API">

<WorkloadType>

   <Type>Basic</Type>

   <SubType>by test</SubType>

   <VusersDistributionMode>by number</VusersDistributionMode>

</WorkloadType>

<LGDistribution>

   <Type>all to each group</Type>

   <Amount>1</Amount>

</LGDistribution>

<Groups>

   <Group>

      <Name>auto_group</Name>

      <Vusers>23</Vusers>

      <Script>

        <ID>4</ID>

     </Script>

   </Group>

</Groups>

<Scheduler>

<Actions>

   <Action>

      <Initialize Type="just before vuser runs">

      <Vusers>0.0</Vusers>

      </Initialize>

   </Action>

   <Action>

      <StartVusers Type="gradually">

      <Ramp>

        <TimeInterval>

           <Days>0</Days>

           <Hours>0</Hours>

           <Minutes>0</Minutes>

           <Seconds>50</Seconds>

        </TimeInterval>

        <Vusers>2</Vusers>

      </Ramp>

      </StartVusers>

   </Action>

   <Action>

      <Duration Type="run for">

      <TimeInterval>

         <Days>0</Days>

         <Hours>0</Hours>

         <Minutes>2</Minutes>

         <Seconds>0</Seconds>

       </TimeInterval>

</Duration>

   </Action>

   <Action>

      <StopVusers Type="simultaneously">

      </StopVusers>

   </Action>

</Actions>

</Scheduler>

</Content>

 

 

 Conclusion

This blog post provides simplified explanations and examples for creating and updating performance test REST calls. I hope you find it useful when working with PC REST APIs.

For more information, visit our online PC REST API  documentation.