Skip to content

Scenario Context

amitmindstix edited this page Jul 16, 2018 · 1 revision

What is ScenarioContext? Why do we need it?

  • This class contains members of POM ie various page objects that need to be dealt with in the module's scenarios
  • This context serves as a scope that gets spawned and destroyed along with scenario.
  • Typically such context class holds a @Before and @After hooks with module specific tags for initialization and teardown for that module
  • Each test in a given module will need to have a constructor that takes this context instance as a single parameter.
  • The constructor based injection takes care of creating scenario context instance and making sure this is kept alive until scenario is executed.
  • Having access to this context from within the test class simplifies the test class - access to webdriver, access to various page objects is through this context class.
  • This concept can be compared to HttpSession or Spring's applicationContext
  • BaseScenarioContext gives basic common abilities like initializing the driver, taking screenshots on failure.
Clone this wiki locally