Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling allureScreenshot on a different thread does not add attachment #64

Open
2 tasks
mattinger opened this issue Nov 12, 2021 · 1 comment
Open
2 tasks

Comments

@mattinger
Copy link

mattinger commented Nov 12, 2021

I'm submitting a ...

  • [ X] bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

What is the current behavior?

I am trying to monitor the destinations of my navController, and at each change in destination record an allure snapshot. The snapshot png files are produced in the allure-results directory. However, they are not referenced as attachments in the .json file. Instead i get an empty attachments array.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

The function i'm using to monitor the nav controller:

fun takeScreenshotOnNavigation(testName: String, navController: NavController): Job {
    val counter = AtomicInteger(0)
    return GlobalScope.launch(Dispatchers.IO) {
        navController.currentBackStackEntryFlow.collect {
            val screenshotName = "${testName}-${counter.getAndIncrement()}"
            allureScreenshot(name=screenshotName)
        }
    }
}

NOTE: I also tried addOnDestinationChangedListener and got the same behavior.

And calling it here in my espresso test:

scenario.onActivity { activity ->
    screenshotJob = takeScreenshotOnNavigation(this::class.java.simpleName + "-" + "testPowerBatteries", activity.navController)
}

but the only attachment i see in the json is the main one from the ScreenshotRule:

    "attachments": [
        {
            "source": "027b14c8-e997-43ca-8c2e-a389104e7d58-attachment.png",
            "name": "failure-screenshot",
            "type": "image/png"
        }
    ],

But the allure-results directory has all the screenshots in it.

What is the expected behavior?

I would expect these attachments to be record in the results.json file.

What is the motivation / use case for changing the behavior?

Automating screenshots on navigation events.

Please tell us about your environment:

Allure version 2.2.7
Test framework [email protected]
Allure integration [email protected]
@mattinger
Copy link
Author

I did figure out that this works a bit better using the above function.

fun <A: Activity> takeScreenshotOnNavigation(
    testName: String,
    scenario: ActivityScenario<A>,
    navControllerProvider: (A) -> NavController
): Job {
    lateinit var navController: NavController
    scenario.onActivity { activity ->
        navController = navControllerProvider(activity)
    }
    return takeScreenshotOnNavigation(testName, navController)
}

Presumably because i'm no longer starting the monitoring inside of the main thread (via scenario.onActivity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant