我有一个导入 .py 文件的 .robot 文件(我的 python 文件有一些模块作为导入语句) 当我尝试运行机器人文件时出现以下错误。 如何确保在 python 类文件中导入的模块也被导入?
[ ERROR ] Error in file 'C:\Users\Admin\Documents\PythonDemo\src\framework\tests\login_box.robot': Importing test library 'CreateCampaign.py' failed: ImportError: No module named framework.page_object_model.home_page
Traceback (most recent call last):
File "C:\Users\Admin\Documents\PythonDemo\src\framework\tests\CreateCampaign.py", line 1, in <module>
from framework.page_object_model.home_page import HomePage
PYTHONPATH:
C:\Users\Admin\Documents\PythonDemo\src\framework
C:\Windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
==============================================================================
Login Box :: Tests Login to BOX.com
==============================================================================
Log into Box using valid credentials | FAIL |
No keyword with name 'When I log into Box as my ${user} with ${userpass}' found.
.robot 文件
*** Settings ***
Library test_create_campaign.py
Documentation Tests Login to BOX.com
*** Variables ***
${user} abc@abc.com
${userpass} testing
*** Test Cases ***
Log into Box using valid credentials
When I log into Box as my ${user} with ${userpass}
.py文件
from framework.page_object_model.home_page import HomePage
from robot.api.deco import keyword
class CreateCampaign(LayarTestCase):
@keyword(name='I log into Box as my ${user} with ${userpass}')
def test_create_campaign(self, user, userpass):
print user
print userpass
请您参考如下方法:
我修改了 python 文件以使其工作。
.py文件
from framework.page_object_model.home_page import HomePage
from robot.api.deco import keyword
class test_create_campaign:
@keyword(name='I log into Box as my ${user} with ${userpass}')
def test_create_campaign(self, user, userpass):
print user
print userpass
- 更正了类定义的语法。
- 将类名重命名为与文件名相同。这很重要,因为 Robot 框架不会接受关键字,否则。您使用类(class)有什么原因吗?您可以在没有类的情况下定义一个方法(关键字),这同样有效。
