├── PageObjectExampleTest.tsv ├── PageObjectExampleTest.robot ├── PageObjectExampleTest.txt ├── GoogleSearchPage.tsv ├── GoogleSearchPage.robot ├── GoogleSearchPage.txt ├── PageObjectExampleTest.html ├── README.md └── GoogleSearchPage.html /PageObjectExampleTest.tsv: -------------------------------------------------------------------------------- 1 | *Setting* 2 | Test Setup GoogleSearchPage.Open ${URL} 3 | Test Teardown GoogleSearchPage.Close 4 | Resource GoogleSearchPage.html 5 | 6 | *Variable* *Value* 7 | ${BROWSER_OPENED} ${false} 8 | ${BROWSER} firefox 9 | ${URL} http://www.google.com 10 | ${SEARCH_TERM} selenium 11 | 12 | *Test Case* 13 | When The User Searches For Selenium The Results Page Title Should Contain Selenium GoogleSearchPage.Search For ${SEARCH_TERM} 14 | ${result} = GoogleSearchPage.Get Title 15 | Should Contain ${result} ${SEARCH_TERM} 16 | -------------------------------------------------------------------------------- /PageObjectExampleTest.robot: -------------------------------------------------------------------------------- 1 | *** Setting *** 2 | Test Setup GoogleSearchPage.Open ${URL} 3 | Test Teardown GoogleSearchPage.Close 4 | Resource GoogleSearchPage.html 5 | 6 | *** Variable *** Value 7 | ${BROWSER_OPENED} ${false} 8 | ${BROWSER} firefox 9 | ${URL} http://www.google.com 10 | ${SEARCH_TERM} selenium 11 | 12 | *** Test Case *** 13 | When The User Searches For Selenium The Results Page Title Should Contain Selenium 14 | GoogleSearchPage.Search For ${SEARCH_TERM} 15 | ${result} = GoogleSearchPage.Get Title 16 | Should Contain ${result} ${SEARCH_TERM} 17 | -------------------------------------------------------------------------------- /PageObjectExampleTest.txt: -------------------------------------------------------------------------------- 1 | | *** Setting *** | 2 | | Test Setup | GoogleSearchPage.Open | ${URL} | 3 | | Test Teardown | GoogleSearchPage.Close | 4 | | Resource | GoogleSearchPage.html | 5 | 6 | | *** Variable *** | Value | 7 | | ${BROWSER_OPENED} | ${false} | 8 | | ${BROWSER} | firefox | 9 | | ${URL} | http://www.google.com | 10 | | ${SEARCH_TERM} | selenium | 11 | 12 | | *** Test Case *** | 13 | | When The User Searches For Selenium The Results Page Title Should Contain Selenium | 14 | | | GoogleSearchPage.Search For | ${SEARCH_TERM} | 15 | | | ${result} = | GoogleSearchPage.Get Title | 16 | | | Should Contain | ${result} | ${SEARCH_TERM} | 17 | -------------------------------------------------------------------------------- /GoogleSearchPage.tsv: -------------------------------------------------------------------------------- 1 | *Setting* *Value* 2 | Documentation Page Object as Resource File Example for Robot Framework 3 | Library Selenium2Library 4 | 5 | *Variable* *Value* 6 | ${SEARCH_FIELD} name=q 7 | ${SEARCH_BUTTON} name=btnG 8 | 9 | *Keyword* 10 | Click On Search [Documentation] Click the search button to proceed with the search 11 | Selenium2Library.Click Button ${SEARCH_BUTTON} 12 | 13 | Close [Documentation] Close the browser window 14 | Selenium2Library.Close Browser # or is it Selenium2Library.Close Window? 15 | 16 | Get Title [Documentation] Get the page title for Google search page 17 | ${result} = Selenium2Library.Get Title 18 | [Return] ${result} 19 | 20 | Open [Arguments] ${url} 21 | [Documentation] Open (or go to) the Google search page 22 | Run Keyword And Return If ${BROWSER_OPENED} == ${true} Selenium2Library.Go To ${url} 23 | Selenium2Library.Open Browser ${url} ${BROWSER} #other optional args 24 | ${BROWSER_OPENED} = Set Variable ${true} 25 | 26 | Search For [Arguments] ${searchTerm} 27 | [Documentation] Perform a search on Google (enter search text, then click search) 28 | GoogleSearchPage.Type Search Term ${searchTerm} 29 | Sleep 1 seconds Arbitrary delay for page load and action to take effect correctly in automation 30 | GoogleSearchPage.Click On Search 31 | 32 | Type Search Term [Arguments] ${searchTerm} 33 | [Documentation] Enter search term into Google search field. This doesn't click the search button as a follow up. 34 | Selenium2Library.Input Text ${SEARCH_FIELD} ${searchTerm} 35 | -------------------------------------------------------------------------------- /GoogleSearchPage.robot: -------------------------------------------------------------------------------- 1 | *** Setting *** Value 2 | Documentation Page Object as Resource File Example for Robot Framework 3 | Library Selenium2Library 4 | 5 | *** Variable *** Value 6 | ${SEARCH_FIELD} name=q 7 | ${SEARCH_BUTTON} name=btnG 8 | 9 | *** Keyword *** 10 | Click On Search 11 | [Documentation] Click the search button to proceed with the search 12 | Selenium2Library.Click Button ${SEARCH_BUTTON} 13 | 14 | Close 15 | [Documentation] Close the browser window 16 | Selenium2Library.Close Browser # or is it Selenium2Library.Close Window? 17 | 18 | Get Title 19 | [Documentation] Get the page title for Google search page 20 | ${result} = Selenium2Library.Get Title 21 | [Return] ${result} 22 | 23 | Open 24 | [Arguments] ${url} 25 | [Documentation] Open (or go to) the Google search page 26 | Run Keyword And Return If ${BROWSER_OPENED} == ${true} Selenium2Library.Go To ${url} 27 | Selenium2Library.Open Browser ${url} ${BROWSER} #other optional args 28 | ${BROWSER_OPENED} = Set Variable ${true} 29 | 30 | Search For 31 | [Arguments] ${searchTerm} 32 | [Documentation] Perform a search on Google (enter search text, then click search) 33 | GoogleSearchPage.Type Search Term ${searchTerm} 34 | Sleep 1 seconds Arbitrary delay for page load and action to take effect correctly in automation 35 | GoogleSearchPage.Click On Search 36 | 37 | Type Search Term 38 | [Arguments] ${searchTerm} 39 | [Documentation] Enter search term into Google search field. This doesn't click the search button as a follow up. 40 | Selenium2Library.Input Text ${SEARCH_FIELD} ${searchTerm} 41 | -------------------------------------------------------------------------------- /GoogleSearchPage.txt: -------------------------------------------------------------------------------- 1 | | *** Setting *** | Value | 2 | | Documentation | Page Object as Resource File Example for Robot Framework | 3 | | Library | Selenium2Library | 4 | 5 | | *** Variable *** | Value | 6 | | ${SEARCH_FIELD} | name=q | 7 | | ${SEARCH_BUTTON} | name=btnG | 8 | 9 | | *** Keyword *** | 10 | | Click On Search | 11 | | | [Documentation] | Click the search button to proceed with the search | 12 | | | Selenium2Library.Click Button | ${SEARCH_BUTTON} | 13 | 14 | | Close | 15 | | | [Documentation] | Close the browser window | 16 | | | Selenium2Library.Close Browser | # or is it Selenium2Library.Close Window? | 17 | 18 | | Get Title | 19 | | | [Documentation] | Get the page title for Google search page | 20 | | | ${result} = | Selenium2Library.Get Title | 21 | | | [Return] | ${result} | 22 | 23 | | Open | 24 | | | [Arguments] | ${url} | 25 | | | [Documentation] | Open (or go to) the Google search page | 26 | | | Run Keyword And Return If | ${BROWSER_OPENED} == ${true} | Selenium2Library.Go To | ${url} | 27 | | | Selenium2Library.Open Browser | ${url} | ${BROWSER} | #other optional args | 28 | | | ${BROWSER_OPENED} = | Set Variable | ${true} | 29 | 30 | | Search For | 31 | | | [Arguments] | ${searchTerm} | 32 | | | [Documentation] | Perform a search on Google (enter search text, then click search) | 33 | | | GoogleSearchPage.Type Search Term | ${searchTerm} | 34 | | | Sleep | 1 seconds | Arbitrary delay for page load and action to take effect correctly in automation | 35 | | | GoogleSearchPage.Click On Search | 36 | 37 | | Type Search Term | 38 | | | [Arguments] | ${searchTerm} | 39 | | | [Documentation] | Enter search term into Google search field. This doesn't click the search button as a follow up. | 40 | | | Selenium2Library.Input Text | ${SEARCH_FIELD} | ${searchTerm} | 41 | -------------------------------------------------------------------------------- /PageObjectExampleTest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 48 |Mapped from (non-Robot Framework) page object example at http://assertselenium.com/automation-design-practices/page-object-pattern/
53 || Setting | 56 |||||
|---|---|---|---|---|
| Test Setup | 59 |GoogleSearchPage.Open | 60 |${URL} | 61 |62 | | 63 | |
| Test Teardown | 66 |GoogleSearchPage.Close | 67 |68 | | 69 | | 70 | |
| Resource | 73 |GoogleSearchPage.html | 74 |75 | | 76 | | 77 | |
| 80 | | 81 | | 82 | | 83 | | 84 | |
| Variable | 89 |||||
|---|---|---|---|---|
| ${BROWSER_OPENED} | 92 |${false} | 93 |94 | | 95 | | 96 | |
| ${BROWSER} | 99 |firefox | 100 |101 | | 102 | | 103 | |
| ${URL} | 106 |http://www.google.com | 107 |108 | | 109 | | 110 | |
| ${SEARCH_TERM} | 113 |selenium | 114 |115 | | 116 | | 117 | |
| 120 | | 121 | | 122 | | 123 | | 124 | |
| Test Case | 129 |||||
|---|---|---|---|---|
| When The User Searches For Selenium The Results Page Title Should Contain Selenium | 132 |GoogleSearchPage.Search For | 133 |${SEARCH_TERM} | 134 |135 | | 136 | |
| 139 | | ${result} = | 140 |GoogleSearchPage.Get Title | 141 |142 | | 143 | |
| 146 | | Should Contain | 147 |${result} | 148 |${SEARCH_TERM} | 149 |150 | |
Resource file mapping of an equivalent page object model/pattern class in code
56 |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.
57 |Mapped from example at http://assertselenium.com/automation-design-practices/page-object-pattern/
58 || Setting | 61 |||||
|---|---|---|---|---|
| Documentation | 64 |Page Object as Resource File Example for Robot Framework | 65 ||||
| Library | 68 |Selenium2Library | 69 |70 | | 71 | | 72 | |
| 75 | | 76 | | 77 | | 78 | | 79 | |
Page locators, with location strategy identifier, as variables of the resource file "class"
82 |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.
83 || Variable | 86 |||||
|---|---|---|---|---|
| ${SEARCH_FIELD} | 89 |name=q | 90 |91 | | 92 | | 93 | |
| ${SEARCH_BUTTON} | 96 |name=btnG | 97 |98 | | 99 | | 100 | |
| 103 | | 104 | | 105 | | 106 | | 107 | |
Page object methods as user keywords of resource file "class"
110 |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).
111 || Keyword | 114 |||||
|---|---|---|---|---|
| Click On Search | 117 |[Documentation] | 118 |Click the search button to proceed with the search | 119 |||
| 122 | | Selenium2Library.Click Button | 123 |${SEARCH_BUTTON} | 124 |125 | | 126 | |
| 129 | | 130 | | 131 | | 132 | | 133 | |
| Close | 136 |[Documentation] | 137 |Close the browser window | 138 |||
| 141 | | Selenium2Library.Close Browser | 142 |# or is it Selenium2Library.Close Window? | 143 |144 | | 145 | |
| 148 | | 149 | | 150 | | 151 | | 152 | |
| Get Title | 155 |[Documentation] | 156 |Get the page title for Google search page | 157 |||
| 160 | | ${result} = | 161 |Selenium2Library.Get Title | 162 |163 | | 164 | |
| 167 | | [Return] | 168 |${result} | 169 |170 | | 171 | |
| 174 | | 175 | | 176 | | 177 | | 178 | |
| Open | 181 |[Arguments] | 182 |${url} | 183 |184 | | 185 | |
| 188 | | [Documentation] | 189 |Open (or go to) the Google search page | 190 |||
| 193 | | Run Keyword And Return If | 194 |${BROWSER_OPENED} == ${true} | 195 |Selenium2Library.Go To | 196 |${url} | 197 |
| 200 | | Selenium2Library.Open Browser | 201 |${url} | 202 |${BROWSER} | 203 |#other optional args | 204 |
| 207 | | ${BROWSER_OPENED} = | 208 |Set Variable | 209 |${true} | 210 |211 | |
| 214 | | 215 | | 216 | | 217 | | 218 | |
| Search For | 221 |[Arguments] | 222 |${searchTerm} | 223 |224 | | 225 | |
| 228 | | [Documentation] | 229 |Perform a search on Google (enter search text, then click search) | 230 |||
| 233 | | GoogleSearchPage.Type Search Term | 234 |${searchTerm} | 235 |236 | | 237 | |
| 240 | | Sleep | 241 |1 seconds | 242 |Arbitrary delay for page load and action to take effect correctly in automation | 243 |244 | |
| 247 | | GoogleSearchPage.Click On Search | 248 |249 | | 250 | | 251 | |
| 254 | | 255 | | 256 | | 257 | | 258 | |
| Type Search Term | 261 |[Arguments] | 262 |${searchTerm} | 263 |264 | | 265 | |
| 268 | | [Documentation] | 269 |Enter search term into Google search field. This doesn't click the search button as a follow up. | 270 |||
| 273 | | Selenium2Library.Input Text | 274 |${SEARCH_FIELD} | 275 |${searchTerm} | 276 |277 | |