Failed to start test through ANT

I have a test class, all tests of this class run fine if I run in eclipse. (right click on the file, run it as jUnit), but when I try to run using Ant Script, it fails.

In fact, this test should run against two browsers. This test works great with Chrome IE. It works great against IE. But the test cannot work against Chrome. I'm not sure what is going on. All information related to the driver that I placed under all the resources / drivers / paths of the project. And the browser profiles that I saved in the browserProfiles folder of the project.

I'm not sure why tests cannot be selected for Chrome.

I have attached test code and code where I am trying to create webdriver and seldriver in the source code.

package com.mytests; public class MyParamTest { private MyWrapperForBrowser browser; @Before public void setup(){ b = new MyWrapperForBrowser("chrome"); b.start(); } @Test public void testCURDOnEntity() { MyEntity e = new MyEntity(browser); Assert.assertTrue(e.createMessage("message", "text")); // more business logic.. } } 

And the source code

  package com.mysrc; import java.util.*; import org.openqa.selenium.*; public class MyWrapperForBrowser { private final WebDriver webDriver; private WebDriverBackedSelenium selDriver; public MyWrapperForBrowser(String driver) { if (driver.equalsIgnoreCase("IE") { // create webDriver , selDriver } else{ System.setProperty("webdriver.chrome.driver", "allresources/drivers/chromedriver.exe"); DesiredCapabilities broserCapabilities = DesiredCapabilities.chrome(); broserCapabilities.setCapability("chrome.switches", Arrays.asList("--start-minimized")); String url = this.getClass().getClassLoader().getResource("browserProfiles/ChromeProfile").getPath() .substring(1); broserCapabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir=" + url)); webDriver = new ChromeDriver(broserCapabilities); selDriver = new WebDriverBackedSelenium(webDriver, ""); } } public void start() { webDriver.get(getURL()); selDriver.windowMaximize(); } } 

The stack trace that I get when I run the Ant build:

 [junit] java.util.zip.ZipException: error in opening zip file [junit] at java.util.zip.ZipFile.open(Native Method) [junit] at java.util.zip.ZipFile.<init>(ZipFile.java:114) [junit] at java.util.zip.ZipFile.<init>(ZipFile.java:131) [junit] at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1028) [junit] at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:147) [junit] at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init> 

Here is the Script assembly:

 <project name="MyProject" default="build-proj" basedir="."> <property file="./build.properties" /> <path id="project.classpath"> <fileset dir="resources/drivers"> <include name="*.*" /> </fileset> </path> <taskdef resource="emma_ant.properties"> <classpath> <pathelement path="${lib.dir}/emma_ant-2.1.5320.jar" /> <pathelement path="${lib.dir}/emma-2.1.5320.jar" /> </classpath> </taskdef> <target name="build-proj"> <antcall target="cleanup" /> <antcall target="compile" /> <antcall target="test" /> </target> <target name="cleanup" description="clean up"> <delete dir="${build.dir}" /> <delete dir="${dist.dir}" /> <delete dir="${test.report.dir}" /> <mkdir dir="${build.dir}" /> <mkdir dir="${build.src.dir}" /> <mkdir dir="${build.test.dir}" /> </target> <target name="compile" description="compiling all the code"> <javac srcdir="${src.dir}" destdir="${build.src.dir}" debug="true"> <classpath> <path refid="project.classpath" /> </classpath> </javac> <javac srcdir="${test.dir}" destdir="${build.test.dir}" debug="true"> <classpath> <path refid="project.classpath" /> <path path="${build.src.dir}" /> </classpath> </javac> </target> <target name="test"> <junit haltonfailure="false" printsummary="true" fork="true" forkmode="once" > <classpath> <pathelement path="${src.dir}" /> <pathelement path="${build.src.dir}" /> <pathelement path="${build.test.dir}" /> <pathelement path="${test.data.dir}" /> <path refid="project.classpath" /> </classpath> <formatter type="xml"/> <batchtest todir="${test.report.dir}"> <fileset dir="${build.test.dir}"> <include name="**/*Test.class" /> </fileset> </batchtest> </junit> </target> </project> 
+2
source share
1 answer

Your class path probably contains more than .jar files.

The ant "junit" task loves only .jar files (or rather Path like structure to use ant term) in the classpath element.

You can try using

 <include name="*.jar" /> 

instead

 <include name="*.*" /> 

in your "project.classpath" -fileset.

+5
source

Source: https://habr.com/ru/post/894560/


All Articles