0
votes

I am writing a custom Page Object library for Robot Framework like this one: robotframework-pageobjectlibrary

My page custom keywords (page objects) are in a separate folder and when I run my Robot Framework tests, I give their path with the --pythonpath option like this: robot --pythonpath ../resources/pageobjects lib-test/test.robot.

My directory structure looks like this:

CustomPageObjectLibrary
|--__init__.py
|--keywords.py
|--locatormap.py
|--pageobject.py
Resources
|--pageobjects
   |__CountryPage.py
Tests
|--lib-test
   |__test.robot

The contents of the CustomPageObjectLibrary are currently the same as in the linked repo except that I use the AppiumLibrary instead of the 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)

My test:

*** Settings ***
Variables       ../../resources/pageobjects/config.py
Library         CustomPageObjectLibrary
Library         AppiumLibrary

*** Test Cases ***
Navigate To Not Connected Screen
Open App
Choose country      germany

I run this with the following command: robot --pythonpath ../resources/pageobjects lib-test/test.robot

The error what I get: No keyword with name 'Open App' found.

What could be the problem with this?

1
The error you mention has nothing to do with pythonpath. Robot is clearly finding your CustomAppiumLibrary library, but it's not finding any keywords in it. Without seeing a simplified version of the library, there's not much we can do to help. - Bryan Oakley
It's not finding the keywords, because they're not there. My keywords are inside the folder what I give as an option with --pythonpath. My folder structure is the same as in your library @BryanOakley - Fogarasi Norbert
Not directly related to page objects, tag can be removed. - asprtrmp
maybe jus export the PYTHONPATH? export PYTHONPATH=/path/to/root/dir - DUDANF

1 Answers

2
votes

For the page object library to work, you must first import PageObjectLibrary in your test. Then, you must request that a page object library be loaded before you can use the keywords in that library.

Since your Open App keyword is in a page object library, you must first call go to page CountryPage or the current page should be CountryPage. Calling either of those keywords will cause your library to be loaded, which then makes the keywords available.