Gherkin BDD comparison

Hi guys, I will post a research about the BDD engines, it is a bit old (2012), but despite this I found very interesting. I have summarised the relevant informations. The actual language to write tests with BDD is called Gherkin. And it has different implementations adopted to different programming language, the most famous:

Cucumber for Ruby

JBehave for Java

NBehave and SpecFlow for C#

Freshen for Python Behat for PHP

All of them have some common set of supported features but there’re some restrictions and abilities specific to the actual engine. So, we will collect useful features for each listed above engine and present it in some comparable form. Key features to be mentioned are:

  • Documentation availability
  • Flexibility in passing parameters
  • Auto-complete
  • Steps, scenario and feature scoping
  • Complex steps
  • Hooks and pre-conditions
  • Binding to code
  • Formatting flexibility
  • Built-in reports
  • Input data sources support
Grade Criteria
0 No support at all
1 Functionality exists but with serious restrictions
2 Major functionality exists
3 Full-featured support

Documentation Availability

  • Cucumber:
    • Cucumber group on LinkedIn – quite populated place with big number of active discussions
    • Cukes Tutorial Site
  • Freshen – honestly speaking I didn’t find any specialized resourse dedicated to freshen only. Most likely it can be discussed in the more general forums dedicated to BDD in general.
  • JBehave:
  • SpecFlow:
  • Behat:


With this sources to look the documentation of each engine, we can evaluate the criteria and the grades:

GRADE CRITERIA
1 Documentation is available in general (it makes grade 1 at once)
2 Every feature is described and has examples (if it fits it makes grade 2)
3 There’re additional well-grown resources (forums, blogs, user groups) where we can find additional information about the engine

At the end we have:

Engine Documentation availability
Cucumber 3
Freshen 2
JBehave 3
NBehave 1
SpecFlow 3
Behat 3

Other grades:

Flexibility in passing parameters:

Engine Regular expressions support Tables support Multi-line input support Extra features
Cucumber 3 3 3 0
Freshen 3 3 3 0
JBehave 2 3 0 3
NBehave 2 3 0 2
SpecFlow 2 3 3 2
Behat 3 3 3 0

Auto-Complete:

Engine Auto-complete support
Cucumber 1
Freshen 1
JBehave 1
NBehave 1
SpecFlow 3
Behat 1

Step Scenario and feature scoping:

Engine Tagging support Scoped steps support
Cucumber 3 0
Freshen 3 0
JBehave 3 1
NBehave 0 0
SpecFlow 3 3
Behat 3 0

Complex Steps:

Engine Composite steps
Cucumber 3
Freshen 3
JBehave 3
NBehave 2
SpecFlow 2
Behat 3

Hooks and pre-conditions:

Engine Backgrounds Hooks
Cucumber 3 3
Freshen 3 3
JBehave 1 1
NBehave 0 1
SpecFlow 3 3
Behat 3 3

Binding Code:

Engine Binding to code
Cucumber 2
Freshen 3
JBehave 3
NBehave 3
SpecFlow 3
Behat 2

Formatting Flexibility:

Engine Formatting
Cucumber 3
Freshen 3
JBehave 1
NBehave 3
SpecFlow 3
Behat 3

Reports:

Engine Built-in reports
Cucumber 3
Freshen 2
JBehave 2
NBehave 2
SpecFlow 2
Behat 3

Input data sources support:

Engine External Data Inclusions
Cucumber 0 0
Freshen 2 3
JBehave 3 2
NBehave 0 0
SpecFlow 0 0
Behat 0 0

Conclusion:

Table


Source
http://mkolisnyk.blogspot.co.uk/2012/06/gherkin-bdd-engines-comparison.html

Create xml with shell script

Hi guys,

Today I will post a shell script that I am using to test a webservice. If you need a xml to test the performance of the server/webservice with Jmeter or if you just need generate a lot of xmls to make any type of test, this example can be useful.

In this code you can generate xmls and change some tags as id, date, etc…

#!/bin/bash
# Written by rafazzevedo
# http://www.azevedorafaela.wordpress.com

defaultpath="/User/" #Change this for the path where you want the files stay

echo "What do you want generate ?"
read element

echo "How many files ?"
read filescount
#Creating the subdirectory for each element and removing the existing folder
if [ ! -d $element ]
then
mkdir "$element"
else
rm -r "$element"
mkdir "$element"
fi

defaultpath=$defaultpath$element/

dateformat=$(date +"%m/%d/%YT%H:%M:%S")

for (( i=0;i<$filescount;i++ )) do

exec 3>temp.xml #Creating temporary file

#HEADER (Common for all xmls)
echo '&3'
echo ' xmlns:cpi="http://xml.wordpress.co.uk/types" >' >&3
echo " http://localhost:9999/$element$i" >&3
echo ' Title' >&3
echo " $dateformat" >&3
echo ' ' >&3
echo ' Rafaela Azevedo' >&3
echo ' http://wordpress.com/img.png' >&3
echo ' rafazzevedo@gmail.co.uk' >&3
echo " " >&3

#SPECIFIC TAGS OF EACH ELEMENT
case $element in

'article')
echo ' Content Test' >&3
echo ' ' >&3
;;

'image')
echo '' >&3
echo ' http://weather.gov/images/xml_logo.gif' >&3
echo ' NOAAs National Weather Service' >&3
echo ' http://weather.gov' >&3
echo '' >&3
;;

esac

echo '' >&3
cp ./temp.xml ${element}/$element-$i.xml #Copying the temporary files
rm ./temp.xml #Removing the temp files

done

echo "Created xml files"


It is helping me a lot lately , I do not need spend a lot of time doing some complex code or generate these files manually. I hope this helps you too .

If you have any suggestion or question, write a comment bellow 🙂

Thank you guys !

Java Reflection – Brief Tutorial

Hi guys, I will write simplified about Java reflection and how you can access with constructors, interfaces, super class, etc…

Java reflection it is useful to instantiate new objects, invoke methods and get/set field values without knowing the names of the classes/methods… and when you want to inspect classes, interfaces, fields and methods at runtime. It is used to examine and modify the structure and code in the same system at runtime.

For example, say you have an object of an unknown type in Java, and you would like to call a ‘doSomething’ method on it if one exists. Java’s static typing system isn’t really designed to support this unless the object conforms to a known interface, but using reflection, your code can look at the object and find out if it has a method called ‘doSomething’ and then call it if you want to.

   Method[] methods = MyObject.class.getMethods();

   for(Method method : methods){
      System.out.println("method = " + method.getName());
   }

What is happening here? It is obtaining the Class object from the class called MyObject, it is using the class object to get a list of methods in this class and print out their names.

From the classes you can obtain information about

  • Class Name
  • Class Modifies (public, private, synchronized etc.)
  • Package Info
  • Superclass
  • Implemented Interfaces
  • Constructors
  • Methods
  • Fields
  • Annotations

For a full list you should consult the JavaDoc for java.lang.Class.

Class Object

First you need obtain the object. If you know the name:

    Class myObjectClass = MyObject.class

If you don’t know the name at compile time:

    String className = ... //obtain class name as string at runtime Class class = Class.forName(className);

Class Name

To obtain the class name, you can try both:

    Class aClass = ... //obtain Class object, as above
    String className = aClass.getName();

If you want only the name without the package:

    Class  aClass          = ... //obtain Class object. See prev. section
    String simpleClassName = aClass.getSimpleName();

Modifiers

To obtain the class modifiers:

 Class  aClass = ... //obtain Class object, as above
 int modifiers = aClass.getModifiers();

The modifiers are packed into an int, you can use the methods with java.lang.reflect.Modifier:

    Modifier.isAbstract(int modifiers)
    Modifier.isFinal(int modifiers)
    Modifier.isInterface(int modifiers)
    Modifier.isNative(int modifiers)
    Modifier.isPrivate(int modifiers)
    Modifier.isProtected(int modifiers)
    Modifier.isPublic(int modifiers)
    Modifier.isStatic(int modifiers)
    Modifier.isStrict(int modifiers)
    Modifier.isSynchronized(int modifiers)
    Modifier.isTransient(int modifiers)
    Modifier.isVolatile(int modifiers)

Package Info

With the package you can have a look in the Manifest of the JAR and others.

   Class  aClass = ... //obtain Class object, as above
   Package package = aClass.getPackage();

Superclass

You can use:

  Class superclass = aClass.getSuperclass();

Interfaces

To get a list of interfaces you can use:

   Class  aClass = ... //obtain Class object, as above
   Class[] interfaces = aClass.getInterfaces();

If you need the complete list of interfaces, you will need to consult both class and superclasses recursively.

Constructors

To access constructors:

 Constructor[] constructors = aClass.getConstructors();

Methods

To access methods:

 Method[] method = aClass.getMethods();

Fields

 Field[] method = aClass.getFields();

Annotations

 Annotation[] annotations = aClass.getAnnotations();

 

You can find more details about the reflection in each constructor, annotations. fields in this tutorial. This was only a brief post to get start to use.

Examples of java reflection: http://docs.oracle.com/javase/tutorial/reflect/index.html

 

Source: http://tutorials.jenkov.com/java-reflection/classes.html

http://stackoverflow.com/questions/37628/what-is-reflection-and-why-is-it-useful

Do you want to test/learn how to do automation in Hybrid apps ?

Hello again,

Today I will post 2 projects ios and android, a sample of Hybrid app.

I found this sample project to you download and start do test calabash with them.

Example Hybrid Apphttps://github.com/moovweb-demos/igadget-phonegap

– After download them, you can follow some instructions to install:

https://azevedorafaela.wordpress.com/2013/12/19/cucumber-and-calabash-ios-automation/

&

https://azevedorafaela.wordpress.com/2014/07/09/calabash-android-install-example-project/

– And to find elements inside the webviews:

https://azevedorafaela.wordpress.com/2014/07/28/summary-of-calabash-ios-ruby-api-query/

Just download them and start do/learn automation in hybrid apps 🙂

Thank you, see you next week guys !

Using different emulators with Chrome in C#

Hi guys, Today I will post a sample code that you can use to test different screens/mobile devices/browsers using Google Chrome browser with C#. You will need change the bold words for the devices and sizes that you want to simulate.

private static ChromeOpt SetCapabilities()
{
Map chromeOptions = new HashMap();

DesiredCapabilities capabilities = DesiredCapabilities.chrome();  capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);


switch (whichCase) {


case "byDevice":
Map mobileEmulation = new HashMap();
mobileEmulation.put("deviceName", "Apple iPhone 4"); //Should be the same name showing in the Chrome Device Emulator
chromeOptions.put("mobileEmulation", mobileEmulation);
break;

case "CustomScreen":
Map deviceMetrics = new HashMap();
deviceMetrics.put("width", 900);
deviceMetrics.put("height", 600);
deviceMetrics.put("pixelRatio", 3.0);


Map mobileEmulation = new HashMap();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent", "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19");
chromeOptions.put("mobileEmulation", mobileEmulation);


break;

}

}
IWebDriver driver =new ChromeDriver(capabilities);
return driver;
}

You can look the list of user agents here:

http://www.useragentstring.com/pages/useragentstring.php

If you have any thoughts/suggestions please leave your comment here 🙂

Thank you guys !

How to install SafariLauncher to run appium ?

Hi guys,

I am going to write about “How you can install the framework of safari to run appium tests”. If you need run tests in safari of real devices with Appium, you can use this framework for ios devices (Android it is more easier as always). So, you need to have an apple developer account.

-> Plug your device

-> Git clone this project: https://github.com/budhash/SafariLauncher

-> Add your device in your developer apple register.

https://developer.apple.com/account/ios/device/deviceList.action

-> Download your certificate and your mobile provisioning profile after

https://developer.apple.com/account/ios/certificate/certificateList.action

&

https://developer.apple.com/account/ios/profile/profileList.action

-> Install your mobile provision in your device (or double touch on the file)

-> Put in blundle id com.safariLauncher.safariLauncher -> inside of the general properties of the project

-> Check if you are deploying in the right version of ios.

-> Run the project

-> Don’t forget to set the capabilities in your automation project:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appium-version", "1.3.1");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName", "Tahir's iPhone");
capabilities.setCapability("udid", "your_udid");
capabilities.setCapability("bundleId", bundle);
capabilities.setCapability("browserName", "safari");
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);    

driver.get("http://www.google.com");
Thread.sleep(20000);

Once you have deployed the safari launcher to the device, everything should be configured correctly so that the next time you run ./reset.sh on appium, the installation of the safari launcher app should succeed.

See you next week !

How choose the order of the browsers that I will be testing ?

By testing your web application using a variety of web browser types, you better emulate the UI experience of your users who may run different browsers. For example, your application might include a control or code in Internet Explorer that is not compatible with other web browsers. By running your coded UI tests across other browsers, you can discover and correct any issue before it impacts your customers.

To discover what is the priority that you should test the browsers is simple, but you have a lot of points to worry.

– Hardware differences

– Monitor resolution settings

– Browser and computer preferences

Usage of each browser 

What is the time that you have ?

When you will be the release ?

 

top 10 browsers to test?

  1. Chrome 39
  2. Internet Explorer 11
  3. Firefox 35
  4. Internet Explorer 10
  5. Chrome 38

 

Usage share of desktop browsers for December 2014
Source Chrome Internet
Explorer
Firefox Safari Opera Other
Stat Counter 49.7% 24.6% 18.0% 4.7% 1.5% 1.6%
W3Counter 42.5% 17.6% 15.6% 14.6% 3.2% 6.5%
Wikimedia 48.1% 17.5% 16.7% 4.8% 1.5% 11.4%
Net Applications 22.7% 59.1% 11.9% 5.0% 0.9% 0.4%

 

How to measure the order of the browsers ?

The ideal is you focus in the most usage browser first and after you can think about the others. So, let’s imagine that you have 4 weeks to test all browsers and you take 1 week to test all the scenarios in one browser. You need to choose the first week to test in the most used browser for your end user, and the second week for the second most used and so on.

This is the ideal in the most of cases, but of course everything depends of how many people you have to help you with the tests, the date of the release, and the other points I already told.

 StatCounter-browser-ww-monthly-200807-201412

 

 

 

 

 

 

 

Tips: 

– Don’t Overestimate neither Underestimate a browser version.

– If you are looking for just mainstream use, StatCounter has a really nice graph to show you what browser you should test.

 

Tools & emulators that you can use:

  • The Browser Sandbox
  • BrowserShots.org
  • CrossBrowserTesting.com
  • SauseLabs

 

Thank you guys ! See you next week 🙂


Source
http://crossbrowsertesting.com/browsers-to-test/

http://en.wikipedia.org/wiki/Usage_share_of_web_browsers

https://msdn.microsoft.com/en-us/library/jj835758.aspx

http://www.digitalfamily.com/tutorials/test-your-website-in-differen-web-browsers/

http://gs.statcounter.com/#desktop-browser-ww-monthly-200807-201412

Basics gestures for calabash-android

Hi guys, today I will post just some basics and very basics commands from the Calabash android API (0.5.5):

– tap_mark(“query”)

– touch(“query”)

– double_tap(“query”)

– perform_action(“touch_coordinate”, center_x, center_y)

– perform_action(“double_tap_coordinate”, center_x, center_y)

– long_press(“query”, options)

– drag (“query”)

– pan_left(options)

– pan_right(options)

– pan_up(options)

– pan_down(options)

– pan (“query”)

– flick_left (options)

– flick_right (options)

– flick_up (options)

– flick_down (options)

– flick (“query”)

– flash(“query”)

– pinch_out (options)

– pinch_in (options)

– pinch (“query”)

– find_coordinate (“query”)

– tap_when_element_exists (“query”)

– long_press_when_element_exists (“query”)

– query_result? (“query”)

 

See you on Wednesday !

Font: https://github.com/calabash/calabash-android/blob/master/ruby-gem/lib/calabash-android/touch_helpers.rb

What is the difference between an interface and abstract class?

Hi guys, I am without internet in my house until 19th 😦
Because of this, I will post some interesting things, but nothing that I wrote. (Because I am without time/internet). Sorry, for this !

Interface

An interface is a contract: the guy writing the interface says, “hey, I accept things looking that way“, and the guy using the interface says “OK, the class I write looks that way“.

An interface is an empty shell, there are only the signatures (name / params / return type) of the methods. The methods do not contain anything. The interface can’t do anything. It’s just a pattern.

E.G (pseudo code):

// I say all motor vehicles should look like this:
interface MotorVehicle
{
void run();


int getFuel();
}

// my team mate complies and writes vehicle looking that way
class Car implements MotorVehicle
{


int fuel;


void run()
{


print("Wrroooooooom");
}


int getFuel()
{
return this.fuel;
}
}

Implementing an interface consumes very little CPU, because it’s not a class, just a bunch of names, and therefore there is no expensive look-up to do. It’s great when it matters such as in embedded devices.

Abstract classes

Abstract classes, unlike interfaces, are classes. They are more expensive to use because there is a look-up to do when you inherit from them.

Abstract classes look a lot like interfaces, but they have something more : you can define a behavior for them. It’s more about a guy saying, “these classes should look like that, and they have that in common, so fill in the blanks!”.

e.g:

// I say all motor vehicles should look like this :
abstract class MotorVehicle
{

int fuel;

// they ALL have fuel, so why not let others implement this?
// let's make it for everybody


int getFuel()
{

return this.fuel;
}


// that can be very different, force them to provide their
// implementation
abstract void run();

}

// my team mate complies and writes vehicle looking that way
class Car extends MotorVehicle
{
void run()
{
print("Wrroooooooom");
}
}

Implementation

While abstract classes and interfaces are supposed to be different concepts, the implementations make that statement sometimes untrue. Sometimes, they are not even what you think they are.

In Java, this rule is strongly enforced.

See you next week !

Font: http://stackoverflow.com/questions/1913098/what-is-the-difference-between-an-interface-and-abstract-class