cucumber / cucumber-android

Android support for Cucumber-JVM
MIT License
135 stars 62 forks source link

Logic AND for Tags not working via gradle command #92

Closed duenes25 closed 1 year ago

duenes25 commented 3 years ago

Describe the bug I am trying to execute specific tests via CICD process using the following gradle command. ./gradlew :connectedCheck -Ptags="{@e2e,~@news}"

But I get the following error: io.cucumber.junit.CucumberJUnitRunnerBuilder > initializationError[Pixel_4_XL_API_30(AVD) - 11] FAILED cucumber.runtime.filter.TagExpressionOld$BadTagException: Bad tag: "{@e2e" at cucumber.runtime.filter.TagExpressionOld$TagExp.(TagExpressionOld.java:140)

To Reproduce I have many .feature files, and they all contain "@e2e" tag 10 of them also contains "@news" tag like so

File 1: `Feature: Module fragment is shown

@e2e
@module`

File 2: `Feature: News fragment is shown

@e2e
@news` 

Using: io.cucumber:cucumber-android:4.9.0

Here is my gradle configuration: android { debug { buildConfigField 'String', 'TEST_TAGS', '"' + getTestTags() + '"' } } def getTestTags() { project.getProperties().get('tags') ?: '' }

Here is my CucumberTestClass: @CucumberOptions(features = ["features"], glue = ["com.my.modules.steps"], tags = ["@e2e or @smoke or @ui or @module or @news"]) @SuppressWarnings("unused") class CucumberTestClass

Here is my CucumberTestRunner: class CucumberTestRunner : CucumberAndroidJUnitRunner(){ private val CUCUMBER_TAGS_KEY = "tags" override fun onCreate(bundle: Bundle) { val tags = BuildConfig.TEST_TAGS if (!tags.isEmpty()) { bundle.putString(CUCUMBER_TAGS_KEY, tags.replace("\\s".toRegex(), "")) } } }

Expected behavior I expect to run all the tests tagged with @e2e, except for the ones tagged with @news.

Desktop (please complete the following information):

Smartphone (please complete the following information):

lsuski commented 3 years ago

It seems to be not related with cucumber-android but with tag parser and probably (as you have some custom tag replacement logic) it is bug in this logic. In general tags are passed through instrumentation args. You passes {@e2e which is maybe wrong statement. Why do you use {. Check this https://cucumber.io/docs/cucumber/api/#running-a-subset-of-scenarios

arekolek commented 2 years ago

I was able to pass options through gradle command using -Pandroid.testInstrumentationRunnerArguments.tags=@e2e

See https://stackoverflow.com/a/72048944/1916449

adityaridha commented 2 years ago

I am able to pass the tags logic combination by processing the tags like below in the onCreate Method

    override fun onCreate(bundle: Bundle) {
        val tags = BuildConfig.TEST_TAGS
        var scenario = BuildConfig.TEST_SCENARIO

        if (tags.isNotEmpty()) {
            bundle.putString("tags", '"' + tags + '"')
        }

        super.onCreate(bundle)
    }

gradlew command

gradlew cAT -Ptags="@staging and not @exclude"