Tosca CICD实现的架构图


关于 Tricentis Tosca 的AOS (Automation Object Service)
Without AOS
如果不用Tosca的AOS 服务, 可以看到Agent还是比较复杂的,每个Agent都需要有Workspace

With AOS
可以看到采用AOS(Automation Object Service)以后,每个Agent不需要单独配置workspace了。
可以看到 AOS 有自己的workspace,其中 AOS 充当了中间人的角色,在Tosca Commander 和 Agent之间起到了桥梁作用。

当Agent执行完测试以后,会把结果传回Tosca Distribution Server,Tosca Distribution Server会把结果传给 AOS(Automation Object Service),AOS 再把结果传到 Common Repository 数据库中。在Tosca Commander 就能查看到结果了。
下面我们开始尝试配置一个Tosca 的分布式测试环境。
1. 创建一个Common Repository

当用Tosca Commander时可以看到 Tosca Commander的 Common Repository(数据库)支持上面几种类型,这次我们创建一个MS SQL Server的数据库。
我们通过docker镜像来快速启动一个MS SQL Server的数据库服务
- 拉取镜像
docker pull mcr.microsoft.com/mssql/server:2022-latest
- 运行容器
docker run -d --name mssql-server -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=数据库密码" -p 1433:1433 -v /Users/xxx/Documents/mssql/data:/var/opt/mssql mcr.microsoft.com/mssql/server:2022-latest
数据库用户名是:sa,密码是SA_PASSWORD设定的,端口:1433
用工具连接DBeaver 连接 MS SQL Server的数据库 创建一个空的数据库,tosca_db

2.创建测试 User
- 在Tosca Server的控制台–点击 User Administration

- 点击Add new

- 输入 User Name,账户过期时间,权限,点击Generate Token就可以生成账户了,本地保存好生成的 Client ID 和 Client secret,无法再次查看。

3. 启动 Tosca 的 Agent 服务
Agent 的服务,可以单独安装。Tosca Server安装的话,默认就集成了Agent。
我们在下面路径,可以找到 ToscaDistributionAgent.exe 服务
C:\Program Files (x86)\TRICENTIS\Tosca Testsuite\DistributedExecution

在 ToscaDistributionAgent.exe 鼠标右键,点击 以管理员身份运行
启动以后,在系统的桌面右下角,就能看到Agent的电脑图标了。

在这个图标上,点击右键,进行Configure Agent,进行配置

主要需要修改
- Connect server (Distribution Server Address)
http://localhost:5007/
这个Server Address 可以在Tosca Server 控制台 – Settings – Automation Object Service中查看到


- Authenticate Agent
# 这个是Tosca Server的地址和端口号,因为我Agent和 Tosca Server安装在一台机器上所以用的localhost Token endpoint URL: http://localhost:8081/connect/token Credentials Source:Local Client ID:上面步骤2生成 Client secret:上面步骤2生成

4.创建一个 Tosca Commander Workspace
我们利用 Tosca Commander 来创建工程,设计测试Case,并且想通过 Tosca Commander 来启动分布式服务Agent。
按照下面的输入,创建一个新的workspace,Repository 选择上面的MS SQL Server数据库。因为是新创建,这里面不选 Use existing Repository

这里会弹出Login登录框,Username是Admin,密码是空,点击Login就行

Tosca Commander 会在 MS SQL Server的 tosca_db 数据库中,初始化创建一些表。

在 Tosca Commander 工程,如图创建 Execution–> TestEvents
参考 youtube视频: https://www.youtube.com/watch?v=1k3wLzXPhqI

‼️重要:修改完,务必点击上面的check in 按钮, 把工程上传到 数据库 Repository。
Tosca Commander 还需要做一些设置,连接分布式监视服务
- 点击 Project —> Settings


- Commander–>DistributedExecution 和 Tricentis Services 需要填写下面的信息
# http://localhost:8081是 Tosca server的 url Monitor Url: http://localhost:8081/monitor Server Url: http://localhost:8081/DistributionServerService/ManagerService.svc Tricentis Services: http://localhost:8081/



再回到Tosca工程,在Configurations,点击鼠标右键,点击 Refresh Agents, 刷新Agent服务状态。


可以看到Agent服务变成1,代表有1台Agent可用。

这时我们在Test Event上点击执行,出现下面的错误。原因是,AOS的 workspace还没有创建。


点击Checkin all 上传所有的修改

5.在Tosca Sever 控制台创建Project
在Tosca Sever 控制台 点击 Administration Console,然后点击add project,输入相关的信息。
name:tosca_cicd_demo Respositry:MSSSQL connection String:Server=123.xx.xx.xx;Database=tosca_db;Uid=sa;Pwd=xxxxx;


6.创建 Tosca AOS 的 Workspace
如图创建一个 AOS 用的workspace。
注意:
Select Type of Repository:Tricents Server Repository


AOS workspace 启动时,会默认去从 Tricents Server Repository 下载最新的配置,如果没加载,也可以点击Update all手动更新
7.配置 Tosca AOS 服务
按照下面的配置即可,然后保存会自动重启服务,大概需要2分钟。




8.用AOS Execution API 去Trigger一个测试
- 可以用下面的命令去取得一个API Token
# http://xxxxx:35801是Tosca Server url,用frp内网穿透出去的 # client_id 和 client_secret是上面创建user时生成的 curl --location --request POST 'http://xxxxx:35801/tua/connect/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'grant_type=client_credentials' \ --data-urlencode 'client_id=xxxxxx' \ --data-urlencode 'client_secret=xxxxx'
- 在Tosca Server以外的机器,可以用下面的Post请求激活一个分布式测试Event

API 接口详情参考:
https://support-hub.tricentis.com/open?id=manual&lang=en&path=%2Ftosca%2F2420%2Fen%2Fcontent%2Fcontinuous_integration%2Fexecution_api_integration.htm&product=tosca&sessionRotationTrigger=true&type=product_manual&version=2024.2
https://documentation.tricentis.com/tosca/1520/en/content/continuous_integration/execution_api_integration.htm
- 在Tosca Server控制台可以看到 Agent执行测试的情况。


补充:Create Tosca Distributed Execution configurations
补充,可以给DEX Agent设定 parameters, 然后在Tosca Commander,可以根据parameters来指定Agent。
You can specify which Tosca Distribution Agents should execute the ExecutionLists in your TestEvent.
To do so, you need to use configurations. A configuration defines which hardware or software is required to execute a certain ExecutionList.
By default, Tosca offers the following configurations:
Configuration | Description |
---|---|
Any | All Agents. By default, the Tosca Distribution (DEX) Server hands any TestEvent to any available Agent. |
RDP | All Agents configured for Unattended Execution. |
The same Agent may be listed in several configuration categories. For example, an Agent that you have configured for Unattended Execution belongs to both categories.
You can create custom configurations based on your own test criteria.
For instance, you can create a configuration exclusively for Agents with Firefox installed. Or a configuration for Agents running on Windows 10, with 32 GB of memory.
To do so, follow the workflow outlined below. The subsequent chapters describe each step in detail.
- Set parameters on the DEX Server. These parameters are the criteria you will later use in your configurations.
- Apply the parameters to your Agents. This specifies which Agent fits the criteria.
- Create your custom configuration in Tosca Commander.
Set parameters on the DEX Server
To set parameters on the server, you have the following options:
- You can create entirely new parameters.
- You can change the values of the default parameters OperatingSystem, Memory, OperatingSystemType, IPAddress, and HostName. For instance, the default values for Memory are 2GB, 4GB, 8GB, 16GB, and 32GB. You can change or delete values, or you can add an additional value option for this parameter.
To create an entirely new parameter, follow the steps below:
- On the DEX Server machine, access the file ConfigurationParameters.xml. By default, this file is located at C:\Program Files (x86)\TRICENTIS\Tosca Server\DEXServer. The system creates the file once the DEX Server is started for the first time.
- Add the new parameter within the TestConfigurationParameters tags. It’s easiest to copy and paste an existing parameter and then adapt it to your needs. The example below shows how to create a parameter for Agents with Firefox installed:
<TestConfigurationParameter> <Name>FirefoxInstalled</Name> <Comment></Comment> <TestConfigurationParameterValues> <TestConfigurationParameterValue> <Key>1</Key> <Value>Yes</Value> </TestConfigurationParameterValue> <TestConfigurationParameterValue> <Key>2</Key> <Value>No</Value> </TestConfigurationParameterValue> </TestConfigurationParameterValues> </TestConfigurationParameter>
To change an existing parameter, follow the steps below:
- On the DEX Server machine, access the file ConfigurationParameters.xml. By default, this file is located at C:\Program Files (x86)\TRICENTIS\Tosca Server\DEXServer. The system creates the file once the DEX Server is started for the first time.
- Modify the value of the respective parameter. In the example below, you have changed one of the default values for the parameter Memory from 32GB to 64GB. Additionally, you have added an additional value option: 70GB.
<TestConfigurationParameter> <Name>Memory</Name> <Comment></Comment> <TestConfigurationParameterValues> <TestConfigurationParameterValue> <Key>1</Key> <Value>2 GB</Value> </TestConfigurationParameterValue> <TestConfigurationParameterValue> <Key>2</Key> <Value>4 GB</Value> </TestConfigurationParameterValue> <TestConfigurationParameterValue> <Key>3</Key> <Value>8 GB</Value> </TestConfigurationParameterValue> <TestConfigurationParameterValue> <Key>4</Key> <Value>16 GB</Value> </TestConfigurationParameterValue> <TestConfigurationParameterValue> <Key>5</Key> <Value>64 GB</Value> </TestConfigurationParameterValue> <TestConfigurationParameterValue> <Key>5</Key> <Value>70 GB</Value> </TestConfigurationParameterValue> </TestConfigurationParameterValues> </TestConfigurationParameter>
Apply server parameters to Agents
Next, you need to specify which Agent fits the criteria you have just set on the DEX Server.
To do so, follow the steps below:
- On the respective Agent machine, stop and start your Agent (see chapter “Work with Tosca Distribution Agents”).
- Open the Distributed Execution Monitor.
- Switch to the Agent View.
- Select the Machine tab.
- If you changed or added values of an existing parameter on the DEX Server, select the new value from the parameter drop-down menu.
- If you created an entirely new parameter, this parameter shows as a separate field. Select the required value from the parameter drop-down menu.

5.Click Save to save your changes.
Create custom configurations
So far, you have set criteria on the DEX Server and then defined which Agents fit these criteria.
Now you need to create a custom configuration in Tosca Commander. With this configuration, you define which combination of criteria you want to apply.
To create a configuration, follow the steps below:
- In Tosca Commander, check out the project root element.
- Get the parameter information from the DEX Server into Tosca Commander:
- Go to the Execution section.
- Right-click
Configurations and select Update configurations from Server from the context menu.
- If you use Tosca Server with an HTTPS binding and this is not a Tosca Server Repository workspace, sign in with your Tricentis User Administration credentials.

- Create a new configuration. Right-click
Configurations and select
Create New Configuration from the mini toolbar.
- In the Properties pane of the configuration, choose which criteria you want to use. To do so, select a value from the Value drop-down menu of the respective parameter(s). If a parameter value is blank, the parameter is not part of the configuration.

- Update the view and display all Agents in their proper configurations. To do so, right-click
Configurations and select Refresh Agents from the context menu.
- If you use Tosca Server with an HTTPS binding and this is not a Tosca Server Repository workspace, sign in with your Tricentis User Administration credentials.
Once you have created your custom configuration, you can assign it to your TestEvent. When you execute this TestEvent, the DEX Server forwards it to all Agents that match the criteria.