Reputation: 199
So I have this case where I want to combine the keywords files with the page objects files.
Let's assume I have foo.robot
for keywords and bar.robot
for page object:
#foo.robot
*** Settings ***
Ressource bar.robot
*** Keywords ***
Click Submit Button
Wait Untile Element Is Visible ${variable_from_bar} 60s
Click Button ${variable_from_bar}
#bar.robot
*** Variables ***
${variable_from_bar} //button[@id="dummybutton"]
my idea is to combine them both like this
#foobar.robot
*** Variables ***
${variable_from_bar} //button[@id="dummybutton"]
*** Keywords ***
Click Submit Button
Wait Untile Element Is Visible ${variable_from_bar} 60s
Click Button ${variable_from_bar}
Is there any particular reason why I shouldn't do this practice? Or any technical issue that would face me in the future after applying it?
Upvotes: 2
Views: 149
Reputation: 7271
Generally I would suggest to rename .robot
to .resource
so resource files will be distinguished from suite files in naming as well.
As for the combination I think it is not a bad approach but the hierarchy can be a bit more separated. Let's say there are web elements that are used across multiple pages you want to put those into separate resource files independent from the page object resource file.
Let's say there is a unique button.
button.resource
*** Keywords ***
Click Unique Button
[Arguments] ${button_locator}
# Handle some unique behaviour
Click Button ${button_locator}
This could be used across multiple pages where the purpose of the button is different, the ID different but still the way a button click should be handled is the same.
PageA.resource
*** Settings ***
Resource button.resource
*** Variables ***
${variable_from_bar} //button[@id="dummybutton"]
*** Keywords ***
Do Stuff
Click Unique Button ${variable_from_bar}
PageB.resource
*** Settings ***
Resource button.resource
*** Variables ***
${download_file} //button[@id="downloadbutton"]
*** Keywords ***
Do Stuff
Select File my_file.txt
Click Unique Button ${download_file}
To summarize you could merge the page object keywords and locator variables into the same file but you should keep the generic, page independent keywords in their own resource files.
Upvotes: 3