{"id":3595,"url":"https://github.com/mauriciotogneri/green-coffee","last_synced_at":"2025-08-03T20:32:48.207Z","repository":{"id":47922041,"uuid":"66268420","full_name":"mauriciotogneri/green-coffee","owner":"mauriciotogneri","description":"Green Coffee","archived":false,"fork":false,"pushed_at":"2021-02-15T21:14:24.000Z","size":325,"stargazers_count":231,"open_issues_count":1,"forks_count":21,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-08-16T14:34:47.963Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mauriciotogneri.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-22T11:52:37.000Z","updated_at":"2024-08-16T14:34:47.964Z","dependencies_parsed_at":"2022-08-12T14:20:12.261Z","dependency_job_id":null,"html_url":"https://github.com/mauriciotogneri/green-coffee","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauriciotogneri%2Fgreen-coffee","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauriciotogneri%2Fgreen-coffee/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauriciotogneri%2Fgreen-coffee/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauriciotogneri%2Fgreen-coffee/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mauriciotogneri","download_url":"https://codeload.github.com/mauriciotogneri/green-coffee/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228567009,"owners_count":17937983,"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-01-05T20:16:45.916Z","updated_at":"2024-12-07T05:30:41.038Z","avatar_url":"https://github.com/mauriciotogneri.png","language":"Java","funding_links":[],"categories":["Test","Libraries"],"sub_categories":["Testing"],"readme":"[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/mauriciotogneri/green-coffee/blob/master/LICENSE.md)\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-green--coffee-green.svg?style=true)](https://android-arsenal.com/details/1/4313)\n\n# Green Coffee\n**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](https://github.com/mauriciotogneri/green-coffee/wiki) for more detailed information.\n\n## Example\n\nGiven the following feature:\n\n```gherkin\nFeature: Login screen to authenticate users\n\n\tScenario: Invalid username and password\n        Given I see an empty login form\n         When I introduce an invalid username\n          And I introduce an invalid password\n          And I press the login button\n         Then I see an error message saying 'Invalid credentials'\n```\n\nFirst, create a class that extends from `GreenCoffeeTest` and declare the Activity, the feature and the step definitions that will be used:\n\n```java\n@RunWith(Parameterized.class)\npublic class LoginFeatureTest extends GreenCoffeeTest\n{\n    @Rule\n    public ActivityTestRule\u003cLoginActivity\u003e activity = new ActivityTestRule\u003c\u003e(LoginActivity.class);\n\n    public LoginFeatureTest(ScenarioConfig scenarioConfig)\n    {\n        super(scenarioConfig);\n    }\n\n    @Parameters(name = \"{0}\")\n    public static Iterable\u003cScenarioConfig\u003e scenarios() throws IOException\n    {\n        return new GreenCoffeeConfig()\n                        .withFeatureFromAssets(\"assets/login.feature\")\n                        .takeScreenshotOnFail()\n                        .scenarios(\n                            new Locale(\"en\", \"GB\"),\n                            new Locale(\"es\", \"ES\")\n                        ); // the locales used to run the scenarios (optional)\n    }\n\n    @Test\n    public void test()\n    {\n        start(new LoginSteps());\n    }\n}\n```\n\nNext, create a class containing the steps definitions:\n\n```java\npublic class LoginSteps extends GreenCoffeeSteps\n{\n    @Given(\"^I see an empty login form$\")\n    public void iSeeAnEmptyLoginForm()\n    {\n        onViewWithId(R.id.login_input_username).isEmpty();\n        onViewWithId(R.id.login_input_password).isEmpty();\n    }\n\n    @When(\"^I introduce an invalid username$\")\n    public void iIntroduceAnInvalidUsername()\n    {\n        onViewWithId(R.id.login_input_username).type(\"guest\");\n    }\n\n    @When(\"^I introduce an invalid password$\")\n    public void iIntroduceAnInvalidPassword()\n    {\n        onViewWithId(R.id.login_input_password).type(\"1234\");\n    }\n\n    @When(\"^I press the login button$\")\n    public void iPressTheLoginButton()\n    {\n        onViewWithId(R.id.login_button_doLogin).click();\n    }\n\n    @Then(\"^I see an error message saying 'Invalid credentials'$\")\n    public void iSeeAnErrorMessageSayingInvalidCredentials()\n    {\n        onViewWithText(R.string.login_credentials_error).isDisplayed();\n    }\n}\n```\n\nAnd 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:\n\n![Example](http://i.imgur.com/4rMK1KK.gif)\n\nYou can see an example applied to a full app [here](https://github.com/vndly/green-coffee-example).\n\n## Installation\n\nAdd the following code to your root `build.gradle`:\n\n```groovy\nallprojects\n{\n    repositories\n    {\n        maven\n        {\n            url 'https://jitpack.io'\n        }\n    }\n}\n```\n\nAdd the following code to your module `build.gradle` file:\n\n```groovy\ndependencies\n{\n    androidTestImplementation 'androidx.test:runner:1.3.0'\n    androidTestImplementation 'androidx.test:rules:1.3.0'\n    androidTestImplementation 'com.github.mauriciotogneri:green-coffee:3.6.0'\n}\n```\n\nAnd the following test instrumentation runner:\n```groovy\ndefaultConfig\n{\n    testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauriciotogneri%2Fgreen-coffee","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmauriciotogneri%2Fgreen-coffee","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauriciotogneri%2Fgreen-coffee/lists"}