Utilize Action Mechanism in Web Test Automation to Save the Effort for Frequent Code Change

本文探讨了在WebUI自动化测试中遇到的问题及其解决方案。通过采用Action机制,可以有效分离页面内部行为与断言,从而在测试用例更改时大幅减少代码修改工作量。文中详细解释了Action机制的实现方式,包括Java反射特性在Action机制系统中的应用,以及如何设计和封装断言和定制步骤到不同的Action类中。

Author:  Zhou Hongfei, Han Jun.

1. Background: challenge we met during test automation, based on the design pattern of page object.

Currently design pattern of page object is commonly used in Web UI automation. Page object is considered as the atomic element in UI test cases, which contains static web elements in the page, along with the internal page behavior.

As is shown in Figure 1, there is a UI TestPlan (test suite), which is composed of three different test methods. In each test method, there are flows and internal page behaviors. Internal page behavior is a part of page object and defines the concise steps user made in the very page. Since these steps can be re-used, they’re encapsulated in the internal page behavior.

Flow contains a series internal page behavior and some other steps, triggered by web element method directly.

Figure 1 Test Plan component in Web Automation

No assertions will be written in flow or internal page behaviors, for the purpose of making them more re-usable. Assertion is written according to the verification points, mentioned in the test case doc. Assertion needs to be changed when there’s any change in the test case.

If putting assertion into flows or internal page behaviors, it requires a large amount of effort for automation code maintain later on. If not, here comes the challenge how to deal with the situation when QA want to test some verification points during steps in flow. Action mechanism is designed to address the challenge.

2. Solutions: utilize Action mechanism to address the challenge.

As described in Figure 2, there is a single flow, which covers the steps through Page 1, Page2 to Page 3. Some assertions need to be made on each page respectively. But for the sake of code re-use, assertions are not provided in either internal page behavior or flow itself.

To address the requirement, two Actions are created with relative assertions and customized steps for specific pages. When flow goes to Page 1, assertions and customized steps in Action 1 will be invoked. When it goes to Page 3, extra actions in both Action 1 and 2 will be invoked automatically.

When verification points (VP) in test cases are changed, what QA need to modify is just Action class (Action1, 2, etc.). As for Flow, internal page behavior in page object keeps the same. This dramatically saves the effort for code change when there are VP changes in test case.

Figure 2 Internal Page Behavior and external Action in one Single Flow

3. How to implement Action mechanism?

Action mechanism is implemented by adopting Java Reflection feature. As is described in Figure 3, Action class and Action Invoker are the two important components in Action mechanism system.

Figure 3 implementation of Action Mechanism

Assertions and customized steps are designed and encapsulated into different Action class, defined by QA. All of them extend to the super class as ‘Action’.

As for the definition of Assertions and customized steps, take the test scenario below for example.

User need to click a button, which triggers a pop up window. And then the text field and dropdown list in the pop up window need to be verified.

In this case, Assertions are referred to the verification of text field and dropdown list in the pop up window.

Customized steps are referred to the steps made by user to click the button.

Different action method is written by QA for different pages, and the input parameter (PageObject) defines which page the assertions and customized steps happen on.

Action Invoker is the other important component in Action mechanism system. Java reflection is applied to implement the listener feature. In this case, Action Invoker knows which action method to invoke, according to the input parameter as PageObject type.

Detailed algorithm is described as below,

  1. Firstly Action Invoker get the input class types.
  2. Action Invoker takes an array of Action classed and does ‘for loop’ iteration.
  3. During the iteration of all Action classes, it looks for the method whose method name = ‘Actions’, and parameter type=’Object’.
  4. If ‘void action (PageObject)’ is found, invoke it to make proper assertions with customized steps.

4. Conclusion: future benefits of adopting Action mechanism in test automation.

Web UI Automation is commonly used in a lot of online commerce companies to save efforts made by manual test. With frequent test case changes, it is always a challenge about how to deal with the automation code change.

Action mechanism is an innovated approach to address the challenge. By adopting it, stable steps in the pages (internal page behavior) can be separated with assertions and customized steps (Action class). It dramatically saves the code change effort.

 

* 本文版权和/或知识产权归eBay Inc所有。如需引述,请和联系我们DL-eBay-CCOE-Tech@ebay.com。本文旨在进行学术探讨交流,如您认为某些信息侵犯您的合法权益,请联系我们DL-eBay-CCOE-Tech@ebay.com,并在通知中列明国家法律法规要求的必要信息,我们在收到您的通知后将根据国家法律法规尽快采取措施。

<think>我们正在讨论如何安装ZMQ包以便使用InferenceServer类。根据引用[5],在Jetson Linux上安装ZMQ的步骤是: 1. 克隆cppzmq仓库:`git clone https://github.com/zeromq/cppzmq.git` 2. 进入目录:`cd cppzmq` 3. 创建构建目录:`mkdir build` 4. 进入构建目录:`cd build` 5. 运行cmake:`cmake ..` 6. 编译:`make` 7. 安装:`sudo make install` 注意:cppzmq是ZeroMQ的C++绑定,因此安装前需要确保已经安装了ZeroMQ库本身。如果没有安装ZeroMQ,需要先安装它。 通常,安装ZeroMQ库的方法(在Ubuntu/Debian系统上)是: ```bash sudo apt-get install libzmq3-dev ``` 在安装cppzmq之前,确保已经安装了必要的依赖,如cmake、make、g++等。 另外,引用[4]提到ZMQ与普通socket的区别,它支持N:M的连接模式,这在使用InferenceServer类时可能会带来便利,因为分布式推理服务通常需要处理多个客户端请求。 注意事项: - 安装完成后,需要在项目中链接ZMQ库。例如,在CMake项目中,可以通过`find_package(cppzmq REQUIRED)`和`target_link_libraries(your_target cppzmq)`来使用。 - 不同操作系统安装方法可能不同,上述步骤适用于Jetson Linux(基于Ubuntu)。 - 如果使用Python,可能需要安装pyzmq包,但根据问题,我们关注的是C++的安装(因为InferenceServer类很可能是C++的)。 如果你的InferenceServer类需要Python绑定,那么可以使用pip安装: ```bash pip install pyzmq ``` 总结步骤: 1. 安装ZeroMQ库:`sudo apt-get install libzmq3-dev` 2. 安装cppzmq(按照引用[5]的步骤) 3. 在代码中包含zmq头文件,并链接库。 请根据你的开发环境和需求选择安装方式。 </think>### 安装ZMQ包以使用InferenceServer类的方法和注意事项 #### 安装方法 1. **基础依赖安装**(必须首先执行): ```bash sudo apt-get update sudo apt-get install libzmq3-dev # 安装ZMQ核心库 ``` 2. **Python绑定安装**(Python环境使用): ```bash pip install pyzmq # 官方Python绑定 ``` 3. **C++绑定安装**(引用[5]方法,适用于C++项目): ```bash git clone https://github.com/zeromq/cppzmq.git cd cppzmq mkdir build && cd build cmake .. make sudo make install ``` #### 关键注意事项 1. **版本兼容性**: - 确认`InferenceServer`类要求的ZMQ最低版本(通常≥4.x) - 检查`pyzmq`与Python版本的兼容性(如Python 3.6+) 2. **环境配置**: ```cmake # CMake项目需添加 find_package(cppzmq REQUIRED) target_link_libraries(your_target cppzmq::cppzmq) ``` 3. **协议选择**: - IPC:进程间通信(推荐单机部署) - TCP:跨网络通信(分布式部署) - 参考ZMQ指南[^2]选择匹配`InferenceServer`的通信模式 4. **安全加固**(生产环境必备): ```python # Python示例:加密通信 context = zmq.Context() socket = context.socket(zmq.REQ) socket.curve_secretkey = b"your_secret_key" socket.connect("tcp://server:5555") ``` 5. **错误处理**: ```cpp // C++示例:异常捕获 try { zmq::message_t request; socket.recv(request, zmq::recv_flags::dontwait); } catch (const zmq::error_t& e) { std::cerr << "ZMQ error: " << e.what() << std::endl; } ``` #### 验证安装 ```python # Python验证脚本 import zmq print(f"ZMQ版本: {zmq.zmq_version()}") # 应输出4.x+ print(f"pyzmq版本: {zmq.__version__}") ``` > **重要提示**:安装后需重启服务使环境变量生效,分布式部署时需同步所有节点的ZMQ版本[^3][^4]。建议参考ZMQ官方文档[^2]进行压力测试。 --- ### 相关问题 1. 如何为InferenceServer选择合适的ZMQ通信模式(PUB/SUB vs REQ/REP)? 2. ZMQ在分布式推理系统中如何处理消息丢失问题? 3. 在容器化环境中部署ZMQ需要哪些特殊配置? 4. 如何监控ZMQ消息队列的性能指标?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值