使用pabot并发执行robotframework测试

原文地址:https://github.com/mkorpela/pabot

Pabot

A parallel executor for Robot Framework tests. With Pabot you can split one execution into multiple and save test execution time.

My goal in creating this tool is to help you guys with big test sets. I've worked with a number of teams around the world that were doing test execution time optimisation before I created this tool. I saw similarities in how Robot Framework testing systems have been built and came up with a quite good solution for the basic parallelisation problem. I hope this tool brings you joy and speeds up your test execution! If you are interested in professional support, please contact me through email firstname.lastname(at)gmail.com! - Mikko Korpela ( those are my firstname and lastname :D )

Installation:

From PyPi:

 pip install -U robotframework-pabot

OR clone this repository and run:

 setup.py  install

Things you should know

  • Pabot will split test execution from suite files and not from individual test level.
  • In general case you can't count on tests that haven't desinged to be executed parallely to work out of the box when executing parallely. For example if the tests manipulate or use the same data, you might get yourself in trouble (one test suite logs in to the system while another logs the same session out etc.). PabotLib can help you solve these problems of concurrency. Also see TRICKS for helpful tips.

Command-line options

Supports all Robot Framework command line options and also following options (these must be before normal RF options):

--verbose
more output

--command [ACTUAL COMMANDS TO START ROBOT EXECUTOR] --end-command
RF script for situations where pybot is not used directly

--processes [NUMBER OF PROCESSES]
How many parallel executors to use (default max of 2 and cpu count)

--pabotlib
Start PabotLib remote server. This enables locking and resource distribution between parallel test executions.

--pabotlibhost [HOSTNAME] Host name of the PabotLib remote server (default is 127.0.0.1) If used with --pabotlib option, will change the host listen address of the created remote server (see https://github.com/robotframework/PythonRemoteServer) If used without the --pabotlib option, will connect to already running instance of the PabotLib remote server in the given host. The remote server can be started with: python PabotLib.py python PabotLib.py resource.txt 192.168.1.123 8271 This enables sharing a resource with multiple Robot Framework instances

--pabotlibport [PORT] Port number of the PabotLib remote server (default is 8270) See --pabotlibhost for more information

--resourcefile [FILEPATH]
Indicator for a file that can contain shared variables for distributing resources. This needs to be used together with pabotlib option. Resource file syntax is same as Windows ini files. Where a section is a shared set of variables.

Example usages:

 pabot test_directory
 pabot --exclude FOO directory_to_tests
 pabot --command java -jar robotframework.jar --end-command --include SMOKE tests
 pabot --processes 10 tests
 pabot --pabotlibhost 192.168.1.123 --pabotlibport 8271 --processes 10 tests
 pabot --pabotlib --pabotlibhost 192.168.1.111 --pabotlibport 8272 --processes 10 tests

PabotLib

pabot.PabotLib provides keywords that will help communication and data sharing between the executor processes. These can be helpful when you must ensure that only one of the processes uses some piece of data or operates on some part of the system under test at a time.

Docs are located at http://htmlpreview.github.io/?https://github.com/mkorpela/pabot/blob/master/PabotLib.html

PabotLib example:

test.robot

  *** Settings ***
  Library    pabot.PabotLib

  *** Test Case ***
  Testing PabotLib
    Acquire Lock   MyLock
    Log   This part is critical section
    Release Lock   MyLock
    ${valuesetname}=    Acquire Value Set
    ${host}=   Get Value From Set   host
    ${username}=     Get Value From Set   username
    ${password}=     Get Value From Set   password
    Log   Do something with the values (for example access host with username and password)
    Release Value Set
    Log   After value set release others can obtain the variable values

valueset.dat

  [Server1]
  HOST=123.123.123.123
  USERNAME=user1
  PASSWORD=password1

  [Server2]
  HOST=121.121.121.121
  USERNAME=user2
  PASSWORD=password2

pabot call

  pabot --pabotlib --resourcefile valueset.dat test.robot
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使⽤ 使⽤pabot并⾏执⾏ 并⾏执⾏robotframework⽤例 ⽤例 主要观点:使⽤pabot并⾏运⾏robotframework,可以解决:robotframework执⾏案例时间长的问题 解决执⾏案例时间长的⽅案: 解决执⾏案例时间长的⽅案: ⽬的: ⽬的: 缩短案例的运⾏时间 两种⽅法: 两种⽅法:      1. 将⼤的项⽬分成⼏个⼦模块,测试案例也是分为⼏个⼦模块,这样进⾏分布式测试 2. 在⼀台机⼦上开启多个进程进⾏测试 解决⽅案: 解决⽅案: 使⽤ 使⽤pabot类库: 类库: pabot 通过开启多个进程以Suite为单位并⾏运⾏robotframework测试案例,并且对于进程之间资源共享的问题也有锁机制。 安装: 安装: pip install robotframework-pabot pabot命令⾏参数: 命令⾏参数: --processes [NUMBER OF PROCESSES] ——> 并⾏的线程数(最⼤是机器CPU的数⽬) --pabotlib启动PabotLib远程服务器。这⽀持在并⾏测试执⾏之间进⾏锁定和资源分配。 --pabotlibhost [HOSTNAME] ——> 远程服务器的主机名(默认是127.0.0.1) --pabotlibport [PORT] ——> PabotLib远程服务器端⼝号(默认为8270) --resourcefile [FILEPATH]可以包含⽤于分配资源的共享变量的⽂件的指⽰符。这需要与pabotlib选项⼀起使⽤。 实际测试: 实际测试: 这⾥新建⼀个pabotdemo⽂件夹,下⾯包含有3个测试⽤例⽂件(即:3个Suite),每个⽂件中包含有3个Test(即:3个测试⽤ 例)。每个测试⽤例都是执⾏相同的步骤sleep 10s。如果在RF中运⾏9个Test,每个Test耗时10s,那就需要90s。 下图为在 下图为在RF中运⾏的测试结果: 中运⾏的测试结果: 使⽤ 使⽤pabot开启 开启2个进程: 个进程:pabot --processes 2 PabotDemo,耗时: ,耗时:63s 使⽤ 使⽤pabot开启 开启3个进程: 个进程:pabot --processes 2 PabotDemo,耗时: ,耗时:32s 上⾯简单测试,没有进程间的资源共享,所以没加锁,具体使⽤可以参考: 注意:Pabot并⾏运⾏是以Suite为单位运⾏的,因为项⽬的案例结构有的Suite中案例个数100多个,有的只有⼏个,这样就导致案 例少的Suite⼏个可能已经运⾏完了,案例多的Suite可能才刚开始,并不能发挥并⾏运⾏的最⼤效果,分布不均,所以需要对案例 进⾏调整,将案例多的Suite进⾏拆分,这样也能开启多个进程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值