Selenium running headless Firefox browser in Windows - firefox

Is it possible to configure Selenium to use Firefox driver and run the browser headlessly within Windows?
I am aware of other drivers working so within Windows or under Linux but not in the particular case mentioned above. Any reference information (ad-hoc ways to achieve it, limitations, etc.) to read upon is highly appreaciated.
Regards,

It is possible to run browsers (Firefox, IE, ...) via dedicated virtual desktop which supported by OS Windows. One such known helper utility for that task is Headless Selenium for Windows.

Here is the way we are running selenium using firefox driver in headless mode on windows.
Create a windows task schedule, you can either do this using the UI
http://windows.microsoft.com/en-US/windows/schedule-task#1TC=windows-7
or with a command like this :
schtasks /Create /TN Automation /TR C:\automation\automated_regression.bat /SC ONSTART /RU Administrator /RP password /F /V1
in our case, the automation is ant driven, so the automated_regression.bat has something like this
:myLoop
cd c:\automation
call ant_env.bat
call ant -f regression.xml
GOTO myLoop
where the regression.xml has a the typical junit targets of a selenium java project
<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>
you can use a logger to record your ant runtime eg.
<record name="log\automation_${timestamp}.log" loglevel="verbose" append="false" />
using this you can follow what is going on in your headless automation.
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'
We have followed this approach and it's working, even screen shots are being taken and inserted in the ant-junit html report.
So the essence is that you need to run your selenium through windows Tasks Scheduler and it will run in headless mode. I think something similar can be done under linux using the cron, but i haven't tried it out to see if it works.

Related

Google Closure Compiler Ant Build without concatenating the output

1) I finally managed to get something compiled through Google Closure Compiler using Ant to automate the process. The problem im facing, is that all the examples provided concatenate the output into one main file (main example I followed), say foo.min.js. What I need is to minify/compile ALL the .js files in one and/or more directories into their respective .min.js files, without concatenating the output, so, lets say, I have 3 .js files, I need 3 minified .min.js outputs.
Here's my (first) current build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="foobar" basedir="." default="compile">
<property environment="env."/>
<property name="env.CLASSPATH" value=""/>
<fail message="Unset $CLASSPATH / %CLASSPATH% before running Ant!">
<condition>
<not>
<equals arg1="${env.CLASSPATH}" arg2=""/>
</not>
</condition>
</fail>
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask" classpath="${env.CLOSURE_COMPILER}/compiler.jar" />
<target name="compile">
<jscomp compilationLevel="simple" warning="quiet" debug="false" output="${basedir}/admin/js/foo.min.js">
<sources dir="${basedir}/admin/js">
<file name="home.js" />
<file name="mailing.js" />
<file name="table_modal_events.js" />
</sources>
</jscomp>
</target>
</project>
2) Following Ant's installation manual, I've added this
<property environment="env."/>
<property name="env.CLASSPATH" value=""/>
<fail message="Unset $CLASSPATH / %CLASSPATH% before running Ant!">
<condition>
<not>
<equals arg1="${env.CLASSPATH}" arg2=""/>
</not>
</condition>
</fail>
to the top of my project, and after building successfully multiple times this way, I noticed that if I remove <property environment="env."/> I get a taskdef class com.google.javascript.jscomp.ant.CompileTask cannot be found
using the classloader AntClassLoader[] error. May I ask why? (being %CLOSURE_COMPILER% an environment variable which I also added to PATH) This answer may be related to this? But I still don't understand.
3) This is the closest related question/answer I could find. But it makes use of a bash script, so my question is: is it possible to achieve what I want using Ant?
I would appreciate if somebody could tell me what I'm doing wrong.
You just need something like into your target
<apply executable="java" parallel="false">
<fileset dir="webapp/js" includes="**/*.js"
excludes="any to exclude" />
<arg line="-jar"/>
<arg path="PATH/closure-compiler-XXX.jar"/>
<arg line="--js "/>
<srcfile/>
<arg line="--warning_level=QUIET" />
<arg line="--js_output_file"/>
<mapper type="glob" from="*.js" to="build/webapp/js/*.js"/>
<targetfile/>
</apply>

Can I use ant war task to export a war built with Maven?

Im using eclipse and maven for my day to day development, which works fine. However I need a specialized war created when its time to export to send over to production, which includes things like minifying and combining js/css etc, separating out static resources for apache rather than tomcat etc.
I tried the maven plugin route but it was a hassle, I'd rather write a simply ant script to export when necessary. I'm using the ant war task, but the exported war contains everything except my WEB-INF/libs folder, which is blank. Does anyone know a way to make the script work with all the libs that maven looks up? This is what I have:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="war" basedir=".">
<property name="builder" value="Me" />
<property name="project-name" value="${ant.project.name}" />
<property name="war-file-name" value="${project-name}.war" />
<property name="source-directory" value="src/main/java" />
<property name="classes-directory" value="target/classes" />
<property name="web-directory" value="src/main/webapp" />
<property name="web-xml-file" value="src/main/webapp/WEB-INF/web.xml" />
<property name="build-directory" value="/" />
<tstamp prefix="build-info">
<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
</tstamp>
<target name="war" depends="">
<mkdir dir="${build-directory}" />
<delete file="${build-directory}/${war-file-name}" />
<war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
<classes dir="${classes-directory}" />
<fileset dir="${web-directory}">
<exclude name="WEB-INF/web.xml" />
</fileset>
<manifest>
<attribute name="Built-By" value="${builder}" />
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>
</project>
You can use maven ant tasks for this. I have not tried this, but from the examples, something like this should work...
<artifact:dependencies filesetId="dependency.fileset" useScope="runtime">
<pom file="pom.xml"/>
</artifact:dependencies>
<copy todir="${webapp.output}/WEB-INF/lib">
<fileset refid="dependency.fileset" />
<!-- This mapper strips off all leading directory information -->
<mapper type="flatten" />
</copy>

How to run Sahi tests as part of a Hudson build?

In the absence of a Maven plugin for Sahi, what's the easiest way to run Sahi tests from Hudson?
You do have a tutorial for integrating Hudson with Sahi, but it is based on a free-style project, and a Ant task (as Pascal Thivent commented)
with zkdemo.xml and other Sahi ant tasks detailed here:
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="bids" default="runfftests">
<property environment="env"/>
<property name="sahi.home" value="${env.SAHI_HOME}" location="/mnt/sda4/Sahi/sahi/" />
<property name="user.data" value="${env.SAHI_USERDATA_DIR}" location="/mnt/sda4/Sahi/sahi/userdata" />
<property name="urlbase" value="http://www.google.com/"/>
<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="${sahi.home}/lib/ant-sahi.jar"/>
<target name="runfftests">
<antcall target="startsahi"/>
<sleep seconds="4"/>
<sahi suite="${user.data}/scripts/my.suite"
browser="/usr/bin/firefox"
baseurl="${urlbase}"
sahihost="localhost"
sahiport="9999"
failureproperty="sahi.failed"
haltonfailure="false"
browserProcessName="firefox"
threads="3">
</sahi>
<sleep seconds="4"/>
<antcall target="stopsahi"/>
<sleep seconds="4"/>
<antcall target="failsahi"/>
</target>
<target name="failsahi" if="sahi.failed">
<fail message="Sahi tests failed!"/>
</target>
<target name="startsahi" description="start sahi proxy">
<java classname="net.sf.sahi.Proxy" fork="true" spawn="true" dir="${sahi.home}">
<!--<env key="MOZ_NO_REMOTE" value="1"/>-->
<classpath location="${sahi.home}/lib/sahi.jar">
<fileset dir="${sahi.home}/extlib" includes="**/*.jar"/>
</classpath>
<arg value="${sahi.home}" id="basePath"/>
<arg value="${user.data}" id="userdataPath"/>
</java>
</target>
<target name="stopsahi" description="stop sahi server">
<sahi stop="true" sahihost="localhost" sahiport="9999"/>
</target>
</project>
you can use maven Surefire plugin call sahi junit test case, then integrated with Jenkin server

webspehere 6.1.0.25 base with RAD 7.0.0.9 wsInstallApp task problem

Hi All,
I am trying to run wsInstallApp task to deploy my war file into
websphere.
I am getting the error "Unable to parse setupCmdLine:
null\bin\setupCmdLine.bat (The system cannot find the path specified.)"
<property name="ear.file" value="../archive/DocProcessing.war" />
There is no attribute for war
Here is the code SNIPPET:
<target name="init">
<path id="lib.ref">
<fileset dir="${env.classpath.WAS_HOME}\lib">
<include name="*.*jar" />
</fileset>
<fileset dir="${env.classpath.WAS_HOME}\bin">
<include name="*.*bat" />
</fileset>
<fileset dir="${env.classpath.WAS_HOME}\plugins">
<include name="*.*jar" />
</fileset>
<fileset dir="${env.classpath.WAS_HOME}\java\lib">
<include name="*.*jar" />
</fileset>
<fileset dir="${env.classpath.WAS_HOME}\deploytool\itp\plugins">
<include name="*.*jar" />
</fileset>
<fileset dir="${env.classpath.WAS_HOME}">
<include name="*.*jar" />
</fileset>
</path>
<taskdef name="wsStartServer" classpathref="lib.ref"
classname="com.ibm.websphere.ant.tasks.StartServer" />
<taskdef name="wsInstallApp" classpathref="lib.ref"
classname="com.ibm.websphere.ant.tasks.InstallApplication" />
</target>
<target name="StartServer" depends="init">
<exec dir="${env.classpath.WAS_HOME}\bin" executable="cmd">
<arg line="/c startServer.bat server1 -profileName AppSrv01" />
</exec>
</target>
<target name="installEar" depends="StartServer">
<echo message="EAR File located: ${ear.file}" />
<wsInstallApp ear="${ear.file}" wasHome="${env.classpath.WAS_HOME}"
conntype="${remoteConnType}" host="${remoteHostName}" user="${remoteUserId}"
password="${remotePassword}" />
</target>
properties set are:
<property name="remoteHostName" value="localhost" />
<property name="remoteConnType" value="SOAP" />
<property name="remotePort" value="8880" />
<property name="remoteUserId" value="wasadmin" />
<property name="remotePassword" value="wasadmin" />
path set for wasHome ="C:\Program Files\IBM\WebSphere\AppServer"
I could
not findout what is wrong in this .Though i am new to websphere i am
trying to find out the solution to install application and start
application using ant script .Please kindly provide me the solution to
get it set right .
Thanx in advance
You have to set 'user.install.root' property, here is an example:
<property name="user.install.root" value="${env.classpath.WAS_HOME}/profiles/was60profile1" />
Yes, we needed to add the following:
<property name="user.install.root" value="${was.path}/profiles/AppSrv01" />
where was.path would be the location where your was application is installed.
I had this error today. And found the answer!!!
Add profileName="[name of the profile]", in my case profileName="wp_profile", And it works!
This process most probably runs ws_ant.bat which in turn calls setupcmdline to initialise all the variables. In my installation the line is like this:
#echo off
#setlocal
call "%~dp0setupCmdLine.bat" %*
Could it be something to do with your server/RAD configuration being invalid, or the project not having a default server assigned to it?
What happens when you run it outside of RAD through the command line, does it still fail in the same way?
More information from IBM Support here:
http://www-01.ibm.com/support/docview.wss?rs=180&uid=swg1PK23265

is it possible to make nant run a publish on web application project

is it possible to make nant run a publish on mvc project or a good old web application project
and after the publish make nant FTP the files to the web server
UPDATE: found the solution to the ftp problem
Nant ftp task thanks Paco
what i mean by publich
is there a command line application or nant task that can public like visual studio publish...
The visual studio publish command rebuilds your solution and then copies the files in the solution directory to a new directory. I use the following target to do almost the same:
<target name="copyToPublish">
<delete dir="${dir.publish}" />
<mkdir dir="${dir.publish}" />
<mkdir dir="${dir.publish}\wwwroot"/>
<copy todir="${dir.publish}\wwwroot" includeemptydirs="false">
<fileset basedir="${website.dir}">
<exclude name="**/*.cs"/>
<exclude name="**/*.pdb"/>
<exclude name="**/*.csproj*"/>
<exclude name="**/obj/**"/>
<include name="**/*.*"/>
</fileset>
</copy>
<mkdir dir="${dir.publish}\database"/>
<copy todir="${dir.publish}\database" includeemptydirs="false">
<fileset basedir="${dir.databasescripts}">
<include name="**/*.sql" />
</fileset>
</copy>
<xmlpoke
file="${dir.publish}\wwwroot\Web.config"
xpath="/configuration/system.web/compilation/#debug"
value="false" />
<xmlpoke
file="${dir.publish}\wwwroot\Web.config"
xpath="/configuration/system.web/trace/#enabled"
value="false" />
<move file="${dir.publish}\wwwroot\Web.config" tofile="${dir.publish}\wwwroot\Release.config" overwrite="true" />
<delete file="${dir.publish}\wwwroot\Web.config" />
</target>
Before this target you have to run the normal build procedure of course.
There is a Ftp Task for nant.
Beside that, you have to create a script that copies the files and directories you need and the config files. I don't do it automatically, because I want to have control over database update scripts and changes in web.config.

Resources