B2G/QA/Automation/Style Guide/Howtos: Difference between revisions

→‎Debug a non-working wait: added extra explanation
(PDB)
(→‎Debug a non-working wait: added extra explanation)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
= How-Tos =
= How-Tos =
== Using WebIDE to Define Locators ==
== Using WebIDE to Define Locators ==
WebIDE can connect to firefox OS devices, and lets the user to view the locators of Firefox OS app.  For basics of WebIDE, please refere to [https://developer.mozilla.org/en/docs/Tools/WebIDE this page].
WebIDE can connect to firefox OS devices, and lets the user to view the locators of Firefox OS app.  For basics of WebIDE, please refer to [https://developer.mozilla.org/en/docs/Tools/WebIDE this page].


'''Prerequisites:'''<br />
'''Prerequisites:'''<br />
Line 56: Line 56:
=== Example ===
=== Example ===
[http://mxr.mozilla.org/gaia/source/tests/python/gaia-ui-tests/gaiatest/apps/music/regions/ Music helper methods] contain a number of examples of shadow DOM usage.   
[http://mxr.mozilla.org/gaia/source/tests/python/gaia-ui-tests/gaiatest/apps/music/regions/ Music helper methods] contain a number of examples of shadow DOM usage.   
<source python>
<source lang="python">
     def tap_cover_in_player_view(self):
     def tap_cover_in_player_view(self):
         # here, we switch to the active iframe view, and then switch into the shadow DOM within
         # here, we switch to the active iframe view, and then switch into the shadow DOM within
Line 83: Line 83:
<br><br>  
<br><br>  
[http://marionette-client.readthedocs.org/en/latest/reference.html?highlight=switch_to_frame#marionette_driver.marionette.Marionette.switch_to_frame switch_to_frame()] command lets you change the frame, and you may need to do this when you need to manipulate system dialog or browser window instance.
[http://marionette-client.readthedocs.org/en/latest/reference.html?highlight=switch_to_frame#marionette_driver.marionette.Marionette.switch_to_frame switch_to_frame()] command lets you change the frame, and you may need to do this when you need to manipulate system dialog or browser window instance.
<source python>
<source lang="python">
# switch to the system frame
# switch to the system frame
self.marionette.switch_to_frame()
self.marionette.switch_to_frame()
Line 93: Line 93:
</source>
</source>
gaia_test.py has a helper app to switch to the displayed app, switch_to_displayed_app().   
gaia_test.py has a helper app to switch to the displayed app, switch_to_displayed_app().   
<source python>
<source lang="python">
def switch_to_settings_app(self):
def switch_to_settings_app(self):
     # wait until settings app is displayed
     # wait until settings app is displayed
Line 103: Line 103:
== Handling Browser Instances  ==
== Handling Browser Instances  ==
As mentioned above, there is a difference between Browser and Browser Tabs.  Also, the browser elements (URL bar, dialogs, buttons, etc.) are on a separate frame (system frame) from the displayed web contents.  <br>In order to properly detect and manipulate all of them, it is necessary to switch between separate frames.
As mentioned above, there is a difference between Browser and Browser Tabs.  Also, the browser elements (URL bar, dialogs, buttons, etc.) are on a separate frame (system frame) from the displayed web contents.  <br>In order to properly detect and manipulate all of them, it is necessary to switch between separate frames.
<source python>
<source lang="python">
         search = Search(self.marionette)
         search = Search(self.marionette)
         search.launch()
         search.launch()
Line 131: Line 131:
On a related note, each page should have its own class definition, where it lists methods that manipulates and checks the associated UI elements.
On a related note, each page should have its own class definition, where it lists methods that manipulates and checks the associated UI elements.
<br>
<br>
<source python>
<source lang="python">
      music_app.wait_for_music_tiles_displayed()
        music_app.wait_for_music_tiles_displayed()


         # tapping albums tab returns the list_view object,
         # tapping albums tab returns the list_view object,
Line 149: Line 149:
== Use Python Debugger ==
== Use Python Debugger ==
You can stop the execution of the script and inject custom python statements by using pdb.  just add below lines where you'd like to start debugging:
You can stop the execution of the script and inject custom python statements by using pdb.  just add below lines where you'd like to start debugging:
<source python>
<source lang="python">
import pdb
import pdb
pdb.set_trace()
pdb.set_trace()
</source>
</source>
[https://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/ Here] is the informative tutorial regarding pdb.
[https://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/ Here] is the informative tutorial regarding pdb.
== Debug a non-working wait ==
When a wait raises an exception while you actually see something happening on the device, you can use a snippet like:
<source lang="python">
# Do something that changes the value of element(s)
do_motion()
for i in range(0, 20)
    print i, expected_end_value, element_that_is_moving.rect["y"]
Wait(self.marionette).until(lambda m: expected_end_value == element_that_is_moving.rect["y"])
</source>
352

edits