国际化

hrun4j默认输出是中文(I❤️Z),如果需要使用英语,可以参考下面的方案。

CLI模式

首先查看CLI运行帮助:java -jar hrun4j.jar run --help

[root@iZwz9d74mj3se04xsvz0crZ CLI_PROJECT]# java -jar hrun4j.jar run --help
Print run command information.
Usage: java -jar hrun4j.jar run [--bsh FILE] [--dot_env_path FILE] [--ext_name VAL] [--help] [--i18n VAL] [--pkg_name VAL] [--quiet] [--testcase_path <testcase_path>] [--testsuite_path <testsuite_path>]
--bsh FILE : Specify hrun4j.bsh as the project
path, not the current path.
--dot_env_path FILE : Specify the path to the.env file
--ext_name VAL : Specify the use case extension. (default:
yml)
--help : show help (default: true)
--i18n VAL : Internationalization support,support
us/cn. (default: CN)
--pkg_name VAL : Specify the project package name.
--quiet : suppress all output on stdout (default:
false)
--testcase_path <testcase_path> : list of testcase path to execute
--testsuite_path <testsuite_path> : Specify the TestSuite path

其中国际化支持可通过i18n设置,i18n全称为internationalization,如果想使用英文,运行时加入--i18n=us参数即可。

案例如下:java -jar hrun4j.jar run --i18n us --testcase_path testcases/get/getScene.yml

完整输出如下:

2021-06-27 21:30:04.863 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Run mode: CLI
2021-06-27 21:30:04.876 [main] INFO vip.lematech.hrun4j.helper.LogHelper - The workspace path:/home/data/workplace/CLI_PROJECT
[TestNG] Running:
hrun4j
2021-06-27 21:30:08.239 [main] INFO vip.lematech.hrun4j.helper.LogHelper - [========================================]@beforeSuite()
2021-06-27 21:30:08.248 [main] INFO vip.lematech.hrun4j.helper.LogHelper - [====================getScene====================]@START
2021-06-27 21:30:08.257 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Step
hrun4j.bsh文件所在路径即为项目工程路径
你好,欢迎使用hrun4j!
官网:http://www.lematech.vip
微信公众号:lematech
技术交流微信:wytest
2021-06-27 21:30:08.661 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Request Url:https://postman-echo.com/get?website=http://lematech.vip&project=hrun4j&author=lematech&page={page}
2021-06-27 21:30:08.662 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Request Method:GET
2021-06-27 21:30:12.199 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response StatusCode:200
2021-06-27 21:30:12.200 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response Body:{"args":{"website":"http://lematech.vip","author":"lematech","project":"hrun4j","page":"{page}"},"headers":{"x-amzn-trace-id":"Root=1-60d87d64-0b9cc79b189478636d70a3e8","x-forwarded-proto":"https","host":"postman-echo.com","x-forwarded-port":"443","accept-encoding":"gzip","user-agent":"okhttp/3.14.9"},"url":"https://postman-echo.com/get?website=http://lematech.vip&project=hrun4j&author=lematech&page={page}"}
2021-06-27 21:30:12.201 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response ContentLength:423
2021-06-27 21:30:12.201 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response Time:2.689
2021-06-27 21:30:12.201 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response Header:{"date":"Sun, 27 Jun 2021 13:30:12 GMT","content-length":"423","set-cookie":"sails.sid=s%3Ac30kDB8Vc4X2wjLhanbovdBwg5agfV0O.9ENw5sopbvJrf1slMR6OR9To0wrfqDFHvGhiLJN7XgA; Path=/; HttpOnly","vary":"Accept-Encoding","content-type":"application/json; charset=utf-8","etag":"W/\"1a7-ryYvxxb8SpvHilpiHdYlGmSCF/k\""}
2021-06-27 21:30:12.201 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response Cookie:
2021-06-27 21:30:12.344 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Assert Check Point:status_code,ExpectValue:200,ActualValue:200,CheckResult:Pass
2021-06-27 21:30:12.351 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Assert Check Point:body.args.website,ExpectValue:http://lematech.vip,ActualValue:http://lematech.vip,CheckResult:Pass
2021-06-27 21:30:12.356 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Assert Check Point:${author},ExpectValue:lematech,ActualValue:lematech,CheckResult:Pass
2021-06-27 21:30:12.358 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Assert Check Point:^website":"(.*?)"$,ExpectValue:website":"http://lematech.vip",ActualValue:website":"http://lematech.vip",CheckResult:Pass
2021-06-27 21:30:12.372 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Step
2021-06-27 21:30:12.487 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Request Url:https://postman-echo.com/get?website=http://lematech.vip&project=hrun4j&author=http://lematech.vip
2021-06-27 21:30:12.487 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Request Method:GET
2021-06-27 21:30:12.726 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response StatusCode:200
2021-06-27 21:30:12.727 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response Body:{"args":{"website":"http://lematech.vip","author":"http://lematech.vip","project":"hrun4j"},"headers":{"x-amzn-trace-id":"Root=1-60d87d64-7015c2a1677f4e0c2aec0130","x-forwarded-proto":"https","host":"postman-echo.com","x-forwarded-port":"443","accept-encoding":"gzip","user-agent":"okhttp/3.14.9"},"url":"https://postman-echo.com/get?website=http://lematech.vip&project=hrun4j&author=http://lematech.vip"}
2021-06-27 21:30:12.727 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response ContentLength:417
2021-06-27 21:30:12.727 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response Time:0.238
2021-06-27 21:30:12.727 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response Header:{"date":"Sun, 27 Jun 2021 13:30:12 GMT","content-length":"417","set-cookie":"sails.sid=s%3A0-vmPuEl_VM_BfJbhK7bMZdBz4W9jV9e.xoWYlmhwuRqB%2FEmy7sLr30Fg7f9skZ8Q5mBOYlQmEZA; Path=/; HttpOnly","vary":"Accept-Encoding","content-type":"application/json; charset=utf-8","etag":"W/\"1a1-Wx8uIB/d86laeKz5ykC+h8/qhJU\""}
2021-06-27 21:30:12.728 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Response Cookie:
2021-06-27 21:30:12.735 [main] INFO vip.lematech.hrun4j.helper.LogHelper - Assert Check Point:status_code,ExpectValue:200,ActualValue:200,CheckResult:Pass
2021-06-27 21:30:12.736 [main] INFO vip.lematech.hrun4j.helper.LogHelper - [====================getScene====================]@END
2021-06-27 21:30:12.745 [main] INFO vip.lematech.hrun4j.helper.LogHelper - [========================================]@afterSuite()
===============================================
hrun4j
Total tests run: 1, Failures: 0, Skips: 0
===============================================

全英文输出,体验棒棒哒💯。

POM模式

POM模式设置中英文非常简单,在初始化运行配置时,通过代码设置i18n方法参数即可,代码如下:

public class Hrun4j extends TestBase {
@Override
@BeforeSuite
public void beforeSuite() {
LogHelper.info(" Add function to static code block !");
/**
* Test case file suffix
*/
RunnerConfig.getInstance().setI18n(Constant.I18N_US);
RunnerConfig.getInstance().setTestCaseExtName(Constant.SUPPORT_TEST_CASE_FILE_EXT_YML_NAME);
}
}

核心设置代码:RunnerConfig.getInstance().setI18n(Constant.I18N_US);

目前支持以下语言:

语言文件名备注
英文message_en_US.properties
中文message_zh_CN.properties默认

国际化支持借助ResourceBundle工具类实现,国际化资源文件存储在hrun-core工程资源文件locales目录下