Auto detect OS of device in appium - android

I am using appium_libto automate my tests in both iOS and Android
Currently, I am maintaining two suites, one for android seperately and another for iOS.
Is there a provision in this cucumber with appium_lib gem, to maintain the cases for both iOS and Android both in a single suite? And let appium automatically detect which device is connected, and execute the test cases tagged accordingly?
Like if Appium detects it to be iOS, run the test cases that are tagged under iOS cucumber -t #ios
I understand env.rb could be of help in this and in hooks.rb under before do I could provide a if and else condition with
if $driver.device_is_android? == 'true'
'cucumber -t #Android'
else
'cucumber -t #iOS'
end
Something like this? Is it possible? I am unable to find information on the internet with respect to auto detect of device OS, and hence posted this as a question with my thoughts.
I understand I can read the versions of the OS with the command adb shell getprop | grep build.version.release , and hence wanted to know if its possible to read the OS with one common command, apart from $driver.device_is_android?
Now to run the cucumber cases, for iOS and Android, I need to pass individual capabilities in appium. Is there a way to do it programmatically in the if and else condition itself?

I also ran into this dilema but I solved differently.
In our case we are using Cucumber on top of Appium so I just execute it with an argument that represents my platform, for example:
cucumber PLATFORM=iOS
Then in my env.rb I get the argument:
#platform = ENV['PLATFORM']
And then I just use it to get the capabilities I want:
if #platform == "DROID"
Appium::Driver.new(droid_caps, true)
else
Appium::Driver.new(ios_caps, true)
end
When you are running a test you always know which platform you are testing so it makes sense to send it as an argument.

Related

Android UI test Fingerprint with Espresso

I have an Android fingerprint implementation working and I was looking to add UI tests with Espresso. One problem I can't find a solution to is how to emulate the scanning of a finger. There is an adb command
adb -e emu finger touch which should work on emulators.
Any idea on how to integrate something like that with Espresso?
From this question sending to an emulator is possible:
Runtime.getRuntime().exec("adb -e emu finger touch 1")
I expect, though can't show any working, that faking a fingerprint on a real device would require some special kind of security magic.
Edit: this doesn't work from within espresso tests.

Android programmatically automated touch events

I was wondering if there is any way to progam automated touch events? For example, I have my android app and I want to make a program where automatically make 100 tests and every test makes touch events depending on what appears on the app. And I would like to do this on emulators, if is possible all 100 test at the same time.
for exercising your app with many (more than 100 events) use monkey (Full name: UI/Application Exerciser Monkey) or/and monkeyrunner.
The Monkey is a command-line tool that you can run on any emulator
instance or on a device. It sends a pseudo-random stream of user
events into the system, which acts as a stress test on the application
software you are developing.
The Monkey includes a number of options, but they break down into four
primary categories:
Basic configuration options, such as setting the number of events to
attempt.
Operational constraints, such as restricting the test to a single package.
Event types and frequencies.
Debugging options.
Site: http://developer.android.com/intl/es/tools/help/monkey.html
Basic using:
$ adb shell monkey [options] <event-count>
Example
adb shell monkey -p your.package.name -v 500
So if you want to take control over Android system events and you're familiar with Python and writing testing scripts, then you can use 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.
The monkeyrunner tool is primarily designed to test applications and devices at the functional/framework level and for running unit test suites, but you are free to use it for other purposes.
Documentation: http://developer.android.com/intl/es/tools/help/monkeyrunner_concepts.html
NOTE: The monkeyrunner tool is not related to the I/Application Exerciser Monkey, also known as the monkey tool. The monkey tool runs in an adb shell directly on the device or emulator and generates pseudo-random streams of user and system events. In comparison, the monkeyrunner tool controls devices and emulators from a workstation by sending specific commands and events from an API.

Using an interactive shell with appium and python

I'm writing automated tests for our Android and iOS apps and I was wondering if there was an interactive shell in python for appium where you can run the app you are testing against and query the screen for certain elements. I know you can use 'arc' in ruby that let's you query the screen on the device for certain elements, but I can't find anything similar for python.

Genymotion scripting

Is it possible to create some kind of scripting with Genymotion?
I know there is shell commands, but I also need to simulate user touch (using adb input).
The idea is to create some simple test for my app, where the script will execute certain shell commands and adb as well.
Thanks
As Genymotion VMs are considered as a physical device by ADB, you can use MonkeyRunner.
This tool, provided by Google allows you to send touches events among other things.
You can script, using Python many inputs. Look at this gist, coming from this StackOverflow post, it gives good example for a complete gesture.

Android command list

I have many questions about Android command. I do not know where I should start But, anyway, I have put all question related Android commands. Here ;
Is subset of Linux commands come in Android by default ? Or, Are we installing something ?
In system/bin, there are lots of commands. Where can I find their meaning ? I have tried man, but man is not built in.
Can I start and stop application via start and stop command ?
Why cannot I run the reboot from terminal emulator ? The error permission is denied.
NOTE : feel free to reedit the question, if you see meaningless part.
Is subset of Linux commands come in Android by default ? Or, Are we installing something ?
A subset exists by default within the system. Things like ls, cd, mkdir, cat etc... are present. You can gain access to a wider range by installing Busy Box on a rooted device, as stated by Zac.
In system/bin, there are lots of commands. Where can I find their meaning ? I have tried man, but man is not built in.
The ADB Page is a good place to start. That covers many of the basic ADB and shell commands. It states near the bottom:
"For a complete list of commands and programs, start an emulator instance and use the adb -help command."
So you can use adb -help on an emualator or device to see a full list of the ADB and shell commands (note I think this list will be android specific commands only, it won't include things like cd,ls and other basic unix commands).
Can I start and stop application via start and stop command ?
No, it states on the ADB dev page:
start ........ Starts (restarts) an emulator/device instance.
stop ........ Stops execution of an emulator/device instance.
To start an application you'll use the am utility iirc it will look something like am start com.your.packagename It's been a while though, I might have syntax wrong. The instructions are listend if you issue the am command by itself with no params in a shell.
Why cannot I run the reboot from terminal emulator ? The error permission is denied.
The system prevents applications from rebooting the device unless they are signed with the same key as the OS. When you use the terminal emulator you are restricted to whatever permissions that application has declared. The reboot permission is not granted to any third party applications, so it won't work correctly from any terminals. You could probably do it if your device was rooted and you used su though
EDIT:
Here is another good resource that lists more of the shell commands
There are not many Linux commands included in android, however if you are rooted you can easily install busybox which has a large range of linux commands.
You need to have root access to reboot your device via the command line (to prevent any old app being able to do it)

Categories

Resources