1. 程式人生 > >Robot Framework - 建立本地測試環境

Robot Framework - 建立本地測試環境

1.2 extern 功能 file crypto edi 源碼 com create

註意:本文內容是以“在Window7系統中安裝本地RobotFrmamework自動化測試環境”為例。

Robot Framework簡介

HomePage:http://robotframework.org/ Robot Framework User Guide:http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html Robot Framework documentation:http://robotframework.org/robotframework/
  • Robot Framework 是一款基於 Python 的功能自動化測試框架;
  • 具備良好的可擴展性,支持關鍵字驅動,可以同時測試多種類型的客戶端或者接口,可以進行分布式測試執行;
  • 可用於驗收測試和驗收測試驅動開發(ATDD);

安裝RIDE

安裝順序:Python ---> setuptools & pip ---> Robot Framewok ---> wxPython(v2.8.12.1) ---> RIDE

1-安裝Python並設置環境變量

>python --version
Python 2.7.12

>
>pip list
pip (8.1.1)
setuptools (20.10.1)

環境變量 PYTHONPATH

C:\Python27\;C:\Python27\Lib\site-packages;C:\Python27\Scripts

建議執行“python -m pip install --upgrade pip ”升級pip。

2-安裝robotframework

根據需要搜索並下載對應源碼的壓縮包(.tar.gz或.zip),解壓後,切換到對應目錄,運行:python setup.py install即可安裝.

>pybot --version
Robot Framework 3.0 (Python 2.7.12 on win32)

3-安裝wxPython

wxPython2.8-win64-unicode-2.8.12.1-py27.exe 4-安裝robotframework-ride
>ride.py  # 啟動RIDE

5-確認已完成所有安裝

>pip list
pip (8.1.2)
robotframework (3.0)
robotframework-ride (1.5.2.1)
setuptools (20.10.1)
>

安裝SSH訪問庫

安裝順序:

  1. PyCrypto
  2. ecdsa
  3. paramiko
  4. robotframework-sshlibrary

確認所有安裝包

>pip list
ecdsa (0.13)
paramiko (1.14.0)
pip (8.1.2)
pycrypto (2.6)
robotframework (3.0)
robotframework-ride (1.5.2.1)
robotframework-sshlibrary (2.1.2)
setuptools (20.10.1)
>

驗證

>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import SSHLibrary
>>>
>>> ssh = SSHLibrary.SSHLibrary()
>>> ssh.open_connection("10.92.111.76", "22")
1
>>> ssh.login("root", "arthur")
u‘Last login: Wed Aug 17 12:32:25 2016 from 10.141.98.107\r\r\n[root@clab395node01 ~]# ‘
>>> print ssh.execute_command("whoami")
root
>>>

安裝Oracle

1 - Oracle Instant Client

Oracle Instant Client provides Oracle access and allows you to run your applications without installing the standard Oracle client.

Since Oracle Instant Client is composed of basic instant client and the sdk instant client , thus two of them should be installed.

Unzip the packages(both instantclient-basic and instantclient-sdk) into a single directory such as "instantclient", in this instruction, the Oracle Instant Client‘s folder structure looks like:

技術分享圖片

To set environment variable, open environment variables setting,

new a system variable named ORACLE_HOME, set its value with the Oracle Instant Client installation path and append ORACLE_HOME to path. See:

C:\Users\guowli>set ORACLE_HOME
ORACLE_HOME=C:\instantclient

C:\Users\guowli>
C:\Users\guowli>set path
Path=C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\RSA SecurID Token Common;C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\WebEx\Productivity Tools;C:Program Files (x86)\Sennheiser\SoftphoneSDK\;C:\Program Files (x86)\SafeCom\SafeComPrintClient;C:\Program Files\Tortoise
SVN\bin;C:\Python27;C:\Python27\Scripts;C:\Python27\Lib\site-packages;C:\Program Files\Java\jdk1.8.0_101\bin;C:\Program
Files\Java\jdk1.8.0_101\jre\bin;C:\instantclient
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

C:\Users\guowli>

2 - cx_Oracle

cx_Oracle is a Python extension module that allows access to Oracle databases and conforms to the Python database API specification.

3 - SQLAlchemy

SQLAlchemy is Python library that allows database connections directly from Python code, helps in handling results and also allows using Python‘s/SQLAlchemys‘s own exception handling. It could be compared in JAVA‘s jdbc library.

確認所有安裝包:

>pip list
cx-Oracle (5.1.2)
ecdsa (0.13)
paramiko (1.14.0)
pip (8.1.2)
pycrypto (2.6)
robotframework (3.0)
robotframework-ride (1.5.2.1)
robotframework-sshlibrary (2.1.2)
setuptools (20.10.1)
sqlalchemy (0.5.6)
>

驗證

>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import sqlalchemy
>>>
>>> host="10.92.111.76"
>>> port="1521"
>>> database="oss"
>>>
>>> connect_str = "oracle://omc:omc@" + str(host) + ":" + str(port) + "/" + str(database)
>>> engine = sqlalchemy.create_engine(connect_str, echo=False)
>>> c = engine.connect()
>>>
>>> result = c.execute("select owner,object_type from all_objects where object_name=‘FM_ALARM‘").fetchall()
>>> 
>>> print result
[(‘PUBLIC‘, ‘SYNONYM‘), (‘FM‘, ‘VIEW‘)]
>>>

安裝Selenium庫

SeleniumLibrary is a Robot Framework test library that uses the popular Selenium web testing tool internally.

It provides a powerful combination of simple test data syntax and support for different browsers .

Web testing TA cases requires SeleniumLibrary.

安裝順序:
  1. decorator
  2. Selenium
  3. robotframework-selenium2library
  4. IEDriverServer - (optional, for IE explorer)

確認所有安裝包:

>pip list
cx-Oracle (5.1.2)
decorator (4.0.10)
ecdsa (0.13)
paramiko (1.14.0)
pip (8.1.2)
pycrypto (2.6)
robotframework (3.0)
robotframework-ride (1.5.2.1)
robotframework-selenium2library (1.7.4)
robotframework-sshlibrary (2.1.2)
selenium (2.53.2)
setuptools (20.10.1)
sqlalchemy (0.5.6)
>

Robot Framework - 建立本地測試環境