Difference between revisions of "Integrating Pega unit tests and scenario tests into build tools and pipelines"

From PegaWiki
Integrating Pega unit tests and scenario tests into build tools and pipelines
Jump to navigation Jump to search
m
Tag: Visual edit
m (curator assigned)
Tag: Visual edit
Line 3: Line 3:
 
|Request to Publish=Yes
 
|Request to Publish=Yes
  
|Curator Assigned=
+
|Curator Assigned=szall
 
|Description=Integrating Pega Units/Scenario tests into build tools and Jenkins
 
|Description=Integrating Pega Units/Scenario tests into build tools and Jenkins
 
|Applications=Platform
 
|Applications=Platform

Revision as of 15:18, 16 November 2020


Curator Assigned szall
Request to Publish Yes
Description Integrating Pega Units/Scenario tests into build tools and Jenkins
Version as of 8.5
Application Platform
Capability/Industry Area DevOps

Introduction[edit]

Automated unit testing is a key stage of a continuous development and continuous integration model of application development. With continuous and thorough testing, issues are identified and fixed prior to releasing an application, which improves the application quality. Continuous and Automated unit testing is achieved with help of Build tools like Maven, Gradle etc. and Continuous Integration tools like Jenkins, Bamboo etc..

Integrating with Build tools[edit]

What is Build tool?[edit]

  • ·        Software build tools are used to automate the creation of executable applications from source code
  • ·        They script or automate a variety of tasks, such as downloading dependencies, compiling and packaging code, running tests, and deployment
  • ·        Examples of Build tools: ANT, MAVEN and GRADLE etc.

As gradle is widely used build tool, will look at how to execute Pega units and Pega scenario tests from sample gradle build script

Execution of Pega Units through gradle build tool[edit]

Pega Platform provides service to execute Pega unit test cases or test suites in your application and return results in xUnit format

Service comprises the following information

  • ·        Service name: PegaUnit Rule-Test-Unit-Case pzExecuteTests
  • ·        Service package: PegaUnit
  • ·        Endpoint:http://<yourapplicationURL>/prweb/PRRestService/PegaUnit/Rule-Test-Unit-Case/pzExecuteTests

               Add REST dependency to invoke Pega unit rest service from your gradle script like below

Restgradledependency.png

Create your gradle task by sending request parameters as below

  • Uri:  Provide the end point URL of your application
  • Username: Provide the operator name
  • Password: Provide the password
  • HTTP Method as post and Content Type as XML

For Example, to execute Pega unit tests through gradle task

PegaUnitA.png

Note: The above gradle task can be called from Jenkins pipeline as well as standalone gradle build task

Pega platform also provides another service to execute Pega Units in asynchronous mode. This service returns polling ID as response which can be used to track the execution output by using it with the rest service /pegaunits/execute/{ID}/results

Service comprises the following information

  • ·        Service name: pegaunits
  • ·        Service package: api
  • ·        Endpoint:http://<yourapplicationURL>/prweb/api/v1/pegaunits/execute

Execution of Pega Scenario tests through gradle build tool[edit]

Pega Platform provides service to execute Pega scenario tests and returns the status code of service

Service comprises the following information and its query parameters

  • ·        Service name: scenariotests
  • ·        Service package: api
  • ·        Endpoint:http://<yourapplicationURL>/prweb/api/v1/scenariotests/execute

Query Parameters:

  • JOB ID: Unique Job ID/Run ID/Build number for the invocation (Used by the Deployment manager to separate runs across deployments, also passed as the run id to cloud providers for tracking)
  • Provider: STANDALONE | CBT | BROWSERSTACK Test service provider to use (or Test service cloud provider).
  • ProviderAuthName: Auth name for the test service account
  • ProviderAuthKey: Auth key for the test service account
  • ProviderURL: Alternate test service provider URL (Optional - Generally used for local selenium hubs).
  • Browser: Browser to run the UI tests on.
  • BrowserVersion: Browser version to run the UI tests on.
  • Platform: OS platform to use.
  • PlatformVersion: OS Platform version to use.
  • ScreenResolution: Resolution of the test system screen to run the tests on.
  • SUTURL: URL of the Pega system under test.
  • SUTUserID: Test operator ID from the Pega system under test.
  • SUTPassword: Password of the test operator ID from the Pega system under test.
  • TestSuiteID: pxInsname of the testsuite to be executed.

Add REST dependency to invoke pega unit rest service from your gradle script like below

dependencies {

classpath group: 'org._10ne.gradle', name: 'rest-gradle-plugin', version: '0.4.2'

}

Build your service URL like below

http://xxx:8080/prweb/api/v1/scenariotests/execute?JobID=1&Provider=STANDALONE&ProviderURL=http://10.225.82.213:5555/wd/hub/&Browser=chrome&BrowserVersion=83.0.4103.39&Platform=XP&SUTURL=http://xxxx:8080/prweb/&SUTUserID=xxx&SUTPassword=xxx&TestSuiteID=xxxxx

Create your gradle task by sending request parameters as below

  • Uri:  Provide the end point URL of your application
  • Username: Provide the operator name
  • Password: Provide the password
  • HTTP Method as post

Note: Before running the service, make sure Provider URL is up and running, look at the references section on how to launch Selenium Grid and Browser stack

Sample gradle task to execute Pega scenario tests

Scenariotestgradletask.png

Integrating with Jenkins[edit]

What is Jenkins?[edit]

Jenkins is an open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery.

Jenkins is highly used CICD tool, Now will look at how can we execute Pega units from Jenkins pipeline project and Jenkins free style project

Jenkins pipeline configuration[edit]

Calling a gradle task from a Jenkins pipeline configuration

  • Open a web browser and navigate to the location of the Jenkins server.
  • Create a Jenkins job of type Pipeline
  • Create a Jenkins pipeline script file like below to run gradle task from your build.gradle<< you can parameterize the URL, UserName and passwords and pass it from Jenkins file to gradle task >>
Jenkinspipelinesnippet.png

Free style Jenkins project[edit]

  • Creating a free style project (old fashioned) and configure the Jenkins server to call the service.
  • Open a web browser and navigate to the location of the Jenkins server.
  • Install the HTTP request plug-in for Jenkins to call the service and the JUnit Plugin so that you can view reports in xUnit format.
    1. Click Manage Jenkins.
    2. Click Manage Plugins.
    3. On the Available tab, select the HTTP Request Plugin check box and the JUnit Plugin check box.
    4. Specify whether to install the plug-in without restarting Jenkins or to download the plug-in and install it after restarting Jenkins.
  • Configure the Pega Platform credentials for the operator who authenticates the Execute Tests service.
    1. Click Credentials, and then click System.
    2. Click the drop-down arrow next to the domain to which you want to add credentials and click Add credentials.
    3. In the Username field, enter the operator ID that is used to authenticate the service. This operator should belong to the access group that is associated with the application for which you want to run test cases and test suites.
    4. In the Password field, enter the password.
    5. Click OK.
  • Configure the Jenkins URL that runs the service.
    1. Click Manage Jenkins, and then click Configure System.
    2. In the Jenkins Location section, in the Jenkins URL field, enter the URL of the Jenkins server.
    3. Click Apply, and then click Save.
  • Add a build step to be run after the project is built.
    1. Open an existing project or create a project.
    2. Click Configure.
    3. In the Build section, click Add build step, and select HTTP Request from the list.
    4. In the HTTP Request section, in the URL field, enter the endpoint of the service. http://<your application URL>/prweb/PRRestService/PegaUnit/Rule-Test-Unit-Case/pzExecuteTests
  • From the HTTP mode list, select POST.
  • Click Advanced.
  • In the Authorization section, from the Authenticate list, select the Pega Platform operator ID that authenticates the service that you configured in step 3.
  • In the Response section, in the Output response to file field, enter the name of the XML file where Jenkins stores the output that it receives from the service. This field corresponds to the LocationOfResults request parameter.
  • In the Post-build Actions section, from the Add post build section list, select Publish Junit test result report and enter **/*.xml in the Test Report XML field. This setting configures the results in xUnit format, which provides information about test results, such as a graph of test results trends, on your project page in Jenkins.
  • Click Apply, and then click Save.
  • After job configuration. you can run your test suites and test cases.
  • Open the project and click Build Now.
  • In the Build History pane, click the build that was run.
  • On the next page, click Test Result.
  • In the All Tests section, click root. The results of all failed tests and all tests are displayed.

Running Pega Units and Pega scenario tests from Deployment Manager[edit]

Configuration to execute Pega units in Deployment Manager[edit]

The Pega unit testing task is run for the access group that is specified in the Application test cases section, which you configure when you add or modify a pipeline.

To add a Pega unit test task, do the following steps:

  1. Do one of the following actions:
    • Click a manually added task, click the More icon, and then click either Add task above or Add task below.
    • Click Add task in the stage.
  2. To run Pega unit tests for either the pipeline application or for an application that is associated with an access group, select Pega unit testing from the Task list.
  3. Optional: Perform one of the following actions:
    • To run all the Pega unit tests that are in a Pega unit suite for the pipeline application, in the Test Suite ID field, enter the pxInsName of the test suite. You can find this value in the XML document that comprises the test suite by clicking, in Pega Platform, Actions > XML on the Edit Test Suite form. If you do not specify a test suite, all the Pega unit tests for the pipeline application are run.
    • To run all the Pega unit tests for an application that is associated with an access group, in the Access Group field, enter the access group.
    • Click Submit.

Configuration to execute Pega Scenario tests in Deployment Manager[edit]

  1. Do one of the following actions:
    • Click a manually added task, click the More icon, and then click either Add task above or Add task below.
    • Click Add task in the stage.
  2. From the Task list, select Run Pega scenario tests.
  3. In the User name field, enter the user name for the Pega Platform instance on which you are running scenario tests. For the Run Pega scenario tests task, if you are using a separate product rule for a test application, the user name that you provide should belong to the access group that is associated with the test application.
  4. In the Password field, enter the Pega Platform password.
  5. From the Test Service Provider field, select the browser that you are using to run the scenario tests in the pipeline.
  6. Do one of the following actions:
    • If you selected CrossBrowserTesting, BrowserStack, or SauceLabs:
      • In the Provider auth name field, enter the auth name that you you use to log in to the test service provider.
      • In the Provider auth key field, enter the key for the test service provider.
    • If you selected Standalone, in the Provider URL field, enter the URL of the Selenium Standalone Server by using one of the following:
      1. Hub hostname and port: Use the format Hubhostname:port.
      2. IP address: Enclose the IP address in double quotation marks.
  7. In the Browser field, enter the browser that you are using to record scenario tests.
  8. In the Browserversion field, enter the browser version.
  9. In the Platform field, enter the development platform that you are using to record tests.
  10. In the Screen resolution field, enter the resolution at which are recording scenario tests.
  11. Click Submit.

Reference Links:[edit]

https://community.pega.com/knowledgebase/articles/devops-release-pipeline-overview/running-pegaunit-test-cases-and-test-suites-execute-tests-service-pega-74

https://collaborate.pega.com/discussion/crossbrowsertesting-integration-scenario-testing-framework

https://collaborate.pega.com/discussion/browserstack-integration-scenario-testing-framework

https://collaborate.pega.com/discussion/selenium-grid-integration-scenario-testing-framework

https://community.pega.com/knowledgebase/articles/devops-release-pipeline-overview/using-deployment-manager-45x