You can only return objects from Marionette that can be JSON-serialized; the battery object cannot (it's a https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager instance). This is why you can return navigator.battery.level, but not navigator.battery.
Jonathan ----- Original Message ----- From: "Craig Comstock" <[email protected]> To: "Zac Campbell" <[email protected]> Cc: "Mozilla B2G mailing list" <[email protected]> Sent: Sunday, February 9, 2014 11:45:09 AM Subject: Re: [b2g] marionette script "hanging" on simple javascript... logcat shows the following: I/Gecko ( 2282): 1391974328201 Marionette DEBUG accepted connection on 127.0.0.1:36081 I/Gecko ( 2282): 1391974328417 Marionette INFO loaded marionette-listener.js I/Gecko ( 2282): 1391974328419 Marionette INFO sendToClient: {"from":"0","value":"3-b2g"}, {564c54ad-127a-41ba-a09b-987040a49396}, {564c54ad-127a-41ba-a09b-987040a49396} I/Gecko ( 2282): 1391974328435 Marionette DEBUG Got request: executeWithCallback, data: {"to":"0","sessionId":"3-b2g","name":"executeAsyncScript","parameters":{"specialPowers":false,"scriptTimeout":null,"newSandbox":true,"args":[],"filename":"vibrate","script":"marionetteScriptFinished(navigator.battery)","line":15}}, id: {9df62a7e-b7d2-437c-9f30-8772f1d20793} E/GeckoConsole( 2282): [JavaScript Warning: "Empty string passed to getElementById()." {file: "chrome://marionette/content/marionette-elements.js" line: 164}] ... repeats quite continuously until I kill -HUP `pidof b2g` ... my script is called "vibrate": #!/usr/bin/python from marionette import Marionette marionette = Marionette('localhost',2828) marionette.start_session() result = marionette.execute_async_script("marionetteScriptFinished(navigator.battery)") print(result) I tried finding the source for marionette-elements.js but didn't have much luck. -Craig ________________________________ From: Zac Campbell <[email protected]> To: Craig Comstock <[email protected]> Cc: Mozilla B2G mailing list <[email protected]> Sent: Sunday, February 9, 2014 5:50 AM Subject: Re: [b2g] marionette script "hanging" on simple javascript... Let me check these example on Monday and get back to you (vibration and battery are not APIs we use in our daily test automation because it's hard to validate the input and output). In the meantime if you want some examples of how we use the Python Marionette client with Fx OS APIs you can look here: https://github.com/mozilla-b2g/gaia/blob/master/tests/python/gaia-ui-tests/gaiatest/gaia_test.py ----- Original Message ----- From: Craig Comstock <[email protected]> To: Zac Campbell <[email protected]> Cc: Mozilla B2G mailing list <[email protected]> Sent: Sat, 08 Feb 2014 05:36:26 -0800 (PST) Subject: Re: [b2g] marionette script "hanging" on simple javascript... Thanks Zac, I think the real problem for me is that the javascript functions don't seem to do what I expect. vibrate() doesn't cause a vibration. returning .battery doesn't return. I tried execute_script first and that didn't work so I tried async. Is it some sort of context or permissions problem? FWIW I have a near constant stream of the following in logcat.... E/GeckoConsole( 109): [JavaScript Warning: "Empty string passed to getElementById()." {file: "chrome://marionette/content/marionette-elements.js" line: 164}] My UI was stuck, i.e. screen black and not responding so I kill HUPd b2g to recover. Thanks, Craig ________________________________ From: Zac Campbell <[email protected]> To: Craig Comstock <[email protected]> Cc: Mozilla B2G mailing list <[email protected]> Sent: Saturday, February 8, 2014 4:22 AM Subject: Re: [b2g] marionette script "hanging" on simple javascript... Hi Craig, execute_async_script expects a callback from marionetteScriptFinished and if doesn't get it it will time out. If you use just execute_script instead of execute_async_script it should work. Or I think you need to do execute_async_script("marionetteScriptFinished(navigator.battery)") (disclaimer untested as I don't have my phone here right now but I think you can work it out!) ----- Original Message ----- From: Craig Comstock <[email protected]> To: Mozilla B2G mailing list <[email protected]> Sent: Fri, 07 Feb 2014 18:37:15 -0800 (PST) Subject: [b2g] marionette script "hanging" on simple javascript... Maybe I'm not understanding something quite right but I was trying to write some python/marionette scripts and the basics detailed here: https://developer.mozilla.org/en-US/Firefox_OS/Platform/Automated_testing/Marionette_for_interactive_Python?redirectlocale=en-US&redirectslug=Mozilla%2FFirefox_OS%2FPlatform%2FTesting%2FMarionette_for_interactive_Python Just don't seem to work... i.e. returning navigator.battery doesn't work, but navigator.battery.level does. Making a phone call seems to work but vibrate doesn't. Any ideas why? I'm running these scripts locally on my keon phone w/ debian installed as well to provide python/gcc/etc... Here's a script that doesn't do anything: #!/usr/bin/python from marionette import Marionette marionette = Marionette('localhost',2828) marionette.start_session() result = marionette.execute_async_script(""" return navigator.vibrate(50); """) print(result) Thanks, Craig _______________________________________________ dev-b2g mailing list [email protected] https://lists.mozilla.org/listinfo/dev-b2g _______________________________________________ dev-b2g mailing list [email protected] https://lists.mozilla.org/listinfo/dev-b2g _______________________________________________ dev-b2g mailing list [email protected] https://lists.mozilla.org/listinfo/dev-b2g _______________________________________________ dev-b2g mailing list [email protected] https://lists.mozilla.org/listinfo/dev-b2g
