There have been some popular posts in this blog describing the use of Eclipse, PyDev and monkeyrunner. However, I have received a lot of questions regarding the definition of the interpreter and perhaps it requires a little deep explanation.
Even though monkeyrunner is a Jython interpreter, to successfully use it from PyDev you have to identify it as plain Python.
This screenshot shows the definition of the interpreter which coincidentally, we called monkeyrunner.
Following these steps you would have no problems using monkeyrunner from PyDev.
Hope this helps.
Wednesday, August 29, 2012
Friday, August 17, 2012
monkeyrunner: detecting the OS
Sometimes you monkeyrunner script should know the Operating System it is running on. In the big majority of the cases you don't have to worry if you are running on Linux or Mac OS X, but things are not so smooth on Windows.
I'll give you an example. I've received some bug reports about AndroidViewClient not being able to find adb. AndroidViewClient tries to be clever and not to invoke adb if it's going to fail because it's not found or it's not executable. To determine this, it is using:
if not os.access(adb, os.X_OK):
raise Exception('adb="%s" is not executable' % adb)
the trick here is that for Windows platforms adb should include the trailing .exe.
Then the problem is to determine the OS the script is running on.
There are several ways of determining the OS in python and jython. Let's see what are the results using monkeyrunner
From the previous table we can determine that the best way of obtaining the OS from a monkeyrunner script is
java.lang.System.getProperty('os.name')
I hope this helps you
I'll give you an example. I've received some bug reports about AndroidViewClient not being able to find adb. AndroidViewClient tries to be clever and not to invoke adb if it's going to fail because it's not found or it's not executable. To determine this, it is using:
if not os.access(adb, os.X_OK):
raise Exception('adb="%s" is not executable' % adb)
the trick here is that for Windows platforms adb should include the trailing .exe.
Then the problem is to determine the OS the script is running on.
There are several ways of determining the OS in python and jython. Let's see what are the results using monkeyrunner
Command | Linux | Mac OS X | Windows |
---|---|---|---|
os.getenv('os') | None | None | Windows_NT |
os.name | java | java | java |
platform.system() | Java | Java | Java |
sys.platform | java1.6.0_26 | java1.6.0_33 | java1.7.0_05 |
java.lang.System.getProperty('os.name') | Linux | Mac OS X | Windows XP |
From the previous table we can determine that the best way of obtaining the OS from a monkeyrunner script is
java.lang.System.getProperty('os.name')
I hope this helps you
Labels:
android,
java,
jython,
monkeyrunner,
python
Wednesday, August 01, 2012
Introduction to Android Testing @ OSCON 2012
It was great having presented my tutorial at OSCON 2012. Definitely is one of the best organized conferences in the world and everything was as expected and even better in most cases. It was a pleasure and an honour for me to be there.
I really want to thank you all.
For those who missed it, here are the slides that are also available at the OSCON 2012 web site: Introduction to Android Testing Presentation.
I really want to thank you all.
For those who missed it, here are the slides that are also available at the OSCON 2012 web site: Introduction to Android Testing Presentation.
Labels:
android,
presentation,
tests,
tutorial
Location:
Portland, OR, USA
Subscribe to:
Posts (Atom)