android


How do I use same Cucumber step definitions for android and iOS


I'm currently beginning an automation project for an app that is identical in flow and design for both Android and iOS. I'm using Ruby with the Cucumber framework.
I have begun automating Android and essentially what I need to do is each step definition to have separate code for android and ios kind of like this pseudo-code:
Then (/^I click the Login Button$/) do
if mobile_platform = android
#android locators and code here
else
#iOS locators and code here
end
end
How would I go about setting up my project to allow for such specific step definition usage?
Is it better to have separate feature and step definitions for each OS instead of trying to meld them together?
Thanks for any and all help you can give me.
Given the commonality between the apps, it makes sense to share the feature files. A clean way to manage the platform-specific step_definitions is to keep them in separate directories.
Take the following simple example project.
You can switch between the alternative step definition folders using the cucumber -r (require) option like so:
cucumber -r features/step_definitions_android -r features/support
Note that automatic loading is disabled as soon as you use the -r option, hence why you need to explicitly include the second require to pull any code you have in the features/support folder.
To make it easy to run against the alternative targets, you can create corresponding profiles:
# cucumber.yaml
android: -r features/step_definitions_android -r features/support
ios: -r features/step_definitions_ios -r features/support
As you can see below, when each of these profiles are run, the relevant platform-specific step definitions are invoked.
I would not go for separate feature files for different operating system. You want your application to behave the same way independent of the operating system. Chances are that your features will diverge if you have two of them.
My approach would be to do two execution and separate the target environments down in the stack. I would use an environment variable to indicate which operating system I'm currently targeting.
The code that will execute something on the particular environment will be very different so I would use a factory to select the current implementation to use. I would not consider separating the execution using multiple conditions in the code as your small example suggest. The only place where I would have a condition of that type would be in the factory method that creates the actual class that will use your application.
You should go with single feature file having no dependency on any O.S.
If you found any such case where you have to separate out operation depending on O.S you have add checks for it.Like you shown above
if mobile_platform = android
#android locators and code here
else
#iOS locators and code here
But 95% of your code should work for both the O.S.
Why don't you add a line to the cucumber.yml that denotes whether you are using android or ios?
mobile_platform: 'android'
And in an environment file, you could do this:
require 'yaml'
cucumber_options = YAML.load_file('cucumber.yml')
$mobile_platform = cucumber_options['mobile_platform']
And then in your step definition files, you can start doing this:
Then (/^I click the Login Button$/) do
if $mobile_platform = 'android'
#android locators and code here
else
#iOS locators and code here
end
end
As Thomas says the key to make this simple is to push things down the stack. To do this you need to apply a simple pattern with quite alot of discipline.
The pattern is to make each step definition implementation a single call to a helper method. Once you are in your helper methods then you can use techniques like using an environment variable, configuration or some conditional to choose implementation.
An example might clarify this. Lets say both apps have the capability to add a friend. When you first add this functionality you will have a step like
When 'I add a friend' do
fill_in first_name: 'Frieda'
fill_in last_name: 'Fish'
...
end
this needs to become
When 'I add a friend' do
add_friend name: 'Frieda'
end
implemented by
module FriendStepHelper
def add_friend( ...)
// Only start thinking about IOS or Android from here down.
...
end
end
Now this might seem a bit of a pain, but what you have done is remove this problem from the realm of Cucumber (which is not designed to deal with this sort of problem) and moved it into the realm of Ruby which certainly is designed to deal with this sort of problem.
Now you are in you programming language you can use all sorts of techniques to make applying your conditional elegant and simple e.g.
#use hungarian prefix's
def ios_add_friend
def droid_add_friend
#return early from os specific functions if wrong OS
def ios_add_friend
return if droid?
...
end
# run both implementations when they are different
def add_friend
ios_add_friend
droid_add_friend
end
# loads of other alternatives
...

Related Links

Creating an action on notification being pressed, Android
Alertdialog creating exception in android
How do I upload an unpublished app from my developer console to my device?
How can Theme.NoTitleBar inherit all attribues of Theme?
Method that is called after onResume?
ORMLite how to make this query?
Android - Tile Image Button
Fragment getItem method return only when download finished
When running 2 http AsyncTasks in parallel sometimes results are exchanged
Android map showing only grids not showing any map view
Http Response inside a service in Android
Can we parse an Xml file in android without using any Parsers or Api?
java.lang.OutOfMemoryError: bitmap size exceeds VM budget on line Drawable.createFromStream(((java.io.InputStream) new URL(url), “”) in android
How to call Web Service in OnCreate() android
How to acces android.provider.Telephony class?
Confusing android error [closed]

Categories

HOME
porting
design-patterns
android-studio-2.2
ns-3
fftw
socket.io
shiro
ms-access-2016
square
jetty
echo
jax-ws
boto3
title
qpython
google-schemas
octave
android-securityexception
java.util.logging
ycsb
gkturnbasedmatch
plink
3nf
android-intent
libusb
bitnami
standards
red5
google-content-api
pimcore
imageresizer
monit
comparator
ckfinder
syntax-highlighting
progress-bar
fractions
soot
android-things
volatile
code-snippets
instantiation
hibernate-search
pop3
alphabetical
amazon-ses
apns-php
cin
stringtokenizer
vmware-fusion
android-softkeyboard
logback-groovy
strftime
openal
jquery-ui-draggable
launchctl
backbone-collections
mathcad
shinobi
structuremap4
choice
smartfoxserver
rocks
cronexpression
atlas
grails-plugin
mongodb-php
mapinfo
tracker-enabled-dbcontext
createprocess
qbxml
ascii-art
rasterize
dynamics-nav-2016
iokit
rewrite
forwarding
google-books
telepat
entity-framework-4.3
rrule
ejb-2.x
showdialog
rickshaw
formview
wcm
universal-image-loader
angular-carousel
codeplex
rcaller
dct
menubar
jeromq
modular
bjyauthorize
onmousemove
qi4j
cakephp-1.2
josql
cross-database
procedures
w3c-geolocation
aspmenu
sifr
qtabbar
tui
linfu-dynamicproxy
unmanagedresources
lemmatization
change-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App