partnet / seauto

SeAuto is a bridge to Selenium from your favorite test framework.
Apache License 2.0
5 stars 1 forks source link

Where does Weld().initialize() need to get it's configuration? #9

Closed scottcsims closed 9 years ago

scottcsims commented 9 years ago

I am trying to wire up an existing project to use seauto-junit. Weld is failing to find my configuration.

I have a /src/test/resources/config.properties where else could weld be looking for configuration? This line is failing: private final WeldContainer weld = new Weld().initialize();

With this error: java.lang.RuntimeException: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

bbarke commented 9 years ago

Thanks for taking a look at SeAuto! I'm not able to reproduce your error locally, but just to be sure, do you have a /src/test/resources/META-INF/beans.xml? If you want to use the defaults, it should look similar to this: https://github.com/partnet/seauto/blob/master/seauto-junit/src/test/resources/META-INF/beans.xml But, even without beans.xml I get errors from Weld.

Weld shouldn't fail to init if it doesen't find the config.properties file, and it should run without it.

scottcsims commented 9 years ago

So you can't reproduce this locally? I added the bean file like you suggested but I did not have any success.

Here is some of my system information. Apache Maven 3.1.1 Java version: 1.8.0_31, vendor: Oracle Corporation Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"

Here is the stack trace:

org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions: Exception 0 : java.lang.RuntimeException: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:199) at com.sun.jersey.server.impl.cdi.CDIExtension.beforeBeanDiscovery(CDIExtension.java:300) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:267) at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137) at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:263) at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:164) at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:51) at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:154) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:245) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:233) at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:213) at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:75) at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:46) at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:46) at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:335) at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.startInitialization(ForwardingBootstrap.java:80) at org.jboss.weld.environment.se.Weld.initialize(Weld.java:134) at com.partnet.junit.SeAuto.(SeAuto.java:50) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283) at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128) at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103) Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350) at javax.naming.InitialContext.getNameParser(InitialContext.java:505) at com.sun.jersey.server.impl.cdi.CDIExtension.diveIntoJNDIContext(CDIExtension.java:267) at com.sun.jersey.server.impl.cdi.CDIExtension.createJerseyConfigJNDIContext(CDIExtension.java:276) at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:195) ... 39 more

at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:48)
at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:46)
at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:335)
at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.startInitialization(ForwardingBootstrap.java:80)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:134)
at com.partnet.junit.SeAuto.<init>(SeAuto.java:50)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
scottcsims commented 9 years ago

I found an article that says I need a jndi.properties file if I see "java.lang.RuntimeException: javax.naming.NoInitialContextException"

jndi.properties: java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

I added the file and I get a new errors.

org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [Producer Method [DriverProvider] with qualifiers [@Default @Any] declared as [[method] @Produces @Singleton public com.partnet.sample.config.selenium.DriverProviderProducer.getWebDriverProvider()], Producer Method [DriverProvider] with qualifiers [@Default @Any] declared as [[method] @Produces @Singleton public com.partnet.automation.selenium.DefaultDriverProviderProducer.getDriverProvider()]]

org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type [DriverProvider] with qualifiers [@Default] at injection point [[field] @Inject protected com.partnet.automation.page.SiteProvider.driverProvider]. Possible dependencies [[Producer Method [DriverProvider] with qualifiers [@Default @Any] declared as [[method] @Produces @Singleton public com.partnet.sample.config.selenium.DriverProviderProducer.getWebDriverProvider()], Producer Method [DriverProvider] with qualifiers [@Default @Any] declared as [[method] @Produces @Singleton public com.partnet.automation.selenium.DefaultDriverProviderProducer.getDriverProvider()]]]

bbarke commented 9 years ago

Great, glad you found a solution to your previous question

It looks like you have DriverProviderProducer from the sample project, AND the alternative defined in your beans.xml file.

Remove the DefaultDriverProviderProducer from your beans.xml or add @Alternative to your local DriverProviderProducer to use the default (https://github.com/partnet/seauto-junit-sample/blob/master/src/test/java/com/partnet/sample/config/selenium/DriverProviderProducer.java) or remove your local DriverProviderProducer.java from the project

scottcsims commented 9 years ago

Thanks for the help. I removed the bean and now I get this.

java.lang.NoSuchMethodError: org.junit.runners.BlockJUnit4ClassRunner.isIgnored(Lorg/junit/runners/model/FrameworkMethod;)Z at com.partnet.junit.SeAuto.runChild(SeAuto.java:73) at com.partnet.junit.SeAuto.runChild(SeAuto.java:42) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283) at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128) at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

bbarke commented 9 years ago

What version of JUnit are you using? Verify you are using the latest version of JUnit (4.12). isIgnored was introduced in v4.12. Previous versions don't have that method, i believe it was called something else

scottcsims commented 9 years ago

That was it, I was using JUnit v4.11 using v4.12 fixed the error. It is working now. Thank you!

bbarke commented 9 years ago

Awesome! Glad to hear it is working for you now! Feel free to ask more questions if/when you have them