Since Appium's inspector is not conducive recording scripts on Windows, I am using AppiumForWindows coupled with uiautomatorviewer from SDK time to identify app objects and actions to send. I know that we can easily use recording option on Mac in order to record the flow and run it on Mac using appium.
However, I wanted to know if i can switch to Mac just for recording my android app script on the Mac machine and go then to my favourite windows machine for running them using appium? I cannot test now because I have not Mac yet. I told myself that it is possible because of the use of java language (multi-platform) and the fact that Appium provides a standard API both Android and iOS for automation but at the same time, I have doubts because of that answer, I have found on line at https://discuss.appium.io/t/can-we-record-the-script-on-mac-machine-using-appium-tool-and-re-run-the-recorded-script-on-android-or-window-phone-using-appium/5938
I want to decide myself finally. Please i want to know what you think about.
Yes and No, Appium api's are cross platform compatible, however the id's and paths which you use to locate the object under test in both platforms are different, which could cause the script to not work.
I have not used the recorder as such, however if both apps are exactly similar, one could create same test case, with maximum reusable in locating an object by accesibility tag (provided both are kept the same).
I set up the automator and implemented some test cases.
I can run it via adb comandline instruction. But is there a way to run it directly in the Eclipse environment?
Like JUnit test cases?
As standard, UI Automator tests are compiled and built into a jar file, on a desktop computer, they are then deployed to the device by pushing the jar file to the device using adb. They are then run on the device, in the Android runtime by using adb shell uiautomator
I have not seen anyone else trying to run the test cases directly on the device rather than building them following the approach Google (Android) document. It might be possible, however you may have to work hard to discover whether your approach is possible or viable. UIAutomator is distinct and separate from the Android InstrumentationTestCase framework. Instead it interacts with the GUI and has the advantage of being able to interact with a wide range of apps, including things like the inbuilt Settings UI on Android devices.
I'm new to Android. I have a Python program that is both a CGI script as well as an SMS-based interaction system for a small database. It is an extremely low demand system (a handful of users) being run by a grassroots organisation. But it requires stability, in the sense of not having random crashes or down time. For various reasons, running this on an Android phone would resolve some problems with the existing setup. However, before I dive in, I wanted to check regarding the feasibility of such a system. It would have to:
Run a web server that could execute CGI scripts (vanilla CGI)
Respond to SMSs
Handle an SQlite database
Do so in Python (as porting it to Java is not feasible due to time constraints)
Interfacing with phone users is not required at this stage.
I am aware that the pieces that would be needed exist - web servers with CGI, SL4A, etc. But the webservers mostly seem intended for personal use and SL4A clearly states that it "is alpha quality software". The various questions on SO relating to SL4A also don't seem to say much on this kind of use case. They are focused on application development for phones (such as this one).
In short, would such a system be stable? Assuming the core program is sound, could I rely on it?
TLDR: CherryPy is a dependable server, and Android may be dependable enough to build servers on these days.
I used to maintain a project that used CherryPy and SL4A (with ws4py for websockets).
CherryPy 3.2.2 worked perfectly on Python 2.6 and Python 3.2.
The application was often running for a day or two. It seemed like it would have been fine if it ran longer, but it got restarted a lot as it was being developed.
CherryPy was always fine, but Android devices do sometimes just crash, so SL4A will exit from time to time, and need to be restarted. This may not be an issue on a device that was only used as a server. For me, it was always stable when the device was left running overnight, but would occasionally crash when I was using the device normally (it was my actual phone). All of this was on a Galaxy SII, back when Android was still pretty buggy like that.
Setting up CherryPy is easy. It's pure Python, so you can just drop a copy onto your path some place and import it (you do not need an emulator either).
You may struggle to keep the device awake. If it is left alone, it will go to sleep. You can tell it to stay awake in the developer options, but I am pretty sure that only works if the device is charging.
UPDATE: Android is much more stable now days, but work on the SL4A project has pretty much ended. There's a project called QPython that maintains SL4A as part of a bigger app, so this stuff can still be done.
For running Python CGI scripts in Android. Basically you needed a web server capable of running CGI scripts in Android platform but, I found none. You need toy CGI script to suit the Cherrypy web server and it could run on Android.
Are steps are here :
First thing we need is to download the SL4A (r4) software in the
Android (2.3) emulator. It can be done from your Android browser by
going to the SL4A site. Now install the software in emulator.
Then install Python for Android from the same SL4A site. It'll
download an apk of version r4.
Launch SL4A application and check that HelloWorld python script is
running. It will make sure that your installation is fine.
Now is the time to install Cherrypy library module. It can be found
at http://www.cherrypy.org/wiki/CherryPyDownload. I have taken 3.2.0
version. Download the egg for python 2.6.
Now we need to transfer the egg file to Android emulator. Use adb
push command to transfer the egg file to /mnt/sdcard/Download.
Launch Python for Android from emulator and click on Import modules.
It will list the newly uploaded egg file. Select it and install.
Now we can write a Cherrypy script to be run as CGI. Below is a
HelloWorld example taken from Cherrypy tutorial (modified a bit)
# Import CherryPy global namespace
import cherrypy
class HelloWorld:
""" Sample request handler class. """
def index(self, **params):
# CherryPy will call this method for the root URI ("/") and send
# its return value to the client.
for key in params:
print key, '=', params[key]
return "Hello world!"
# Expose the index method through the web. CherryPy will never
# publish methods that don't have the exposed attribute set to True.
index.exposed = True
# CherryPy always starts with app.root when trying to map request URIs
# to objects, so we need to mount a request handler root. A request
# to '/' will be mapped to HelloWorld().index().
cherrypy.config.update({'server.socket_host': '127.0.0.1'})
cherrypy.config.update({'server.socket_port': 8080})
cherrypy.quickstart(HelloWorld(), '/')
8> The script needs to be transferred to /mnt/sdcard/sl4a/scripts directory in emulator. Then you can launch SL4A and tap the script to run. Debug outputs are visible if you run in SL4A console.
9> From the Android browser, check the URL http://localhost:8080/. It will say "Hello world".
This the web server set we can place python scripts to access Android phone data and other stuff which can be exposed to the outside clients.
Credits to: see the screen shots here
Other Info:
micro-httpd (GET / POST / CGI support) cross-compiled to Android
python-for-android
Running "Hello, world!" as a CGI Script
What I recommend:
I suggest to go for any lightweight web servers (like node.js) in raspberry pi
Ref:
Raspberrry pi python
lightweight web servers
web application framework for Node.js
Here is a link to one of my blog posts describing how to turn your android phone in a basic CGI webserver using Py4A / SL4A in around 10 minutes http://matbaker.wordpress.com/2013/01/29/android-webserver-in-10-minutes/
Your application requires running a server, which presumes constant availability, connectivity and unrestricted processing power. A mobile phone provides none of these.
Mobile phones are designed to conserve battery life by minimising processing and power demands. These two points are directly at odds with running a server.
But it requires stability, in the sense of not having random crashes or down time.
Assuming your software is correctly written, you may not have to worry about crashes, but the OS will be constantly trying to put the system to sleep.
Run a web server that could execute CGI scripts (vanilla CGI)
Respond to SMSs
Handle an SQlite database
Do so in Python (as porting it to Java is not feasible due to time constraints)
Why not just use a small virtual server? You can easily purchase a server for as little as $5 a month (e.g. DigitalOcean) and use Twilio as an SMS gateway (a few cents per SMS). Cheap, available, reliable and highly available. You get a preinstalled Ubuntu image, install a few extra packages on there and away you go with Python and SQLite. And you don't have to worry at all about the mobile/SMS side of things (signal strength, network availability, etc). All these points above would be satisfied by this solution.
If you don't want to operate a server externally (ie. "in the cloud") then you could use an old PC and install Linux. Or even use a plug computer and have an almost invisible server. There are so many hardware options that are more suitable than a mobile phone.
For various reasons, running this on an Android phone would resolve some problems with the existing setup.
How? What is it about Android that makes it preferable? If you're referring to the laptop battery problem, the phone would suffer a similar (if not worse) fate.
In short, would such a system be stable? Assuming the core program is sound, could I rely on it?
You will probably be fighting the OS and the hardware the whole time. A server wants to be running constantly, a mobile phone wants to be running as little as possible. The entire stack of hardware and software is optimised for power conservation. A mobile is designed to run from a battery with intermittent charging, and its thermal management systems are designed to wake the CPU as infrequently as possible. If you try to run a mobile as a server, you will likely wear out the hardware very quickly. They are simply not designed to run 24/7. You could run such a system, and it would probably work for a while, but I expect you would have to replace the hardware before too long.
Use hardware suited to the task of running a server. Old PCs are so easy to come by these days, it should be possible to get one for free that would be up to the task.
Also, is CGI really a requirement? You should really look at WSGI; it is far more efficient. CherryPi is a nice Python server, and Flask is definitely worth a look too.
I would like to write some sort of macro app that presses keys. Would this be possible on IOS and/or Android?
Yes, for android, have you tried MonkeyRunner
The monkeyrunner tool provides an API for writing programs that
control an Android device or emulator from outside of Android code.
With monkeyrunner, you can write a Python program that installs an
Android application or test package, runs it, sends keystrokes to it,
takes screenshots of its user interface, and stores screenshots on the
workstation.
This link says that it is indeed possible to write code in Python and use it for app development in android platform. I would like to know what the catch is when using Python and not Java. Is there any compromise being made in speed of execution or size?
From the link you posted:
Scripts can be run interactively in a terminal, in the background, or via Locale.
This already is a disadvantage, as you can't release your Apps to Android Market easily. This can however ostensibly be avoided by the build script of Pygame Subset for Android, but I am not sure about this. The Python interpreter will however need to be installed on the device, which will bloat the App's size by quite a bit.
The speed of execution of Python on an Android device of course is slower than Java, as Python doesn't magically accelerate just because it runs on a phone. The difference isn't that great in most situations, though.