GoogleSearchPage

Resource file mapping of an equivalent page object model/pattern class in code

One could expand this to include nesting/layering/inheriting of page objects from a base object to more specific page objects, but this is just a simple example for now.

Mapped from example at http://assertselenium.com/automation-design-practices/page-object-pattern/

Setting
Documentation Page Object as Resource File Example for Robot Framework
Library Selenium2Library

Page locators, with location strategy identifier, as variables of the resource file "class"

The page locators could be separated out in separate variable file(s), for those who prefer page object modeling where locators are kept separate from the page object methods. But best to have them together to represent the page object.

Variable
${SEARCH_FIELD} name=q
${SEARCH_BUTTON} name=btnG

Page object methods as user keywords of resource file "class"

Since there is no "this" or "self" (I think?) referral of keywords or variables within resource file, we shall just append resource file name to local keyword methods in scope just for clarification in case of keyword name conflicts (even though presently not).

Keyword
Click On Search [Documentation] Click the search button to proceed with the search
Selenium2Library.Click Button ${SEARCH_BUTTON}
Close [Documentation] Close the browser window
Selenium2Library.Close Browser # or is it Selenium2Library.Close Window?
Get Title [Documentation] Get the page title for Google search page
${result} = Selenium2Library.Get Title
[Return] ${result}
Open [Arguments] ${url}
[Documentation] Open (or go to) the Google search page
Run Keyword And Return If ${BROWSER_OPENED} == ${true} Selenium2Library.Go To ${url}
Selenium2Library.Open Browser ${url} ${BROWSER} #other optional args
${BROWSER_OPENED} = Set Variable ${true}
Search For [Arguments] ${searchTerm}
[Documentation] Perform a search on Google (enter search text, then click search)
GoogleSearchPage.Type Search Term ${searchTerm}
Sleep 1 seconds Arbitrary delay for page load and action to take effect correctly in automation
GoogleSearchPage.Click On Search
Type Search Term [Arguments] ${searchTerm}
[Documentation] Enter search term into Google search field. This doesn't click the search button as a follow up.
Selenium2Library.Input Text ${SEARCH_FIELD} ${searchTerm}