有没有可能将Selenium配置为使用Firefox驱动程序并在Windows中无头运行浏览器?
我知道其他驱动程序在Windows或Linux下也可以这样工作,但不是在上面提到的特定情况下。任何参考信息(实现它的特别方法、限制等)在上面阅读是非常令人欣喜的。
致以敬意,
发布于 2015-10-28 17:23:35
可以运行浏览器(Firefox、IE等)通过Windows操作系统支持的专用虚拟桌面。用于该任务的一种已知的辅助实用程序是Headless Selenium for Windows。
发布于 2014-10-23 06:38:35
这是我们在windows的无头模式下使用firefox驱动程序运行selenium的方法。
创建windows任务计划,您可以使用UI http://windows.microsoft.com/en-US/windows/schedule-task#1TC=windows-7执行此操作。
或者使用下面这样的命令:
schtasks /Create /TN Automation /TR C:\automation\automated_regression.bat /SC ONSTART /RU Administrator /RP password /F /V1在我们的例子中,自动化是ant驱动的,所以automated_regression.bat具有如下内容
:myLoop
cd c:\automation
call ant_env.bat
call ant -f regression.xml
GOTO myLoop其中,regression.xml具有selenium java项目的典型junit目标。
<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>您可以使用记录器来记录您的蚂蚁运行时,例如。
<record name="log\automation_${timestamp}.log" loglevel="verbose" append="false" />使用这个,你可以跟踪你的无头自动化中正在发生的事情。
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也可以做类似的事情,但我还没有尝试过它是否有效。
发布于 2018-01-04 13:20:07
https://stackoverflow.com/questions/17062453
复制相似问题