B2G/QA/Automation/Style Guide/Python Script Style: Difference between revisions

Moved away the external consumer parts and fixed nits
(Moved away the external consumer parts and fixed nits)
 
(7 intermediate revisions by 2 users not shown)
Line 80: Line 80:
@property
@property
def search_term(self):
def search_term(self):
     return self.selenium.find_element(*self._search_box_locator).value
     return self.marionette.find_element(*self._search_box_locator).value
</source>
</source>


Line 120: Line 120:


== Using High-Level Methods ==
== Using High-Level Methods ==
* In a test script, make sure to only have steps that are high level.  Details can be encapsulated in the helper methods.
* A test script should remain a short entry point which leads to more details (like the main() function of a program). Don't detail every single tap and wait, in the test. Use methods that reflect a user's intent rather than a sequence of small steps the user has to do. The details of how to fulfill that intent will be in the page classes.
* A test should remain a short entry point which leads to more details (like the main() function of a program).
<source lang="python">
* Don't detail every single tap and wait, in the test. Use methods that reflect a user's intent rather than a sequence of small steps the user has to do. The details of how to fulfill that intent will be in the page classes.
# Good
<source python>
# good
messages.send_an_sms_to_yourself()
messages.send_an_sms_to_yourself()
# bad
 
# Bad
messages.open_sms_app()
messages.open_sms_app()
messages.create_new_sms(receiver)
messages.create_new_sms(receiver)
Line 135: Line 134:
== Variable Naming ==
== Variable Naming ==
* Name your variables with units.  
* Name your variables with units.  
<source python>
<source lang="python">
# good
# Good
timeout_in_seconds, width_in_pixels
timeout_in_seconds, width_in_pixels
# bad
 
# Bad
timeout, width
timeout, width
</source>
</source>
* Don't shorten variable names.  
* Don't shorten variable names.  
<source python>
<source lang="python">
# good
# Good
self.time_out_error_time = 1000
self.time_out_error_time = 1000
# bad
 
# Bad
self.t_out_err_tim = 1000
self.t_out_err_tim = 1000
</source>
</source>


== Making test multi-locale ==  
== Making Tests Locale Independent ==  
It is recommended to make the test scripts (and especially the helper methods) locale independent, because this enables us to test devices in RTL locale.  There are still some sections in gaiatest where it checks for the displayed English text, but unless one cannot avoid it, data-l10n-id attribute should be checked in place of any raw text comparison.
It is recommended to make the test scripts (and especially the helper methods) locale independent, because this enables us to test devices in RTL locale.  There are still some sections in gaiatest where it checks for the displayed English text, but unless one cannot avoid it, data-l10n-id attribute should be checked in place of any raw text comparison.


<source python>
<source lang="python">
          
          
         # below method will not work in a non-English locale,  
         # below method will not work in a non-English locale,  
Line 171: Line 172:
* We can check for the raw text in order to verify the user input (i.e., a phone number entered in the dialer app)
* We can check for the raw text in order to verify the user input (i.e., a phone number entered in the dialer app)
* We check the data-l10n-id for any string that comes from Gaia only (i.e., an error message)
* We check the data-l10n-id for any string that comes from Gaia only (i.e., an error message)
== Be aware of outside consumers of ui-test ==
* Be aware if you change or remove the Gaia UI test API, that outside consumers (mtbf, etc) might get broken.
Confirmed users
198

edits