java - ANT 构建无法识别 geckodriver 可执行文件 "The driver executable does not exist"

标签 java jenkins ant illegalstateexception geckodriver

在 Eclipse 中运行时我没有遇到任何问题,但是当我尝试在 Jenkins 中运行 ANT 构建时,我得到以下信息:

java.lang.IllegalStateException: The driver executable does not exist: C:\Program Files (x86)\Jenkins\jobs\Update InforTAP Build\workspace\lib\geckodriver0-19.exe

Image capture of file info 该 exe 存在于该确切目录中,并且权限已设置为 777。在第 3 方服务器中运行的测试工作正常。这似乎表明这是使用 Jenkins 本地运行方式的唯一问题。

这是数据输出:(请注意,我已删除“ANT_BUILDS”)

before :C:\Program Files (x86)\Jenkins\jobs\Update InforTAP Build\workspace\ANT_BUILDS browser

location: lib\geckodriver0-19.exe

after :C:\Program Files (x86)\Jenkins\jobs\Update InforTAP Build\workspace\lib\geckodriver0-19.exe

lib目录在这里: C:\Program Files (x86)\Jenkins\jobs\Update InforTAP Build\workspace\lib\

ANT 构建文件位于此处: C:\Program Files (x86)\Jenkins\jobs\Update InforTAP Build\workspace\ANT_BUILDS\

    final FirefoxOptions firefoxOptions = new FirefoxOptions();

                ensureOneDriverInstance(Browser.GEKODRIVER_EXE_NAME);

                System.setProperty("webdriver.gecko.driver", Browser.getDriverExeLocation(Browser.FIREFOX));
                System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
                System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");

                firefoxOptions.addPreference("browser.popups.showPopupBlocker", false);
                firefoxOptions.addPreference("security.sandbox.content.level", 5);

                driver = new FirefoxDriver(firefoxOptions);

public static String getDriverExeLocation(final Browser browserType) {
        String currentWorkingDirectory = null;
        String browserLocation = null;

    public static final String GEKODRIVER_EXE_NAME = "geckodriver0-19.exe";
    public static final String GEKODRIVER_EXE_LOCATION = "lib\\\\" + GEKODRIVER_EXE_NAME;

browserLocation = GEKODRIVER_EXE_LOCATION;
currentWorkingDirectory = UtilsFile.getCurrentDirectory();
        System.out.println("before :" + currentWorkingDirectory);
        System.out.println("browser location: " + browserLocation);
        if ((currentWorkingDirectory != null) && currentWorkingDirectory.contains("ANT_BUILDS")) {
            if (browserLocation != null) {
                System.setProperty("user.dir", currentWorkingDirectory.replaceAll("ANT_BUILDS", ""));
                browserLocation = currentWorkingDirectory.replaceAll("ANT_BUILDS", browserLocation);
            }
        }
        System.out.println("after :" + browserLocation);
        return browserLocation;
}

这是 ANT 构建文件

<property name="RELEASE_ROOT" value="workspace/" />
<property name="BASE_ROOT" value="${basedir}/workspace/" />
<property name="SRC" value="${RELEASE_ROOT}/src" /> <!-- Change it to your source folder -->
<property name="LIB" value="${RELEASE_ROOT}/lib" /> <!-- Change it to your lib folder --> 
<property name="SELENIUM.LIB" value="${RELEASE_ROOT}" /> <!-- Change it to your lib folder --> 
<property name="BIN" value="${RELEASE_ROOT}/bin1" /> <!-- Change it to your binary folder where you need to gerate the compiled binary file -->
<property name="REPORT" value="${RELEASE_ROOT}/reports/ANT" /> <!-- Change it to your output report folder -->

<property environment="env" />
    <property name="CATALINA_HOME.LIB" location="${env.CATALINA_HOME}/lib"/>
    <property name="CATALINA_HOME.BIN" location="${env.CATALINA_HOME}/bin"/>

<import file="${CATALINA_HOME.BIN}/catalina-tasks.xml"/>


<fileset dir="${SELENIUM.LIB}" id="http.jars">
        <include name="lib/httpclient*.jar" />
        <include name="lib/httpcore*.jar" />
    </fileset>

<fileset dir="${CATALINA_HOME.LIB}" id="CATALINA_HOME.jars">
    <include name="servlet-api.jar" />
    <include name="**/*.jar" />
</fileset>

<fileset dir="${SELENIUM.LIB}" id="SELENIUM.jars">
    <include name="lib/*.jar" />
</fileset>

<path id="test.classpath"> <!-- Creating a classpath for use while compiling -->
    <fileset refid="http.jars" />
    <fileset refid="CATALINA_HOME.jars" />
    <fileset refid="SELENIUM.jars" />
    <pathelement location="${BIN}" />
</path>

<target name="init"> <!-- Initialization target which deletes and recreates the binary folder.-->
    <delete dir="${BIN}" />
    <mkdir dir="${BIN}" />
</target>

<target name="compile" depends="init"> <!-- Target for compiling the source folder  -->
        <javac  includeantruntime="false" source="1.8" srcdir="${SRC}" fork="true" destdir="${BIN}" encoding="UTF-8" > 
            <classpath>
                <fileset refid="http.jars" />
                <fileset refid="CATALINA_HOME.jars" />
                <fileset refid="SELENIUM.jars" />
                <pathelement location="${BIN}" />
            </classpath>
        </javac>
    </target>


<target name="run-regression"> <!-- Target to run test in batches. -->
    <delete dir="${REPORT}" />
    <mkdir dir="${REPORT}" />
    <mkdir dir="${REPORT}/xml" />                   
<junit printsummary="yes" haltonfailure="no">
<jvmarg value="-Duser.dir=${BASE_ROOT}"/>   <!-- has to be absolute path  echo the path to see what we have so far-->
        <classpath>
            <pathelement path="${BIN}" />
                <fileset refid="CATALINA_HOME.jars" />
                <fileset refid="SELENIUM.jars" />
        </classpath>
        <test name="com.infor.infortap.tomcatpa.testsuite.TestSuiteRegressionInternalAdmin" haltonfailure="no" todir="${REPORT}/xml" outfile="TEST-result"> 
                <formatter type="xml" />
        </test>

    </junit>
        <junitreport todir="${REPORT}">
            <fileset dir="${REPORT}/xml">
                <include name="TEST*.xml" />
            </fileset>
            <report format="frames" styledir="${RELEASE_ROOT}/reports/report-formats" todir="${REPORT}/html" />
        </junitreport>

    </target>

<target name="compile-and-run-regression-internal-admin" depends="compile, run-regression"/>

最佳答案

答案是创建一个 Jenkins 主目录,而不是尝试使用默认设置。 Create a Jenkins Home Directory

我还使用用户 ID 登录 Windows 服务,而不是选择第一个选项来允许 Windows 服务使用当前 session 。

关于java - ANT 构建无法识别 geckodriver 可执行文件 "The driver executable does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49395205/

相关文章:

java - 将应用程序属性覆盖为未定义/未设置

java - Spring 数据休息: NULL values issue

java - Spring Security - 在哪里设置默认用户的权限?

javascript - tinymce构建脚本压缩所有js文件

java - Ant/JUnit - 如何断言包依赖项/非依赖项?

java - Spring 流 : Pass object back and forth from between Main WebFlow and Subflow

jenkins - 在 Groovy 脚本中访问当前的 Jenkins 构建

bash - Jenkins 在控制台输出页面中显示 echo 命令

jenkins - 如何在 Sauce Ondemand 中加载 Selenium 测试套件/案例?

java - Java 中删除注释的脚本