最近需要在linux下使用命令执行robotframework测试用例,顺便搭建下robotframework的headless环境

系统:centos7.5

软件版本:firefox38.5


搭建步骤:

1.安装处理图形化功能及firefox 

命令:yum install Xvfb  libXfont  lrzsz Xorg firefox


2.安装pip

命令:wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py;python get-pip.py


3.安装selenium、robotframework及robotframework-selenium2library

命令:pip install pyvirtualdisplay selenium robotframework robotframework-selenium2library


4.编写虚拟显示脚本DisplayLib.py

# -*- coding: utf-8 -*-

from pyvirtualdisplay import Display

display = Display(visible=0, size=(1024, 768))
##启动虚拟显示
def start():
    display.start()

##关闭虚拟显示
def stop():
    display.stop()



5.测试运行

*** Settings ***
Library           DisplayLib.py
Library           Selenium2Library    30
Library           OperatingSystem
Suite Setup       DisplayLib.start   #DisplayLib.start最好放在suite,如果放在test case中,会启动多个虚拟显示进程
Suite Teardown    DisplayLib.stop    #当测试执行完,关闭虚拟显示
*** Test Cases ***
testDisplay
    open_baidu

*** Keywords ***
open_baidu
    Open Browser    https://www.baidu.com/    ff
    [Teardown]    Close All Browsers



执行结果:



Logo

更多推荐