首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium在Windows中运行无头Firefox浏览器

问Selenium在Windows中运行无头Firefox浏览器
EN

Stack Overflow用户
提问于 2013-06-12 17:49:19
回答 3查看 15K关注 0票数 15

有没有可能将Selenium配置为使用Firefox驱动程序并在Windows中无头运行浏览器?

我知道其他驱动程序在Windows或Linux下也可以这样工作,但不是在上面提到的特定情况下。任何参考信息(实现它的特别方法、限制等)在上面阅读是非常令人欣喜的。

致以敬意,

EN

回答 3

Stack Overflow用户

发布于 2015-10-28 17:23:35

可以运行浏览器(Firefox、IE等)通过Windows操作系统支持的专用虚拟桌面。用于该任务的一种已知的辅助实用程序是Headless Selenium for Windows。

票数 10
EN

Stack Overflow用户

发布于 2014-10-23 06:38:35

这是我们在windows的无头模式下使用firefox驱动程序运行selenium的方法。

创建windows任务计划,您可以使用UI http://windows.microsoft.com/en-US/windows/schedule-task#1TC=windows-7执行此操作。

或者使用下面这样的命令:

代码语言:javascript
复制
schtasks /Create /TN Automation /TR C:\automation\automated_regression.bat /SC ONSTART /RU Administrator /RP password /F /V1

在我们的例子中,自动化是ant驱动的,所以automated_regression.bat具有如下内容

代码语言:javascript
复制
:myLoop
cd c:\automation
call ant_env.bat
call ant -f regression.xml
GOTO myLoop

其中,regression.xml具有selenium java项目的典型junit目标。

代码语言:javascript
复制
    <property name="main.dir" location="./selweb" />
    <property name="src.dir" location="${main.dir}/src" />
    <property name="lib.dir" location="${main.dir}/lib" />
    <property name="build.dir" location="${main.dir}/build" />
    <property name="test.report" location="${main.dir}/testreport">
    </property>
    
    <path id="build.classpath">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar" />
        </fileset>
    </path>
    
    <target name="clean">
        <delete dir="${build.dir}" />
        <delete dir="${test.report}" />
    </target>
    
    <target name="make dir" depends="clean">
        <mkdir dir="${build.dir}" />
        <mkdir dir="${test.report}" />
    </target>
    
    <target name="compile" depends="clean, make dir">
        <javac srcdir="${src.dir}" destdir="${build.dir}" debug="true">
            <classpath refid="build.classpath" />
        </javac>
    </target>
    
    <target name="junit" depends="clean, make dir,compile">
        <loadfile property="LATEST" srcFile="LATEST" />
        <junit printsummary="no" fork="true" haltonfailure="false" dir="${main.dir}">
            <classpath>
                <pathelement path="${build.dir}" />
                <fileset dir="${lib.dir}">
                    <include name="**/*.jar" />
                </fileset>
            </classpath>
            <formatter type="xml" />
            <batchtest todir="${test.report}">
                <fileset dir="${build.dir}">
                    <include name="**/tests/**/*.class" />
                </fileset>
            </batchtest>
        </junit>
        
        <junitreport todir="${test.report}">
            <fileset dir="${test.report}">
                <include name="**/*.xml"/>
            </fileset>
            <report format="noframes" todir="${test.report}/html" styledir="${main.dir}/style"> 
            <param name="TITLE" expression="Selenium Test Results for build ${LATEST}"/>
            </report>
            <report format="frames" todir="${test.report}/html" styledir="${main.dir}/style"/>
        </junitreport>      
    </target>

您可以使用记录器来记录您的蚂蚁运行时,例如。

代码语言:javascript
复制
<record name="log\automation_${timestamp}.log" loglevel="verbose" append="false" />

使用这个,你可以跟踪你的无头自动化中正在发生的事情。

代码语言:javascript
复制
The ' characters around the executable and arguments are
not part of the command.
    [junit] Test com.yourtests ... FAILED
    [junit] Implicitly adding C:\automation\dep\apache-ant-1.8.4\lib\ant-launcher.jar;C:\automation\dep\apache-ant-1.8.4\lib\ant.jar;C:\automation\dep\apache-ant-1.8.4\lib\ant-junit.jar;C:\automation\dep\apache-ant-1.8.4\lib\ant-junit4.jar to CLASSPATH
.....    
'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
'com.yourtests'
'filtertrace=true'
'haltOnError=false'
'haltOnFailure=false'
'showoutput=false'
'outputtoformatters=true'
'logfailedtests=true'
'logtestlistenerevents=false'
'formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,c:\automation\selweb\testreport\TEST-com.yourtests'
'crashfile=c:\automation\junitvmwatcher2114698975676150832.properties'
'propsfile=c:\automation\junit4190343520192991051.properties'

我们已经遵循了这种方法,并且它是有效的,甚至屏幕截图也被拍摄并插入到ant-junit html报告中。

所以本质上你需要通过windows任务调度程序运行你的selenium,它将在无头模式下运行。我认为在linux下使用cron也可以做类似的事情,但我还没有尝试过它是否有效。

票数 2
EN

Stack Overflow用户

发布于 2018-01-04 13:20:07

根据最近的发展,可以在无头模式下运行Chrome和Firefox,而不需要任何外部黑客。

Chrome版:

https://www.youtube.com/watch?v=0gSDYRbtwmw

火狐的:

https://www.youtube.com/watch?v=D0xcg5nviso

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17062453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档