mauriciotogneri / green-coffee

Green Coffee
MIT License
231 stars 21 forks source link

Using grantPermission #17

Closed jocmp closed 6 years ago

jocmp commented 6 years ago

I have two questions regarding the grantPermission method:

  1. Where's the best place to put the initialization? Here's one place I thought of:

    override fun beforeScenarioStarts(scenario: Scenario?, locale: Locale?) {
        super.beforeScenarioStarts(scenario, locale)
        grantPermission("android.permission.ACCESS_FINE_LOCATION")
    }
  2. What strings are permitted? For instance, grantPermission calls executeShellCommand which takes a Manifest-permitted String for permission, contrasted against something like GrantPermissionRule which would take something along the lines of android.Manifest.permission.ACCESS_FINE_LOCATION.

mauriciotogneri commented 6 years ago

Hi @josiahcampbell,

I didn't know about the GrantPermissionRule. I will delete the method grantPermission in favor of the rule. I released a new version (3.2.1) with this change.

Thanks!

jocmp commented 6 years ago

Thanks for the response!

It's worth noting that I was able to get GrantPermissionRule working in my GreenCoffeeTest file:

@RunWith(Parameterized::class)
class SignUpTest(scenarioConfig: ScenarioConfig) : GreenCoffeeTest(scenarioConfig) {
    @get:Rule
    val activity = ActivityTestRule(LoginActivity::class.java)
    @get:Rule
    val grantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION);

    @Test
    fun test() {
        start(SignUpSteps())
    }

    companion object {
        @Parameters(name = "{0}")
        @JvmStatic
        fun scenarios(): Iterable<ScenarioConfig> {
            return GreenCoffeeConfig()
                    .withFeatureFromAssets("assets/signup.feature")
                    .scenarios()
        }
    }
}