Green Coffee


Source link: https://github.com/mauriciotogneri/green-coffee

Green Coffee

Green Coffee is a library that allows you to run your acceptance tests written in Gherkin in your Android instrumentation tests using the step definitions that you declare. Visit the wiki for more detailed information.

Example

Given the following feature:

Feature: Login screen to authenticate users
Scenario: Invalid username and password

Given I see an empty login form

 When I introduce an invalid username

  And I introduce an invalid password

  And I press the login button

 Then I see an error message saying 'Invalid credentials'

First, create a class that extends from GreenCoffeeTest and declare the Activity, the feature and the step definitions that will be used:

@RunWith(Parameterized.class) public class LoginFeatureTest extends GreenCoffeeTest {

  @Rule
  public ActivityTestRule<LoginActivity> activity = new ActivityTestRule<>(LoginActivity.class);

public LoginFeatureTest(ScenarioConfig scenarioConfig)
  {

super(scenarioConfig);

  
}

@Parameters(name = "{
0
}
")
  public static Iterable<ScenarioConfig> scenarios() throws IOException
  {

return new GreenCoffeeConfig("testapp") // folder to place the screenshot if a test fails

 .withFeatureFromAssets("assets/login.feature")

 .scenarios(

  new Locale("en", "GB"),

  new Locale("es", "ES")

 );
 // the locales used to run the scenarios (optional)
  
}

@Test
  public void test()
  {

start(new LoginSteps());

  
}
 
}

Next, create a class containing the steps definitions:

public class LoginSteps extends GreenCoffeeSteps {

  @Given("^I see an empty login form$")
  public void iSeeAnEmptyLoginForm()
  {

onViewWithId(R.id.login_input_username).isEmpty();

onViewWithId(R.id.login_input_password).isEmpty();

  
}

@When("^I introduce an invalid username$")
  public void iIntroduceAnInvalidUsername()
  {

onViewWithId(R.id.login_input_username).type("guest");

  
}

@When("^I introduce an invalid password$")
  public void iIntroduceAnInvalidPassword()
  {

onViewWithId(R.id.login_input_password).type("1234");

  
}

@When("^I press the login button$")
  public void iPressTheLoginButton()
  {

onViewWithId(R.id.login_button_doLogin).click();

  
}

@Then("^I see an error message saying 'Invalid credentials'$")
  public void iSeeAnErrorMessageSayingInvalidCredentials()
  {

onViewWithText(R.string.login_credentials_error).isDisplayed();

  
}
 
}

And that's it, now you can create your own tests using Green Coffee. This is how it looks when you run a more complex test:

You can see an example applied to a full app here.

Installation

In order to use Green Coffee, add the following dependency to your build.gradle file:

dependencies {

  androidTestCompile 'com.android.support.test:runner:1.0.1'
  androidTestCompile 'com.mauriciotogneri:greencoffee:2.9.0' 
}

And the following test instrumentation runner:

defaultConfig {

  testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
}

License

MIT License  Copyright (c) 2017 Mauricio Togneri  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

Resources

An architecture for Android as a replacement of MVC.

A lightweight wrapper around realm-java which introduces reactive stream semantics to SQL operations.

Dexter is an Android library that simplifies the process of requesting permissions at runtime.

android-utils contains a lot of useful utility classes for Android development.

Character picker view.

A simple, yet powerful wrapper around the SupportMapFragment with support for clustering and built-in support for querying and rendering a Realm results.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes