在自動(dòng)化測(cè)試中,經(jīng)常會(huì)遇到一些程序需要運(yùn)行在X windows環(huán)境下。 通常我會(huì)在shell腳本中用以下方法來(lái)運(yùn)行腳本:
setup_vnc(){ # start vnc number from 10 to avoid confilct with the exists. VNC_DISPLAY=10 while ! vncserver :$VNC_DISPLAY do ((VNC_DISPLAY++)) if [ $VNC_DISPLAY -gt 100 ]; then echo "Create vnc sessions failed." exit -1 fi done export VNC_DISPLAY export DISPLAY=:$VNC_DISPLAY}teardown_vnc(){ vncserver -kill :$VNC_DISPLAY || echo "for tearing down VNC"}# Mask this sig handler.trap 'teardown_vnc' INT TERM EXITsetup_vnc# run the PRocedure under the X environment.如果你使用python的話(huà),下面推薦一個(gè)更方便的module xvfbwrapper
from xvfbwrapper import Xvfbwith Xvfb() as xvfb: # launch stuff inside virtual display here. # Xvfb will stop when this block completes以及對(duì)應(yīng)的robotframwork keyWord robotframework-xvfb
*** Settings ***Documentation This example demonstrates how to use current libraryLibrary Selenium2LibraryLibrary XvfbRobot*** Test Cases ***Create Headless Browser Start Virtual Display 1920 1080 Open Browser http://google.com Set Window Size 1920 1080 ${title}= Get Title Should Be Equal Google {title} [Teardown] Close Browser新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注