1 Aug 2012 08:19
Re: [Cucumber] [JVM] Not able to figure out the error with before hook
On Wed, Aug 1, 2012 at 6:32 AM, Bill Ross <ross@...> wrote: > On 7/31/2012 10:24 PM, Aslak Hellesøy wrote: > > > > > > On 1 Aug 2012, at 05:57, Yogesh Aggarwal <yogesh70.aggarwal@...> > wrote: > > > > On Wednesday, August 1, 2012 10:18:45 AM UTC+5:30, BillR wrote: >> >> >> >> On 7/31/2012 9:38 PM, Yogesh Aggarwal wrote: >> > Hi Aslak, >> > >> > I have the following before and after hooks in one of the classes: >> > >> > String CurrentMarket; >> > <at> Before >> > public void executehook(Scenario sc){ >> >> How is cucumber to know what to pass to these hooks? (Same with After.) >> I think the error is saying you can't have arguments to methods with >> these annotations. >> >> Bill > > > Hi Bill, > > This is a cucumber predefined that Before hook method must accept an object > of Scenario class and After hook an object of ScenarioResult class. > > > Why do you think Before takes a Scenario??? > > They both expext ScenarioResult or nothing. > > I'm surprised that a Before would take something named Result. As you saw, > I was misled by it. An alternative would be to rename ScenarioResult > ScenarioContext, to be temporally agnostic. > Although you _can_ declare a ScenarioResult method parameter in a Before block, it makes little sense to do so. As you point out, the scenario hasn't run yet. I'm tempted to only allow the After hooks accept a ScenarioResult parameter. Alternatively, Before hooks could accept a parameter like ScenarioContext (or perhaps better - ScenarioInfo) that exposes some read-only information and doesn't allow the user to do dangerous things that mutates internal state. Yogesh, I see you want to have access to tags. Can you create a github ticket for that please? Cheers, Aslak > Bill > > > Aslak > > Thanks! >> >> >> > >> > System.out.print("Inside Before Hook"); >> > >> > List<Tag> tags = sc.getTags(); >> > if(tags!=null){ >> > >> > CurrentMarket = tags.get(0).toString(); >> > } >> > >> > } >> > >> > >> > <at> After >> > public void close(ScenarioResult result) throws >> > FileNotFoundException{ >> > try { >> > File sc = this.getScreenshotAs(OutputType.FILE); >> > result.embed(new FileInputStream(sc), "image/png"); >> > } catch(WebDriverException e) { >> > System.err.println(e.getMessage()); >> > } finally { >> > super.close(); >> > } >> > } >> > >> > After hook works fine. >> > >> > But code always gives error while working with Before hook and due to >> > which test fails. What is the wrong in the above code? cucumber >> > version used is 1.0.8 >> > >> > cucumber.runtime.CucumberException: When a hook declares an argument >> > it must be of type cucumber.runtime.ScenarioResult. public void >> > >> > com.nextag.cucumber.search.INTL.ProductSortingOptionsStepDefs.executehook(gherkin.formatter.model.Scenario) >> > at >> > >> > cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:51) >> > at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:182) >> > at cucumber.runtime.Runtime.runHooks(Runtime.java:174) >> > at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:165) >> > at >> > cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:32) >> > at >> > cucumber.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:76) >> > at cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:65) >> > at cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:20) >> > at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) >> > at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) >> > at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) >> > at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) >> > at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) >> > at org.junit.runners.ParentRunner.run(ParentRunner.java:236) >> > at cucumber.junit.FeatureRunner.run(FeatureRunner.java:72) >> > at cucumber.junit.Cucumber.runChild(Cucumber.java:76) >> > at cucumber.junit.Cucumber.runChild(Cucumber.java:36) >> > at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) >> > at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) >> > at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) >> > at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) >> > at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) >> > at org.junit.runners.ParentRunner.run(ParentRunner.java:236) >> > at cucumber.junit.Cucumber.run(Cucumber.java:81) >> > at org.junit.runners.Suite.runChild(Suite.java:128) >> > at org.junit.runners.Suite.runChild(Suite.java:24) >> > at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) >> > at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) >> > at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) >> > at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) >> > at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) >> > at org.junit.runners.ParentRunner.run(ParentRunner.java:236) >> > at org.junit.runner.JUnitCore.run(JUnitCore.java:157) >> > at org.junit.runner.JUnitCore.run(JUnitCore.java:136) >> > at >> > >> > org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:62) >> > at >> > >> > org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:139) >> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> > at >> > >> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) >> > at >> > >> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) >> > at java.lang.reflect.Method.invoke(Method.java:597) >> > at >> > >> > org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) >> > at >> > >> > org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) >> > at >> > >> > org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) >> > at >> > >> > org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103) >> > at >> > org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74) >> > >> > cucumber.runtime.CucumberException: When a hook declares an argument >> > it must be of type cucumber.runtime.ScenarioResult. public void >> > >> > com.nextag.cucumber.search.INTL.ProductSortingOptionsStepDefs.executehook(gherkin.formatter.model.Scenario) >> > at >> > >> > cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:51) >> > at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:182) >> > at cucumber.runtime.Runtime.runHooks(Runtime.java:174) >> > at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:165) >> > at >> > cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:32) >> > at >> > cucumber.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:76) >> > at cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:65) >> > at cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:20) >> > at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) >> > at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) >> > -- >> > -- Rules -- >> > >> > 1) Please prefix the subject with [Ruby], [JVM] or [JS]. >> > 2) Please use interleaved answers >> > http://en.wikipedia.org/wiki/Posting_style#Interleaved_style >> > 3) If you have a question, don't reply to an existing message. Start a >> > new topic instead. >> > >> > You received this message because you are subscribed to the Google >> > Groups Cukes group. To post to this group, send email to >> > cukes@... To unsubscribe from this group, send email to >> > cukes+unsubscribe@... For more options, visit this group >> > at https://groups.google.com/d/forum/cukes?hl=en >> > >> > >> > -- > -- Rules -- > > 1) Please prefix the subject with [Ruby], [JVM] or [JS]. > 2) Please use interleaved answers > http://en.wikipedia.org/wiki/Posting_style#Interleaved_style > 3) If you have a question, don't reply to an existing message. Start a new > topic instead. > > You received this message because you are subscribed to the Google Groups > Cukes group. To post to this group, send email to cukes@... To > unsubscribe from this group, send email to > cukes+unsubscribe@... For more options, visit this group at > https://groups.google.com/d/forum/cukes?hl=en > > > > -- > -- Rules -- > > 1) Please prefix the subject with [Ruby], [JVM] or [JS]. > 2) Please use interleaved answers > http://en.wikipedia.org/wiki/Posting_style#Interleaved_style > 3) If you have a question, don't reply to an existing message. Start a new > topic instead. > > You received this message because you are subscribed to the Google Groups > Cukes group. To post to this group, send email to cukes@... To > unsubscribe from this group, send email to > cukes+unsubscribe@... For more options, visit this group at > https://groups.google.com/d/forum/cukes?hl=en > > > > > -- > -- Rules -- > > 1) Please prefix the subject with [Ruby], [JVM] or [JS]. > 2) Please use interleaved answers > http://en.wikipedia.org/wiki/Posting_style#Interleaved_style > 3) If you have a question, don't reply to an existing message. Start a new > topic instead. > > You received this message because you are subscribed to the Google Groups > Cukes group. To post to this group, send email to cukes@... To > unsubscribe from this group, send email to > cukes+unsubscribe@... For more options, visit this group at > https://groups.google.com/d/forum/cukes?hl=en > > -- -- -- Rules -- 1) Please prefix the subject with [Ruby], [JVM] or [JS]. 2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style 3) If you have a question, don't reply to an existing message. Start a new topic instead. You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes@... To unsubscribe from this group, send email to cukes+unsubscribe <at> googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
RSS Feed