--pythonpath 选项不适用于 Robot Framework
--pythonpath option not working with Robot Framework
我正在为 Robot Framework 编写自定义页面对象库,如下所示:robotframework-pageobjectlibrary
我的页面自定义关键字(页面对象)在一个单独的文件夹中,当我 运行 我的 Robot Framework
测试时,我使用 --pythonpath
选项给出它们的路径,如下所示:robot --pythonpath ../resources/pageobjects lib-test/test.robot
。
我的目录结构如下所示:
CustomPageObjectLibrary
|--__init__.py
|--keywords.py
|--locatormap.py
|--pageobject.py
Resources
|--pageobjects
|__CountryPage.py
Tests
|--lib-test
|__test.robot
CustomPageObjectLibrary 的内容目前与链接存储库中的内容相同,除了我使用 AppiumLibrary
而不是 SeleniumLibrary
。
CountryPage.py
from CustomPageObjectLibrary import PageObject
class CountryPage(PageObject):
PAGE_TITLE = "Country"
_locators = {
'germany': 'countryGermany',
}
# def __init__(self):
# super(PageObject, self).__init__()
def open_app(self):
self.appiumlib.open_application('http://localhost:4723/wd/hub', platformName='Android', deviceName='...', appPackage='...', appActivity='.MainActivity', uiautomator2ServerInstallTimeout=50000)
def choose_country(self, country):
# Convert country to lovercase
country = str(country).lower()
self.appiumlib.wait_until_element_is_visible(定位器=self.locator.germany)
self.appiumlib.click_element(定位器=self.locator.germany)
我的测试:
*** Settings ***
Variables ../../resources/pageobjects/config.py
Library CustomPageObjectLibrary
Library AppiumLibrary
*** Test Cases ***
Navigate To Not Connected Screen
Open App
Choose country germany
我 运行 使用以下命令:robot --pythonpath ../resources/pageobjects lib-test/test.robot
我得到的错误:No keyword with name 'Open App' found.
这可能是什么问题?
要使页面对象库正常工作,您必须先在测试中导入 PageObjectLibrary
。然后,您必须先请求加载页面对象库,然后才能使用该库中的关键字。
由于您的 Open App
关键字在页面对象库中,您必须先调用 go to page CountryPage
或 the current page should be CountryPage
。调用这些关键字中的任何一个都会导致加载您的库,然后使关键字可用。
我正在为 Robot Framework 编写自定义页面对象库,如下所示:robotframework-pageobjectlibrary
我的页面自定义关键字(页面对象)在一个单独的文件夹中,当我 运行 我的 Robot Framework
测试时,我使用 --pythonpath
选项给出它们的路径,如下所示:robot --pythonpath ../resources/pageobjects lib-test/test.robot
。
我的目录结构如下所示:
CustomPageObjectLibrary
|--__init__.py
|--keywords.py
|--locatormap.py
|--pageobject.py
Resources
|--pageobjects
|__CountryPage.py
Tests
|--lib-test
|__test.robot
CustomPageObjectLibrary 的内容目前与链接存储库中的内容相同,除了我使用 AppiumLibrary
而不是 SeleniumLibrary
。
CountryPage.py
from CustomPageObjectLibrary import PageObject
class CountryPage(PageObject):
PAGE_TITLE = "Country"
_locators = {
'germany': 'countryGermany',
}
# def __init__(self):
# super(PageObject, self).__init__()
def open_app(self):
self.appiumlib.open_application('http://localhost:4723/wd/hub', platformName='Android', deviceName='...', appPackage='...', appActivity='.MainActivity', uiautomator2ServerInstallTimeout=50000)
def choose_country(self, country):
# Convert country to lovercase
country = str(country).lower()
self.appiumlib.wait_until_element_is_visible(定位器=self.locator.germany) self.appiumlib.click_element(定位器=self.locator.germany)
我的测试:
*** Settings ***
Variables ../../resources/pageobjects/config.py
Library CustomPageObjectLibrary
Library AppiumLibrary
*** Test Cases ***
Navigate To Not Connected Screen
Open App
Choose country germany
我 运行 使用以下命令:robot --pythonpath ../resources/pageobjects lib-test/test.robot
我得到的错误:No keyword with name 'Open App' found.
这可能是什么问题?
要使页面对象库正常工作,您必须先在测试中导入 PageObjectLibrary
。然后,您必须先请求加载页面对象库,然后才能使用该库中的关键字。
由于您的 Open App
关键字在页面对象库中,您必须先调用 go to page CountryPage
或 the current page should be CountryPage
。调用这些关键字中的任何一个都会导致加载您的库,然后使关键字可用。