简体   繁体   English

如何基于git commit运行机器人框架测试?

[英]How do I run robot framework tests based on git commits?

We are developing a web application, in which we run robot framework regression tests against. 我们正在开发一个Web应用程序,在其中运行机器人框架回归测试。 I'd like to be able to run specific robot framework tests based on tags from git so I wouldn't have to run full regression every time. 我希望能够基于git的标签运行特定的机器人框架测试,因此我不必每次都运行完全回归。

Currently I use Jenkins to execute windows batch commands. 目前,我使用Jenkins执行Windows批处理命令。 My first job pulls down everything from the repository. 我的第一项工作是从存储库中提取所有内容。

cd /d C:\home\(Repository here)
git pull --summary

My second job runs the tests I specify, which is full regression currently. 我的第二项工作是运行指定的测试,当前是完全回归测试。

robot -P C:\home\(Repository root here) C:\home\(Path to test cases)

Is there a way to run specific tests based on certain tags in git? 有没有一种方法可以基于git中的某些标签运行特定的测试? For example running the "Login" tests because someone pushed a commit that had the [Login] tag in their commit message. 例如,运行“登录”测试是因为有人推送了在其提交消息中具有[Login]标签的提交。

Here's an example of a test suite. 这是一个测试套件的示例。

FileName = C:\\home(Repo)\\Regression\\Common\\Login\\LoginTestSuite.txt 文件名= C:\\ home(Repo)\\ Regression \\ Common \\ Login \\ LoginTestSuite.txt

*** Settings ***
Documentation    Login Test Suite
Suite Setup    Suite Setup
Library    SeleniumLibrary
Force Tags    LoginTests

*** Test Cases ***
User A Login Test
[Documentation]    This is documentation
[Tags]    Requirement A
(Test Steps Here)

Additional Information 附加信息

Robot Framework Version: 3.0.4 机械手框架版本:3.0.4

Application Front End: AngularJS 应用程序前端:AngularJS

Application Back End: C# 应用程序后端:C#

By the discussion in the comments, your goal is to run the Robot Framework tests having specific tags; 通过评论中的讨论,您的目标是运行具有特定标签的Robot Framework测试; these tags are coming from the git tags in the latest merge (let's call them "gtags" , to distinguish the two). 这些标记来自最新合并中的git标记(我们将它们称为“ gtags” ,以区别两者)。

One specifies the cases to be ran based on their tags through the --include command-line option ; 一个通过--include 命令行选项基于标签来指定要运行的案例; so if the gtags include "LoginTests", you'd run only them like this: 因此,如果gtags包含“ LoginTests”,则只能像这样运行它们:

robot -P C:\home\(Repository root here) --include logintests C:\home\(Path to test cases)

If the gtags are more than one, say they are (LoginTests, LogoutTests) , you could append more --include options: 如果gtags都不止一个,说他们是(LoginTests, LogoutTests)你可以追加更多--include选项:

--include logintests --include logouttests

Another option is to combine them in a single include argument - RF allows that by using the "AND", "OR" & "NOT" boolean operators inside the value: 另一种选择是将它们组合为单个include参数-RF允许通过在值内部使用“ AND”,“ OR”和“ NOT” 布尔运算符来实现:

--include logintestsORlogouttests

With "AND" only the cases having both tags will be picked, "OR" - the cases having either of the tags (sounds like your case), "NOT" negates the follow-up logic. 使用“与”时,将仅选择同时具有两个标签的案例,“或”-具有两个标签中的任何一个案例(听起来像您的案例),“不”则否定后续逻辑。 These three control strings are case-sensitive . 这三个控制字符串区分大小写

Naturally, for this scheme to work the gtags must be the same as the ones you've put in the test cases. 自然,为了使该方案起作用,gtag必须与您在测试用例中放置的gtag相同。 If not, you'll have to add some logic to map the gtags to the ones in the cases ("Login" -> "logintests"). 如果不是,则必须添加一些逻辑以将gtag映射到案例中的gtag(“登录”->“ logintests”)。

The tags in RF are normalized - converted to lowercase and all spaces are removed; RF中的标签已标准化-转换为小写并删除了所有空格; for RF "LoginTest" == "Login Test" == "login test" == "logintest" (though the usage of whitespace is discouraged - it's too easy to put two in the source, thus assigning two separate tags to the case) . 对于RF "LoginTest" == "Login Test" == "login test" == "logintest" (尽管不鼓励使用空格-太容易将两个放在源中,因此为案例分配了两个单独的标签) So whatever casing comes from the gtags, they'll be matched if after normalization the strings are the same. 因此,不管来自gtags的大小写形式是什么,如果标准化后的字符串相同,它们将被匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM