I am running calabash-android test for an android application. I need to attach images and videos to a particular section. I can reach the gallery section and after that, I could not select an item from the device library. Is there any way to keep a copy of video and image in my test directory and access the whenever needed? Or is there any solution to access the gallery. And one more thing is that I am integrating the test on Circle-ci later. And I don't know how can I manage it when it is on Circle-ci. All kind of help is appreciated.
Calabash only has access to your app, not anything outside of it.
You will be able to put together a solution using adb to interact with the screen, using touch or keyboard events. However, this will be tied to one specific screen size, as it's done by pixels.
adb shell input tap x y
You could put the images/videos in the directory so they are the most recent, then use adb touch events to select them? It's a bit hacky but it should work.
If I've understood your question correctly, the circle ci part should probably be split out into another question, as it isn't really tied to the previous bit.
EDIT: We ended up getting it to work by running
`adb shell input tap 200 200`
Related
I'm using Android emulator in Jenkins to run functional tests (Cucumber). Everything works fine if the emulator doesn't contain showcase view at the start.
But if there is a showcase view my tests fail, because application runs behind this view.
I've tried to send keyevents using adb to the emulator before using it:
adb shell input keyevent KEYCODE_MENU;
but it doesn't help. I've tried KEYCODE_MENU, KEYCODE_BACK and other keys, but they don't disable this view.
I guess this property should be available as a system preference in the Android, but I can't find it :(
How can I disable showcase view in emulator? I have access to the emulator using adb.
UPDATE
There's no such flag which can be set in emulator config file or passed to emulator at the start.
And I still don't have a clean solution for this, but few workarounds exist. And that's understandable as showcase view is just a view from Launcher application and logic for that is inside Launcher application.
tricky way, but universal: Prepare custom Android Launcher application with disabled showcase (based on AOSP Launcher) and pre-install (replace default launcher) it on target emulator.
manual way, not universal: gather list of emulators used and coordinates of OK button on those, and send appropriate touch coordinates upon emulator start (as Christopher Orr proposed)
You should be able to send a tap event, for example:
adb shell input tap 700 900
That would tap at approximately the correct x,y pixel coordinate for that button on a Nexus 4.
This is a difficult one: I want to know where the buttons / textviews etc are located in the current focused activity which might not be mine. The app shall only run on my device so I can guarantee root / su and system-signatures + Android 4.2 and up (API 17).
I thought of getting a Screenshot via screencap or fb2png, passing it to an edge detection algorithm and look for squares, this would cover some views, better then nothing but this is not really satisfying me.
An other way would be to unpack the app, look for the layout files and parse them in what way ever (but if it has multiple layout files it will be very hard / impossible).
Thus Android must now which views are in foreground to make them touchable.
Where is this info stored? How can I access it? Or maybe other ideas?
I am testing an Android application with Sikuli, but each time the test runs the behaviour is different:
the test stops at the first command, not finding the first image
finds only some images and the test stops at a particular image which isn't found
finds all images and the test runs successfully
Sikuli is runned on Windows 7. Does anyone know if it's a problem of focus or something else and how to solve it?
Thanks
Maybe you can fix your recognition issue by changing the matching level. From Sikuli Gui :
Click on the image
In Pattern Settings > Matching Preview, drag the Similarity bar to a value below 1.0 (try different values)
You may also need to add a delay for the browse button to appear on the screen. You could try something like this
wait("Browse.png", 10 ) # Wait for up to 10s for the app to load
You might also try increasing the size of the picture that you are matching to. Try including nearby artifacts. Remember that you can change the location on the picture that is the mouse click point if your Browse button is not dead centre.
You can try any click action twice, using a try/except block.
Sometimes the vision algorithm just fails.
Running the Android Emulator (for anything) is paaaainffullly sloooow and arbitrary.
So, it pays with Android ems to make Sikuli statements a little "smarter,"
like this:
wait(browsebutton.png, 20)
onAppear(browsebutton.png, click(browsebutton.png))
Looks busier, but it makes the script "smart" in both waiting for the button, and then clicking it as soon as it appears (instead of waiting twenty seconds if it appears after five).
I would need to be able to take screen dumps for testing, and with ICS there is now a screen shot function, that can be invoked by pressing (and holding) volume down and power button.
Is there any way to script this function through adb? (As I understand it there's no public java API for it). I have tried to use KeyEvent from java to emulate power and volume button, and I have tried to use adb keyevent and adb sendevent without success. I suspect that the power button also generate some low level calls that are not generated with the above methods.
So do anyone know if it is possible to call the function from adb?
If this is not possible, do someone know where in the source code this screen shot function exist? Maybe I can figure something out by reading it.
update
source code for capture the screen is in "frameworks/base/services/surfaceflinger/services/surfaceflinger/SurfaceFlinger.cpp" in a function called screenCapture. I do not know if it is possible to call it from jni, but I will try, because it would be great if I could take a screen shot through java.
Otherwise, #edthethird had a solution through android.amberfog.com/?p=168 that will make it possible to take a screenshot with the commandline.
Thank you for the help everyone!
In the form of adb commands, the following works on ICS devices:
adb shell /system/bin/screencap -p /sdcard/img.png
adb pull /sdcard/img.png img.png
See: http://a-more-common-hades.blogspot.com/2012/01/screenshot-command.html
Well this has nothing to do with ICS, but in eclipse, look at a Devices tab. There is a tiny little camera icon on the far right. (From right to left, it is "box", "line", "upside down triangle", and "camera". Click on this camera to take a screen shot of the currently selected device.
This works on any version of Android, not only ICS.
See this question:
Screenshot of the Nexus One from adb?
Basically you can pull the framebuffer using adb and convert it into a usable image yourself, or you can just use the command line utility provided by Google. Looking round I think you may need to tweak that utility a little to get it to work on newer versions of Android.
As the other answer points out though, its probably less hassle to just do this from Eclipse, unless you're trying to automate testing.
After looking into the source code, there is a library that does exactly what I want.
frameworks\base\cmds\screencap\screencap.cpp
The program can be executed on android by /system/bin/screencap .
So it is possible to execute in Java on android by Runtime.getRuntime().exec();
A drawback is that you need a special certificate for taking screenshots.
I've started creating a MonkeyRunner script. This is going ok, but whenever I add a MonkeyDevice::touch command, I have to determine the input coordinates by trial-and-error. Basically I guess at the coordinates I want to touch and see if those coordinates result in the button touch I'm trying to test. That works, but it's a slow process. Is there anyway to determine the coordinates of UI controls, perhaps from the layout XML files?
I found how to do it. Use the Pixel Perfect view within Eclipse to determine the x & y coordinates of the UI element. Here's a quick overview:
1) Eclipse must be running
2) Your Android device must be connected (either the real device via ADB, or the emulator)
3) Run the hierarchy viewer (in /tools)
4) Select "Inspect screenshot"
The Pixel Perfect view will launch automatically. Just place the cross-hairs on the UI element. The x and y coordinates, along with the RGB values, are displayed below.
Here's the URL that got me started: http://developer.android.com/guide/developing/debugging/debugging-ui.html#pixelperfect
This post (monkeyrunner: interacting with views), may give you and idea of how to obtain the View's coordinates using AndroidViewClient.
Most of the Android versions you can enable pointer location in Settings->Developer Options. Once you enable it, it is easy to find out the (x,y) coordinates.
you can also use the HierarchyViewer tool in your AndroidSDK>tools folder to take screenshots of the current screen and examine that image pixel by pixel to get exact coordinates.
For devices older than Android 4.0, see the paragraph following this one. Android 4.0 and later include Settings->Developer options->Pointer location toggle which toggles a transparent ribbon across the top of the device screen with coordinates, velocities and touch-pressure readings including swipe tracks and x/y crosshairs for the current touch location. This is a lot easier than using alternatives such as Monkey Recorder and other means. In Android 4.2 and later, Developer options is hidden from the Settings menu and must be enabled by going to Settings->About tablet and tapping on Build number seven times. One can only presume that Android hid Developer options because of the increasingly user-experience-affecting options it contains and the number of consumer calls/complaints to device makers from people who played with it or whose children played with it.
In older versions which may not include a Pointer location toggle, there is an app on the Play Store (aka Android Market), Developers Tools. See link here: https://play.google.com/store/apps/details?id=com.ggb.development
It will show up with a gear icon and the caption Dev Tools on a device and provide similar functionality which Dev Tools in an AVD (Android Virtual Device) has. That includes Dev Tools ->Development settings>No Pointer Location/Pointer Location radio button toggle. Setting that toggle to Pointer Location provides the exact same functionality built-in with Android 4.0 and later. The same application also has a more limited pointer setting at Dev Tools->Pointer Location which limits pointer location to only a blank screen.
Enjoy!
Create a xyz.py file with below code and connect the device and run it in terminal like monkeyrunner xyz.py, then you will get your device in pc, then u click on any button in the recorder it will give you the coordinates, after that explore it to any file and you can use the coordinates.
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
device = mr.waitForConnection()
recorder.start(device)
I found an adb approach. Use adb shell getevent -l to get a list of events, grep for ABS_MT_POSITION (gets the line with touch events in hex) and finally use awk to get the relevant hex values, strip them of zeros and convert hex to decimal that monkey runner uses. This is all done with the following:
adb shell getevent -l | grep ABS_MT_POSITION --line-buffered | awk '{a = substr($0,54,8); sub(/^0+/, "", a); b = sprintf("0x%s",a); printf("%d\n",strtonum(b))}'
This continuously prints the x and y coordinates in the terminal only when you press on the device.