0

I am trying to capture screenshot on iOS device when any of my test gets failed.

Problem statement : How to get behave scenario inside the after_step() method

Observed error :

HOOK-ERROR in after_step: TypeError: after_step() missing 1 required positional argument: 'scenario'

What I have tried :

  • Initialise one global variable and assign the current scenario name from method called before_scenario()
  • Diff methods provided by appium itself to perform screenshot action
  • Screenshot is being taken but from automation suit sometime multiple tests gets failed then we should have screenshot should have easily distinguishable name

Let me know if you came across such a scenario and found clean solution.

1 Answer 1

0

Working solution with python :

This screenshot functionality can be integrated independently. But recommended if you could add it under after step [BDD/Cucumber framework] would be most efficient :

directory = "documents/project_folder/screenshots/"
file_name = context.scenario.name + "__" + step.name + ".png"

context.driver.save_screenshot(directory + file_name)
  • scneario.name : Return name of currently executed scenario

  • step.name : Return name of currently executed BDD step

  • So even if from automation run includes 10 test and if 5 tests failed due to some reason you will be able to identify which failure for which test and at which step with actual screenshot.

  • This will help you and save time to reproduce in-order to resolve/fix the automation test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.