【问题标题】:ANT build is unable to recognize geckodriver executable "The driver executable does not exist"ANT 构建无法识别 geckodriver 可执行文件“驱动程序可执行文件不存在”
【发布时间】:2018-08-29 21:59:13
【问题描述】:

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

java.lang.IllegalStateException: 驱动程序可执行文件不存在:C:\Program Files (x86)\Jenkins\jobs\更新 InforTAP Build\workspace\lib\geckodriver0-19.exe

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

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

之前:C:\Program Files (x86)\Jenkins\jobs\Update InforTAP Build\workspace\ANT_BUILDS 浏览器

位置:lib\geckodriver0-19.exe

在 :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 BUILD 文件

<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 Windows 服务并开始使用 java -jar jenkins.war 命令,一切正常。这并不是一个真正的长期解决方案,因为如果 VM 重新启动或有人意外关闭了窗口,我们将不得不手动启动 Jenkins 服务。
  • 我想知道这是否能解决我的问题Move Jenkins Intall Directory

标签: java jenkins ant illegalstateexception geckodriver


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    相关资源
    最近更新 更多