我正在像这样编写用于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(locator = self.locator.germany)self.appiumlib.click_element(locator = 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.
这可能是什么问题?
要使页面对象库正常工作,必须首先导入页面对象库。然后,必须先加载页面对象库,然后才能使用该库中的关键字。
由于Open App
关键字在页面对象库中,因此必须首先调用go to page CountryPage
或the current page should be CountryPage
。调用这些关键字中的任何一个都将导致您的库被加载,然后使这些关键字可用。