2015-07-28 67 views
0

我想創建與下面的代碼蟒蛇網絡驅動程序實例創建一個Web驅動程序實例:不能在python

from robot.libraries.BuiltIn import BuiltIn 
import Selenium2Library 
from Selenium2Library import Selenium2Library 

def get_webdriver_instance(): 
    s2l = BuiltIn().get_library_instance("Selenium2Library") 
    return s2l._current_browser() 

,但在內置的()get_library_instance(「Selenium2Library」)我我收到以下錯誤:

Traceback (most recent call last): 
     File "<stdin>", line 1, in <module> 
     File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 2922, in get_library_instance 
     return self._namespace.get_library_instance(name) 
     File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 70, in _namespace 
     return self._context.namespace 
     File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 65, in _context 
     raise RobotNotRunningError('Cannot access execution context') 
robot.libraries.BuiltIn.RobotNotRunningError: Cannot access execution context 

可能有人請幫助我解決這個錯誤

回答

0

_current_browser只返回當前瀏覽器

如果你想使用Selenium2Library在Python比你可以做下

from Selenium2Library import Selenium2Library 
sl = Selenium2Library() 
sl.open_browser('firefox') 
1

錯誤消息告訴你,除非你實際運行測試,你不能使用內置的庫的方法(通過pybot,jybot等)。您不能在獨立的Python腳本中調用BuiltIn().get_library_instance('Selenium2Library')

+0

我正在使用pybot命令運行測試,但仍然收到此錯誤 – Madhuri