第三方整合

Jenkins是一种非常流行的工具,用于编排和管理构建和发布管道。测试自动化正在发展成为Jenkins这样的工具,并且Leaptest周围的社区已经 建立 一个本地的Jenkins插件,这使得在Leaptest中触发测试用例运行非常简单。

该视频包括以下内容:

  • Jenkins和Leaptest之间的集成概述(点击 缩图 下载概述幻灯片)。
     飞跃测试 Jenkins集成概述
  • 正在下载 飞跃测试  GitHub存储库中的本地Jenkins插件(链接: //github.com/Customatics/)
  • 安装 飞跃测试 Jenkins服务器上的插件
  • 创建一个项目和一个构建定义,包括 飞跃测试 插件作为构建步骤
  • 配置 飞跃测试 构建步骤,并简要介绍Leaptest中的时间表
  • 触发测试用例以继续运行 云托管 Jenkins中的机器。
  • 在詹金斯检查测试结果。

飞跃 上市 REST API 使DevOps,IT运营和开发人员可以很轻松地将LEAPWORK与任何第三方系统集成。


以下是Windows PowerShell脚本运行预定义的LEAPWORK计划,轮询结果直到可用为止,然后循环浏览所有失败的情况,并显示如何获取其中的相关数据结构。然后可以将数据推送到任何第三方系统,例如TFS,JIRA或任何其他应用程序生命周期管理(ALM)系统。

请注意,该脚本不包含任何错误处理或日志记录机制。它仅旨在演示将LEAPWORK与第三方系统集成的核心功能。

下载PowerShell脚本示例。

	
		# LEAPWORK REST API example: Run a schedule and iterate through the results.
#
# Author: Claus Topholt.

# Step 1: Get the id of the schedule called "My Test Schedule".
$schedule = "My Test Schedule"
$runScheduleId = "";
echo "Getting id for schedule '$scheduleTitle'."  
$headers = @{}
$headers.Add("AccessKey","APIAccessKey")
$runSchedules = Invoke-WebRequest -ContentType "application/json" -Headers $headers "http://localhost:9001/api/v3/schedules" | ConvertFrom-Json
foreach($runScheduleItem in $runSchedules)
{
    if ($runScheduleItem.title -eq $schedule) { $runScheduleId = $runScheduleItem.id }
}
if ($runScheduleId -eq "") { throw "Could not find schedule '$schedule'." }

# Step 2: Run the schedule now.
echo "Running the schedule."
Start-Sleep 1   
$runNow = Invoke-WebRequest -Method PUT -ContentType "application/json" -Headers $headers "http://localhost:9001/api/v3/schedules/$runScheduleId/runNow"
if ($runNow.StatusCode -ne 200) { throw "Could not run schedule." }
$runNowResponse=$runNow.Content | ConvertFrom-Json
$runId=$runNowResponse.RunId

# Step 3: Get the result, keep polling every 5 seconds until a new result is returned.
do
{
    Start-Sleep -Seconds 5
    Write-Host "Polling for run results."
    $runResult = Invoke-WebRequest -ContentType "application/json" -Headers $headers "http://localhost:9001/api/v3/run/$runId" | ConvertFrom-Json
} 
while ($runResult.Status -ne 'Finished')
Write-Host "Results received."

# Step 4: If there are any failed cases, iterate through them.
if ($runResult.Failed -gt 0)
{
    Write-Host "Found $($runResult.Failed) failed case(s)."    
    $runId=$runResult.RunId
    $runItemIds = Invoke-WebRequest -ContentType "application/json" -Headers $headers http://localhost:9001/api/v3/run/$runId/runItemIds | ConvertFrom-Json 

    $rootPath =$runResult.RunFolderPath
    foreach ($runItemId in $runItemIds.RunItemIds)
    {   
   
    $runItems = Invoke-WebRequest -ContentType "application/json" -Headers $headers http://localhost:9001/api/v3/runItems/$runItemId | ConvertFrom-Json 

        if($runItems.FlowInfo.Status -eq 'Failed')
        {
            # Here is a good place to do integration to eg. TFS, JIRA or any other Application Lifecycle Management system.

            # Output the log messages as an example.
            echo "Case '$($runItems.FlowInfo.FlowTitle)' failed. Here are the log messages:"                
           
            $keyFrames = Invoke-WebRequest -ContentType "application/json" -Headers $headers http://localhost:9001/api/v3/runItems/$runItemId/keyframes/1 | ConvertFrom-Json 

            $bugDescription = "Log from LEAPWORK:$newline $newline"
            foreach ($keyframe in $keyFrames)
            {
                if ($keyframe.Level -ge 6)
                {
                    $keyframeTimestamp = get-date($keyframe.Timestamp.LocalDateTime) -Format "dd-MM-yyyy HH:mm:ss"
                    echo "$keyframeTimestamp - $($keyframe.LogMessage)"
                }
            }            
        }
    }
}
else
{
    Write-Host "No failed cases found."
}
	

该脚本包括四个步骤:

Step 1:获取时间表的ID。这是通过调用REST API端点来完成的 获取所有时间表.

Step 2:立即运行计划。这是通过调用 立即运行时间表,这将指示Controller将时间表排入队列,以便尽快执行。

Step 3:每5秒钟轮询一次结果,直到返回新结果。这是通过调用 通过ID运行,它将返回“完成”或“正在执行”状态,直到有新结果可用为止。

Step 4:如果有任何失败的案例,请遍历失败的案例并使用其中的数据来了解出了什么问题。例如,如果集成旨在在错误跟踪系统(例如JIRA)中自动创建新的错误,这将非常有用。

运行脚本将产生如下结果:

S C:\LEAPWORK-Scripts> run-schedule.ps1
Getting id for schedule 'My Test Schedule'.
Running the schedule.
Polling for run results.
Polling for run results.
Polling for run results.
Results received.
Found 2 failed case(s).
Case 'Simple waiter with random outcome' failed. Here are the log messages:
29-08-2016 11:15:15 - Connecting to local
29-08-2016 11:15:15 - Connected to local
29-08-2016 11:15:15 - Running
29-08-2016 11:15:20 - Waited for 5 second(s).
29-08-2016 11:15:20 - 46 generated by number generator.
29-08-2016 11:15:20 - '46' is not greater than or equal to '50' (compared as Number).
29-08-2016 11:15:21 - Case is failed.
Case 'Always fails' failed. Here are the log messages:
29-08-2016 11:15:24 - Connecting to local
29-08-2016 11:15:24 - Connected to local
29-08-2016 11:15:24 - Running
29-08-2016 11:15:26 - Case is failed.

您可以通过以下URL探索上述端点: http:// localhost:9001 / help / index 如果您在自己的计算机上安装了Controller。

浏览LEAPWORK REST API的完整文档。

如有任何疑问,请联系优先支持 prioritysupport@leapwork.com.