352
edits
(→Using high-level methods: added) |
(File Headers added) |
||
| Line 70: | Line 70: | ||
# Bad | # Bad | ||
class test_this_site: | class test_this_site: | ||
</source> | |||
== Locators == | |||
TBD - jlorenzo | |||
* Locator variables should be prefixed with <code>_</code> to show that it is [http://docs.python.org/tutorial/classes.html#private-variables private]. | |||
* Variables should be descriptive of the area and not clash with any properties. | |||
* Should have a suffix of <code>_locator</code>. | |||
* Accessing locators should be done through a property or method as this keeps the locator as read-only. | |||
<source lang="python"> | |||
@property | |||
def search_term(self): | |||
return self.selenium.find_element(*self._search_box_locator).value | |||
</source> | |||
* We should use locators in the following order of preference (there will be exceptions): | |||
** ID | |||
** Name | |||
** Class name | |||
** CSS selector | |||
** XPath | |||
* CSS locators should use whitespace for readability when using direct descendants. | |||
<source lang="python"> | |||
# Good | |||
_my_locator = "css=#content > p > a" | |||
# Bad | |||
_my_locator = "css=#content>p>a" | |||
</source> | |||
* Use Python tuples to define locators: | |||
<source lang="python"> | |||
# Good | |||
_my_locator = (By.ID, "content") | |||
</source> | </source> | ||
edits