{"id":19398537,"url":"https://github.com/sebaslogen/espresso-cucumber","last_synced_at":"2025-04-24T06:31:30.549Z","repository":{"id":32490220,"uuid":"36070742","full_name":"sebaslogen/espresso-cucumber","owner":"sebaslogen","description":"Library to test Android applications using Espresso test framework with cucumber BDD language and Spoon screenshots","archived":false,"fork":false,"pushed_at":"2015-09-10T22:11:37.000Z","size":10732,"stargazers_count":47,"open_issues_count":1,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-03T00:25:32.377Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebaslogen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-22T12:18:16.000Z","updated_at":"2024-07-27T12:47:41.000Z","dependencies_parsed_at":"2022-09-03T22:50:58.516Z","dependency_job_id":null,"html_url":"https://github.com/sebaslogen/espresso-cucumber","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebaslogen%2Fespresso-cucumber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebaslogen%2Fespresso-cucumber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebaslogen%2Fespresso-cucumber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebaslogen%2Fespresso-cucumber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebaslogen","download_url":"https://codeload.github.com/sebaslogen/espresso-cucumber/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250578094,"owners_count":21453240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T11:06:21.354Z","updated_at":"2025-04-24T06:31:29.726Z","avatar_url":"https://github.com/sebaslogen.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Espresso + Cucumber + Spoon\n\nLibrary to test Android applications using Espresso **test framework with cucumber BDD language and Spoon screenshots**.\n\nThe objective of this library is to enable UI testing with access to application internals through JUnit while expressed in a natural English language and supported by screenshots when required.\n\nThis library is created for use with Eclipse and/or with Ant, to use in Android Studio or with gradle I recommend using gradle version management to fetch libraries from the maven repositories.\n\n**Sample test execution report**\n![test execution report image](https://raw.githubusercontent.com/neoranga55/espresso-cucumber/master/report-sample.png)\n\n\n## Espresso\n\nAndroid test Instrumentation library created by Google to write concise, beautiful, and reliable Android UI tests\n\n**Key features**:\n+ Damn fast\n+ Less flaky tests (thanks to automatic synchronization with UI thread)\n+ Better code (clearner, shoter and more readable code) thanks to the use of hamcrest expressions\n+ Less bolierplate code (thanks mainly to the two points above you need less code to get the job done)\n\n#### Sample code\nSample to start an Activity, click a button and then check some text appears:\n```java\ngetActivity();\nonView(withText(\"Show text\")).perform(click());\nonView(withText(\"Expected text\").check(matches(isDisplayed()));\n```\n\n#### Links\n\nhttps://code.google.com/p/android-test-kit/wiki/Espresso\n\nhttps://code.google.com/p/android-test-kit/wiki/EspressoV2CheatSheet\n\n\n## Cucumber\n\n[BDD](http://en.wikipedia.org/wiki/Behavior-driven_development) or behavior-driven development allows developers and testers to write test code that is highly readable and can **turn the tests in the most up to date documentation of the application**.\n\nCucumber is a thin library that enables abstraction of Java code into BDD language.\n\n#### Sample code\nExample of Cucumber feature test (that could be designed in collaboration with product owner):\n```java\nFeature: First Run Wizard\n  Test the first run wizard flow when user starts the device for the first time\n  \n  Scenario: Happy flow to complete the first run wizard\n    Given I press \"United Kingdom\"\n    Then I see text \"Terms and Conditions\"\n```\n\nAnd the Java code to support it: \n```java\n@Given(\"^I press \\\"(.+)\\\"$\")\npublic void i_press_buttonText(final String buttonText) {\n    onView( withText( buttonText ) ).perform( click() );\n}\n \n@Given(\"^I see text \\\"(.+)\\\"$\")\npublic void i_see_text(final String text) {\n    onView( withText( text ) ).check( matches( isDisplayed() ) );\n}\n```\n\n#### Links\n\nhttps://cukes.info/ (Cucumber)\n\nhttps://github.com/cucumber/cucumber-jvm/\n\nhttps://github.com/masterthought/cucumber-reporting (Improved cucumber reporting)\n\nhttp://blog.czeczotka.com/2014/08/17/writing-cucumber-jvm-step-definitions/ (Advanced step definitions with regular expressions in Java-Cucumber)\n\nhttp://35qk152ejao6mi5pan29erbr9.wpengine.netdna-cdn.com/wp-content/uploads/2011/08/Cucumber-Regular-Expressions-Cheat-Sheet.pdf\n\n\n## Spoon\n\n[Spoon is a library](https://github.com/square/spoon) from Square to distribute tests across multiple devices but also to take screenshots of the running application.\n\nThe use integrated in this library is to **take screenshots automatically when a test fails** and to enable screenshots on demand. In addition, test cases can include screenshots on demand for debugging or inspection purposes.\n\n\n## Getting started\n\nThe code in this repository can be compiled and imported as a library in an Android test project to be used or modified.\n\nA faster method to bootstrap a test application is to use the script in this repository to automatically create a test project for your application using a template\n\n#### Bootstrapping a test project\nExecute script espresso.py to generate a new test project for your application.\nYou need to supply the package name of your application and the initially tested Activity, see below:\n```java\n./espresso.py -h\nusage: espresso.py [-h] [-d DESTINATION_PATH] [-p PROJECT_NAME] [-a ACTIVITY]\n                   action element package\n \nCreate test project with Cucumber and Espresso from template    \nFor Espresso library examples and documentation visit: https://code.google.com/p/android-test-kit/wiki/EspressoSamples\n \npositional arguments:\n  action                The action to perform (e.g. 'generate' or just 'g')\n  element               The element to perform the action (e.g. 'test' or just 't')\n  package               The package of the target application to test (e.g. com.tomtom.pnd.firstrunwizard)\n \noptional arguments:\n  -h, --help            show this help message and exit\n  -d DESTINATION_PATH, --destination-path DESTINATION_PATH\n                        Path inside which the test project will be created and placed (e.g. .../MyAppProject/test)\n  -p PROJECT_NAME, --project-name PROJECT_NAME\n                        Name of the project to test (last part of package name is used by default)\n  -a ACTIVITY, --default-activity ACTIVITY\n                        Name of the main activity to test (test will instrument this activity as starting point, e.g. HomeActivity)\n```\n\nExample to generate a test from example application 'DemoApp':\n```java\ncd espresso-test-lib\n./espresso.py g t com.tomtom.pnd.demo -p DemoApp -a DemoActivity -d ../../pndapps/Apps/DemoApp/test\n```\n\n## Running a test\n\nThe execution follows the same procedure as any [Android instrumentation test](http://developer.android.com/tools/testing/testing_android.html) with this basic two steps:\n\n1. Compile and install test project (this should automatically compile the application the you're going to test)\n2. Execute Android instrumentation from command line using ADB.\nExample: `adb shell am instrument -r -w com.tomtom.pnd.firstrunwizard.test/com.tomtom.espresso.test.EspressoInstrumentation`\n\nMore information: http://www.kandroid.org/online-pdk/guide/instrumentation_testing.html\n\n\n## Technical details of mixing Espresso and Cucumber\n\nThe integration happens in the **[EspressoInstrumentation](https://github.com/neoranga55/espresso-cucumber/blob/master/espresso-test-lib/EspressoInstrumentation/src/com/tomtom/espresso/test/EspressoInstrumentation.java) class**, this is where the **AndroidJUnitRunner** Instrumentation needs to be extended to add Cucumber features. By creating a **CucumberInstrumentationCore** object and providing the bundle to this object, Cucumber can start the tests and take control of the testing flow when the test instrumentation is started.\n\nFinally, the configuration file that selects which test definition classes will be used and which feature files will be executed is defined in a class with the tag `@RunWith(Cucumber.class)`. There is a nice and simple example in the  **[RunCucumberTest](https://github.com/neoranga55/espresso-cucumber/blob/master/sample-test-project/FirstRunWizardEspressoTest/src/java/com/tomtom/pnd/firstrunwizard/test/RunCucumberTest.java)** class.\n\n_Warning: The combination of Espresso and Cucumber could produce a horrible taste on human beings, please consider  applying it only to Androids._\n\n\n## Licenses\n\nThis library was produced internally at TomTom but is released under Apache license 2.0\n\n- Espresso: Apache 2.0 https://code.google.com/p/android-test-kit/\n- Cucumber: https://github.com/cucumber/cucumber-jvm/blob/master/LICENCE\n- Spoon: Apache 2.0 https://github.com/square/spoon/blob/master/LICENSE.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebaslogen%2Fespresso-cucumber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebaslogen%2Fespresso-cucumber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebaslogen%2Fespresso-cucumber/lists"}