How to integrate Cucumber with Appium for Mobile Application Automation under BDD?

Cucumber is a behavior driven development tool and I am going to use cucumber-jvm to kick-start the acceptance testing with Appium framework. Cucumber-jvm is nothing but the java implementation of cucumber in which it will support all the leading JVM languages right from Java, Scala, Groovy, Jython etc.

Cucumber feature will be used to frame the scenarios and the same scenarios will be automated by using the Appium framework and core java. Please note, cucumber will not trigger any user actions directly without the integration of any coding language.

Let us start the play in the below part;

  1. Please refer the Appium setup and configuration in the below URL;

https://gopekannan.wordpress.com/2015/08/26/how-to-automate-android-mobile-application-using-appium/

  1. Install the cucumber Eclipse plugin based on the below URl;

https://marketplace.eclipse.org/content/cucumber-jvm-eclipse-plugin

  1. Download the cucumber supported jar(latest version) based on the below URL or maven repository, New project should be created in Eclipse and mapped all downloaded jar in the Java build Path associated with the Eclipse;

cucumber-jvm-deps, cucumber-java, cucumber-core, cucumber-junit, cucumber-reporting, gherkin, junit, cobertura, mockito-all

https://oss.sonatype.org/content/repositories/releases/info/cukes/

BDD_1

Hope Environment is ready to get in to the cucumber BDD world;

  1. Create a new Java Project in Eclipse
  2. Create a new Folder and name the folder as ‘Feature’
  3. Create a new File under the Feature folder and name the file as ‘TestCuke.feature’(File name is your wish but Don’t forget to add the file extension as .feature)
  4. Now you are going to add the test scenarios in the newly created feature file as follows;

Feature: New User Signup Process

Scenario: Successful Signup with Valid details

Given User is on Signup screen

And User enters profile details

Then Signup completed and profile created successfully

Scenario: Successful logout process

When User Logout from the Mobile Application

Then Application home page should be displayed with Signup option

In the above statement, Signup process is a feature which is available in the mobile application and we are going to test that feature. Two scenarios has been mentioned in the above stance in which one scenario is signup should be completed with valid input parameters and the next scenario is to logout from the mobile application.

Under each scenario, test steps will be mentioned to trigger the user actions in accordance with the acceptance testing. Requirements has been clearly mentioned in the feature file in sake of scenarios and test steps. Business Analyst will be preparing the scenarios in respect to the customer requirements.

Finally requirement is ready in the feature file and now we should create a class file(mention the user-defined package name) to make the feature file to work or test the application.

BDD_4

public class Capabilities {

public static void deviceCapabilities() throws Exception
{
DesiredCapabilities capabilities = new DesiredCapabilities(“”, “”, Platform.ANY);
capabilities.setCapability(CapabilityType.BROWSER_NAME, ” “);
capabilities.setCapability(“deviceName”, “Motorola”);
capabilities.setCapability(“platformVersion”, “5.1”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“appPackage”, “packageName”);
capabilities.setCapability(“appActivity”,”ActivityName”);

try
{
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”),capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
}
}

We should mention the test step information such as Given/When/Then/And/But prior to the Java method, which is going to trigger certain action associated with the mobile application. All the Java code actions is going to be performed with the help of Appium framework and please refer the below link to create Appium based automation project;

https://gopekannan.wordpress.com/2015/08/26/how-to-automate-android-mobile-application-using-appium/

Given – Describes the preconditions and initial state before the start of a test and allows for any pre-test setup that may occur

When – Describes actions taken by a user during a test

Then – Describes the outcome resulting from actions taken in the When clause

And – Logical and

But – Logically the same as And, but used in the negative form

Now the Java class file is ready and now we are going to run the feature file specific to the Java based code file. Junit will come in to the picture and it’s going to help us in the forthcoming section; Junit will start to execute the scenarios available in the feature file and java class file.

Create a class file under the same package of the above Java class file; This file is going to handle the report section too.

package demoBDD;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features = “Feature”, glue={” demoBDD “},format = {“html:C:\\Users\\gkannan\\Documents\\Workspace\\AppiumDemo\\output” })
public class RunCukeTest {
}

Feature is going to represent the folder name and glue is nothing but the Java project package name. format is used for reporting purpose.

Everything is ready and you can run the Junit class file for seeing the automated acceptance testing using Cucumber, Appium with Core Java and Junit. Right click the Junit class file and click the Junit Test under the Run As option.

BDD_2

Another option to run the cucumber based feature file is just right click the feature file based on the below screenshot;

BDD_3

 

BDD_5

Run your script and Happy automation!!!

We can see the extensive html report customization for visualizing the test results in the next posting 🙂

 

3 thoughts on “How to integrate Cucumber with Appium for Mobile Application Automation under BDD?

  1. This is the good article. But I have one concern, How do we test this on AWS Device Farm ? I have developed Test project for Android using above mentioned process but unable to test this on AWS device farm ?

    Need help

    Like

Leave a comment