{"action":"created","issue":{"url":"https://api.github.com/repos/getgauge/gauge/issues/143","labels_url":"https://api.github.com/repos/getgauge/gauge/issues/143/labels{/name}","comments_url":"https://api.github.com/repos/getgauge/gauge/issues/143/comments","events_url":"https://api.github.com/repos/getgauge/gauge/issues/143/events","html_url":"https://github.com/getgauge/gauge/issues/143","id":75928203,"number":143,"title":"@AfterSpec creates new object, instead of reusing the object that was used for @Step and @BeforeSpec, losing state","user":{"login":"timhurkmans","id":6498828,"avatar_url":"https://avatars.githubusercontent.com/u/6498828?v=3","gravatar_id":"","url":"https://api.github.com/users/timhurkmans","html_url":"https://github.com/timhurkmans","followers_url":"https://api.github.com/users/timhurkmans/followers","following_url":"https://api.github.com/users/timhurkmans/following{/other_user}","gists_url":"https://api.github.com/users/timhurkmans/gists{/gist_id}","starred_url":"https://api.github.com/users/timhurkmans/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timhurkmans/subscriptions","organizations_url":"https://api.github.com/users/timhurkmans/orgs","repos_url":"https://api.github.com/users/timhurkmans/repos","events_url":"https://api.github.com/users/timhurkmans/events{/privacy}","received_events_url":"https://api.github.com/users/timhurkmans/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-13T10:04:35Z","updated_at":"2015-05-13T11:25:04Z","closed_at":null,"body":"When running @BeforeSpec and @AfterSpec, a new object is constructed for both @BeforeSpec __and__ @AfterSpec methods. This is unexpected as the state is preserved when calling @BeforeSpec and @Step, but a new state is created for the @AfterSpec call.\r\n\r\nFix would be to make sure that during @AfterSpec the original object/state is reused, instead of a new object/state being created.\r\n\r\nMy use case: @BeforeSpec: create Selenium WebDriver, @AfterSpec: close WebDriver. This way a new browser is created for each spec.\r\n\r\nOutput:\r\n\r\n\t[INFO] --- gauge-maven-plugin:1.0.1:execute (default) @ afterSpecTest ---\r\n\tMyTestSpec\r\n\t==========\r\n\tConstructing new TestImplementation object\r\n\tRunning BeforeSpec\r\n\t\r\n\tTest Scenario\r\n\t-------------\r\n\t←[0;34;49m* MyTestStep\r\n\t←[0mRunning TestStep\r\n\t←[2A←[0;32;49m* MyTestStep\r\n\t←[0m←[2BConstructing new TestImplementation object\r\n\tRunning AfterSpec\r\n\t[Html Report Plugin] : Sucessfully generated html reports to => [..some path..]\r\n\t11:54:05.025 [INFO] 1 scenarios executed, 0 failed\r\n\r\nSpec file:\r\n\r\n\tMyTestSpec\r\n\t=====================\r\n\tThe implementation class TestImplementation has the @Step MyTestStep, \r\n\tand implementations for @BeforeSpec and @AfterSpec. When @AfterSpec is \r\n\texecuted, a new TestImplementation object is created, which is unexpected.\r\n\t\r\n\tTest Scenario\r\n\t--------------\r\n\t* MyTestStep\r\n\r\n\r\nImplementation file\r\n\r\n\tpublic class TestImplementation {\r\n\t\tpublic TestImplementation() {\r\n\t\t\tSystem.out.println(\"Constructing new TestImplementation object\");\r\n\t\t}\r\n\t\r\n\t\t@BeforeSpec\r\n\t\tpublic void setUp(SpecificationInfo info) {\r\n\t\t\tSystem.out.println(\"Running BeforeSpec\");\r\n\t\t}\r\n\t\r\n\t\t@AfterSpec\r\n\t\tpublic void tearDown(SpecificationInfo info) {\r\n\t\t\tSystem.out.println(\"Running AfterSpec\");\r\n\t\t}\r\n\t\r\n\t\t@Step(\"MyTestStep\")\r\n\t\tpublic void testStep() {\r\n\t\t\tSystem.out.println(\"Running TestStep\");\r\n\t\t}\r\n\t}\r\n"},"comment":{"url":"https://api.github.com/repos/getgauge/gauge/issues/comments/101631727","html_url":"https://github.com/getgauge/gauge/issues/143#issuecomment-101631727","issue_url":"https://api.github.com/repos/getgauge/gauge/issues/143","id":101631727,"user":{"login":"ApoorvaM","id":8859725,"avatar_url":"https://avatars.githubusercontent.com/u/8859725?v=3","gravatar_id":"","url":"https://api.github.com/users/ApoorvaM","html_url":"https://github.com/ApoorvaM","followers_url":"https://api.github.com/users/ApoorvaM/followers","following_url":"https://api.github.com/users/ApoorvaM/following{/other_user}","gists_url":"https://api.github.com/users/ApoorvaM/gists{/gist_id}","starred_url":"https://api.github.com/users/ApoorvaM/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ApoorvaM/subscriptions","organizations_url":"https://api.github.com/users/ApoorvaM/orgs","repos_url":"https://api.github.com/users/ApoorvaM/repos","events_url":"https://api.github.com/users/ApoorvaM/events{/privacy}","received_events_url":"https://api.github.com/users/ApoorvaM/received_events","type":"User","site_admin":false},"created_at":"2015-05-13T11:25:04Z","updated_at":"2015-05-13T11:25:04Z","body":"Gauge has a configuration to specify the level at which you want to clear the cache and use new objects. By default, this is at scenario level.\r\n\r\nIf you want it to be at specification level, you can set this property in PROJECT_ROOT/env/default/java.properties :\r\n```\r\ngauge_clear_state_level = spec\r\n```\r\nRefer [documentation](http://getgauge.io/documentation/user/current/test_code/java/configuration.html#gauge_clear_state_level) to see all the possible levels to clear cache."}}