2014-05-19 1 views
0

Grails 2.3.7의 Geb-Spock 기능 테스트에서 HtmlUnitDriver를 사용하려고합니다. Maven을 사용하여 프로젝트를 빌드합니다. 나는이 드라이버를 사용하여 테스트를 실행하면종속성 문제로 인해 Geb-Spock Grails 테스트에서 HtmlUnitDriver를 사용할 수 없습니다.

내가 얻을 :

java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal 

은 내가이 오류가 생각 나는 xml-apis 제외했기 때문에 :

<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-htmlunit-driver</artifactId> 
    <version>2.41.0</version> 
    <scope>test</scope> 
    <exclusions> 
     <exclusion> 
      <groupId>xml-apis</groupId> 
      <artifactId>xml-apis</artifactId> 
     </exclusion> 
    </exclusions> 
</dependency> 

을하지만 내가해야 할 일을했을 때문에 그렇지 않으면 내가 maven을 실행하고 유닛 테스트가 시작될 때 에러가 발생합니다 :

Fatal error forking Grails JVM: java.lang.reflect.InvocationTargetException 
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException 
    at org.grails.launcher.GrailsLauncher.launch(GrailsLauncher.java:150) 
    at org.grails.maven.plugin.tools.ForkedGrailsRuntime.main(ForkedGrailsRuntime.java:168) 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.grails.launcher.GrailsLauncher.launch(GrailsLauncher.java:144) 
... 1 more 
Caused by: java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.tools.ant.helper.ProjectHelper2$RootHandler.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/grails/launcher/RootLoader) of the current class, org/apache/tools/ant/helper/ProjectHelper2$RootHandler, and its superclass loader (instance of <bootloader>), have different Class objects for the type andler.setDocumentLocator(Lorg/xml/sax/Locator;)V used in the signature 
at org.apache.tools.ant.helper.ProjectHelper2.parseUnknownElement(ProjectHelper2.java:131) 
at org.apache.tools.ant.helper.ProjectHelper2.parseAntlibDescriptor(ProjectHelper2.java:111) 
at org.apache.tools.ant.taskdefs.Antlib.createAntlib(Antlib.java:91) 
at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:440) 
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:292) 
at org.apache.tools.ant.ComponentHelper.checkNamespace(ComponentHelper.java:877) 
at org.apache.tools.ant.ComponentHelper.getDefinition(ComponentHelper.java:308) 
at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:285) 
at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:264) 
at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:417) 
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163) 
at groovy.util.AntBuilder.performTask(AntBuilder.java:314) 
at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:264) 
at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:147) 
at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:203) 
at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64) 
at org.codehaus.gant.GantBuilder.invokeMethod(GantBuilder.java:99) 
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45) 
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) 
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) 
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) 
at org.codehaus.gant.GantBinding.initializeGantBinding(GantBinding.groovy:108) 
at org.codehaus.gant.GantBinding.<init>(GantBinding.groovy:42) 
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeScriptWithCaching(GrailsScriptRunner.java:428) 
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.callPluginOrGrailsScript(GrailsScriptRunner.java:414) 
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeCommand(GrailsScriptRunner.java:378) 
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeCommand(GrailsScriptRunner.java:345) 
... 6 more 

그래서 저는 ' 어떤 종류의 의존성 문제. 하지만 어떻게 처리해야할지 모르겠습니다. 종속성 트리를 분석하려고했지만 누가 이걸 org/xml/sax/Locator 또는 org/w3c/dom/ElementTraversal을 원하는지 확인하는 방법을 모르겠습니다.

xalan 및 xerces와 마찬가지로 HtmlUnitDriver에서 xml-apis 이상을 제외하려고 시도했지만 도움이되지 않았습니다.

pom.xml은 다음과 같습니다

... 
<properties> 
    <grails.version>2.3.7</grails.version> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <h2.version>1.3.170</h2.version> 
    <gebVersion>0.7.2</gebVersion> 
    <seleniumVersion>2.41.0</seleniumVersion> 
    <spockVersion>0.7</spockVersion> 
    <gebSpockVersion>0.9.0-RC-1</gebSpockVersion> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-async</artifactId> 
     <version>${grails.version}</version> 
     <exclusions> 
      <exclusion> 
       <groupId>org.grails.plugins</groupId> 
       <artifactId>spock</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-rest</artifactId> 
     <version>${grails.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-services</artifactId> 
     <version>${grails.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-i18n</artifactId> 
     <version>${grails.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-databinding</artifactId> 
     <version>${grails.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-filters</artifactId> 
     <version>${grails.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-gsp</artifactId> 
     <version>${grails.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-log4j</artifactId> 
     <version>${grails.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-servlets</artifactId> 
     <version>${grails.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-url-mappings</artifactId> 
     <version>${grails.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-resources</artifactId> 
     <version>${grails.version}</version> 
     <scope>runtime</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-test</artifactId> 
     <version>${grails.version}</version> 
     <scope>test</scope> 
     <exclusions> 
      <exclusion> 
       <groupId>org.grails.plugins</groupId> 
       <artifactId>spock</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>org.grails</groupId> 
     <artifactId>grails-plugin-testing</artifactId> 
     <version>${grails.version}</version> 
     <scope>test</scope> 
     <exclusions> 
      <exclusion> 
       <groupId>org.grails.plugins</groupId> 
       <artifactId>spock</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 


    <dependency> 
     <groupId>com.h2database</groupId> 
     <artifactId>h2</artifactId> 
     <version>${h2.version}</version> 
     <scope>runtime</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.grails.plugins</groupId> 
     <artifactId>cache</artifactId> 
     <version>1.1.1</version> 
     <scope>compile</scope> 
     <type>zip</type> 
    </dependency> 

    <dependency> 
     <groupId>org.grails.plugins</groupId> 
     <artifactId>hibernate</artifactId> 
     <version>3.6.10.9</version> 
     <scope>runtime</scope> 
     <type>zip</type> 
    </dependency> 

    <dependency> 
     <groupId>org.grails.plugins</groupId> 
     <artifactId>database-migration</artifactId> 
     <version>1.3.8</version> 
     <scope>runtime</scope> 
     <type>zip</type> 
    </dependency> 

    <dependency> 
     <groupId>org.grails.plugins</groupId> 
     <artifactId>jquery</artifactId> 
     <version>1.11.0.2</version> 
     <scope>runtime</scope> 
     <type>zip</type> 
    </dependency> 

    <dependency> 
     <groupId>org.grails.plugins</groupId> 
     <artifactId>jquery-ui</artifactId> 
     <version>1.10.3</version> 
     <scope>runtime</scope> 
     <type>zip</type> 
    </dependency> 

    <dependency> 
     <groupId>org.grails.plugins</groupId> 
     <artifactId>resources</artifactId> 
     <version>1.2.7</version> 
     <scope>runtime</scope> 
     <type>zip</type> 
    </dependency> 

    <dependency> 
     <groupId>org.grails.plugins</groupId> 
     <artifactId>tomcat</artifactId> 
     <version>7.0.52.1</version> 
     <scope>provided</scope> 
     <type>zip</type> 
    </dependency> 

    <dependency> 
     <groupId>org.grails.plugins</groupId> 
     <artifactId>spock</artifactId> 
     <version>${spockVersion}</version> 
     <scope>test</scope> 
     <type>zip</type> 
    </dependency> 

    <dependency> 
     <groupId>org.grails.plugins</groupId> 
     <artifactId>geb</artifactId> 
     <version>${gebVersion}</version> 
     <scope>test</scope> 
     <type>zip</type> 
    </dependency> 

    <dependency> 
     <groupId>org.gebish</groupId> 
     <artifactId>geb-spock</artifactId> 
     <version>${gebSpockVersion}</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.spockframework</groupId> 
     <artifactId>spock-grails-support</artifactId> 
     <version>0.7-groovy-1.8</version> 
    </dependency> 

    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-htmlunit-driver</artifactId> 
     <version>${seleniumVersion}</version> 
     <scope>test</scope> 
     <exclusions> 
      <exclusion> 
       <groupId>xalan</groupId> 
       <artifactId>xalan</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>xml-apis</groupId> 
       <artifactId>xml-apis</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>xerces</groupId> 
       <artifactId>xercesImpl</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-chrome-driver</artifactId> 
     <version>${seleniumVersion}</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-firefox-driver</artifactId> 
     <version>${seleniumVersion}</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-support</artifactId> 
     <version>${seleniumVersion}</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.solr</groupId> 
     <artifactId>solr-solrj</artifactId> 
     <version>4.3.0</version> 
     <exclusions> 
      <exclusion> 
       <groupId>org.apache.httpcomponents</groupId> 
       <artifactId>httpclient</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpclient</artifactId> 
     <version>4.2.5</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-httpclient</groupId> 
     <artifactId>commons-httpclient</artifactId> 
     <version>3.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpmime</artifactId> 
     <version>4.2.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.tuckey</groupId> 
     <artifactId>urlrewritefilter</artifactId> 
     <version>4.0.3</version> 
    </dependency> 

    <dependency> 
     <groupId>co.freeside</groupId> 
     <artifactId>betamax</artifactId> 
     <version>1.1.2</version> 
     <scope>test</scope> 
    </dependency> 

나는이 문제를 해결하는 방법에 대한 발언에 대한 감사합니다.

편집

는 그래서, erdi에 의해 제안 된 버전을 시도 : (

2014-05-23 14:37:06,008 [main] ERROR javascript.StrictErrorReporter 
- runtimeError: message=[The data necessary to complete this operation 
is not yet available.] 
sourceName=[http://localhost:8080/search-web-app/static/plugins/jquery-1.11.0.2/js/jquery/jquery-1.11.0.min.js] line=[2] lineSource=[null] lineOffset=[0] 

FirefoxChrome 드라이버 확인 일 :

selenium-htmlunit-driver 2.26.0 
        geb 0.9.0-RC-1 
       geb-spock 0.9.0-RC-1 
       (and spock 0.7) 

내가 오류 시험 합격). HtmlUnit 드라이버가 작동하는 이유는 Jenkins 서버에서 테스트를 실행할 수 있기를 원하기 때문입니다. 내가 이해할 수 있듯이 HtmlUnit은 브라우저를 열지 않기 때문에 허용한다. (잘못 이해했다면 나를 바로 잡아라.)

+0

CI에서 브라우저 테스트를 실행할 때 보통하는 일은 Xvfb와 함께 실제 브라우저를 가상 디스플레이로 실행하는 것입니다. – erdi

+0

설명을 주셔서 감사합니다. PhantomJS를 사용하여 끝 냈습니다. 그것은 다른 드라이버보다 느리기 때문에'waitFor {...} '를 추가하여 작동하게 만들지 만, 그렇지 않으면 괜찮습니다. – nuoritoveri

답변

1

최신 버전 HtmlUnitDriver Grails 2.26.0으로 실행할 수있었습니다. 어쨌든 더 복잡한 웹 페이지에서는 제대로 작동하지 않으므로 HtmlUnitDriver을 사용하지 않는 것이 좋습니다. 거의 항상 테스트에서 실제 브라우저를 사용하는 것이 좋습니다.

최신 Geb 버전은 0.9.2이고 geb-spock 및 Grails Geb 플러그인 (0.9.0-RC-1 및 0.7.2)에는 다른 버전을 사용하지 않아야합니다.

+0

비고 주셔서 대단히 감사합니다. 나는 그 질문을 갱신했다. – nuoritoveri