-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.xml
335 lines (315 loc) · 15.6 KB
/
macros.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?xml version="1.0" encoding="UTF-8"?>
<!-- @author Michael Vogel -->
<project name="selenium-common">
<!-- =================================================================== -->
<!-- MACROS -->
<!-- =================================================================== -->
<macrodef name="run-junit" description="runs the junit tests">
<attribute name="reports.dir" />
<attribute name="baseUrl" description="url to run the selenium test against" />
<attribute name="src.dir" />
<attribute name="classes.dir" />
<attribute name="driver" description="selenium driver to use, options are html, firefox, ie" />
<attribute name="timeout" />
<attribute name="htmljavascript" default="false" description="set to true to run the HtmlUnitDriver with javascript enabled" />
<attribute name="debug" default="false" description="set to true to print out the report to the console" />
<attribute name="usefile" default="true" description="set to true to save the report to file" />
<attribute name="reports.dir.append.timestamp" default="${reports.dir.append.timestamp}" />
<sequential>
<condition property="url" value="http://${@{baseUrl}}" else="http://@{baseUrl}">
<isset property="@{baseUrl}" />
</condition>
<condition property="junit.reports.dir" value="@{reports.dir}/${TSTAMP}" else="@{reports.dir}">
<equals arg1="@{reports.dir.append.timestamp}" arg2="true" />
</condition>
<condition property="debug" value="true">
<equals arg1="@{debug}" arg2="true" />
</condition>
<condition property="usefile" value="true">
<equals arg1="@{usefile}" arg2="true" />
</condition>
<mkdir dir="${junit.reports.dir}" />
<mkdir dir="${junit.reports.dir}/xml" />
<echo message="Running Selenium Test Cases against ${url} against @{driver} with htmljavascript=@{htmljavascript}, showoputput=@{debug}, debug=${debug}, usefile=${usefile}">
</echo>
<junit printsummary="${junit.printsummary}" haltonfailure="${junit.haltonfailure}" jvm="${jdkHome}/bin/java" maxmemory="${jdk.maxmemory}" showoutput="@{debug}" fork="${jdk.fork}">
<sysproperty key="baseUrl" value="${url}" />
<sysproperty key="driver" value="@{driver}" />
<sysproperty key="timeout" value="@{timeout}" />
<sysproperty key="javascript" value="@{htmljavascript}" />
<classpath>
<pathelement location="@{classes.dir}" />
</classpath>
<classpath refid="lib.classpath" />
<batchtest fork="${jdk.fork}" todir="${junit.reports.dir}/xml">
<fileset dir="@{src.dir}">
<include name="**/*.java" />
</fileset>
<formatter type="xml" usefile="true" if="usefile" />
<formatter type="plain" usefile="false" if="debug" />
</batchtest>
</junit>
<if>
<equals arg1="${usefile}" arg2="true" />
<then>
<junitreport todir="${junit.reports.dir}">
<fileset dir="${junit.reports.dir}/xml">
<include name="TEST*.xml" />
</fileset>
<report format="frames" todir="${junit.reports.dir}/html" />
</junitreport>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="compile" description="Compiles a set of java sources.">
<attribute name="src.dir" />
<attribute name="classes.dir" />
<attribute name="classpath.refid" />
<attribute name="jdkHome" />
<element name="pre-compile" optional="true" />
<element name="post-compile" optional="true" />
<sequential>
<pre-compile />
<if>
<available file="@{src.dir}" type="dir" />
<then>
<mkdir dir="@{classes.dir}" />
<javac srcdir="@{src.dir}" destdir="@{classes.dir}" debug="${jdk.debug}" includeantruntime="false" fork="${jdk.fork}" executable="@{jdkHome}/bin/javac" target="${jdk.version}">
<classpath refid="lib.classpath" />
</javac>
<post-compile />
</then>
<else>
<echo message="src.dir for ${project.name} does not exist at @{src.dir}" />
</else>
</if>
</sequential>
</macrodef>
<macrodef name="clean-reports" description="Cleans the reports folder in the project">
<attribute name="reports.dir" />
<element name="post-clean" optional="true" />
<sequential>
<delete dir="@{reports.dir}" />
<post-clean />
</sequential>
</macrodef>
<macrodef name="clean" description="Cleans a project">
<attribute name="build.dir" />
<attribute name="classes.dir" />
<element name="post-clean" optional="true" />
<sequential>
<delete dir="@{build.dir}" />
<delete dir="@{classes.dir}" />
<post-clean />
</sequential>
</macrodef>
<macrodef name="get-key-from-nested-map">
<attribute name="map" />
<attribute name="search.value" description="The value to search for in the nested list" />
<attribute name="property" description="The property to set if the key is found." />
<sequential>
<for-contrib list="@{map}" param="entry" delimiter=":">
<sequential>
<propertyregex-contrib select="\1" override="true" property="key" input="@{entry}" regexp="^(.*?)=">
</propertyregex-contrib>
<propertyregex-contrib select="\1" override="true" property="list" input="@{entry}" regexp="=(.*?)$">
</propertyregex-contrib>
<for-contrib list="${list}" param="list.value" delimiter=",">
<sequential>
<if>
<equals arg1="@{list.value}" arg2="@{search.value}" />
<then>
<property name="@{property}" value="${key}" />
</then>
</if>
</sequential>
</for-contrib>
</sequential>
</for-contrib>
</sequential>
</macrodef>
<!-- generate testng xml -->
<macrodef name="generate-testng-xml">
<attribute name="src.dir" />
<attribute name="classes.dir" />
<attribute name="build.dir" />
<attribute name="testng.build.file" />
<sequential>
<property name="testng.tmp.file" value="tmp-output.xml" />
<delete file="@{build.dir}/${testng.tmp.file}" failonerror="false" />
<echo file="@{build.dir}/${testng.tmp.file}" message="<classes>
" append="true" />
<fileset id="sources" dir="@{src.dir}">
<include name="**/*.java" />
</fileset>
<pathconvert property="qualified.names" pathsep="
" refid="sources">
<chainedmapper>
<flattenmapper />
<globmapper from="*" to="*" />
<!-- Converts file path to class name. -->
<mapper type="package" from="*.java" to="*" />
</chainedmapper>
</pathconvert>
<for-contrib list="${qualified.names}" delimiter="
" param="qualified.name">
<sequential>
<echo file="@{build.dir}/${testng.tmp.file}" message="<class name="@{qualified.name}" />
" append="true" />
</sequential>
</for-contrib>
<echo file="@{build.dir}/${testng.tmp.file}" message="</classes>
" append="true" />
<echo file="@{build.dir}/@{testng.build.file}" message="" append="true" />
<xmltask source="${testng.build.template.file}" dest="@{build.dir}/@{testng.build.file}">
<insert path="suite/test" file="@{build.dir}/${testng.tmp.file}">
</insert>
</xmltask>
<delete file="@{build.dir}/${testng.tmp.file}" />
</sequential>
</macrodef>
<!-- run -->
<macrodef name="run-testng">
<attribute name="reports.dir" />
<attribute name="classes.dir" />
<attribute name="baseUrl" />
<attribute name="testng.build.file" />
<attribute name="port" default="${selenium.port}" />
<sequential>
<condition property="url" value="http://${@{baseUrl}}" else="http://@{baseUrl}">
<isset property="@{baseUrl}" />
</condition>
<echo message="url = ${url} - suitename ${testng.suite.name}" />
<available type="file" file="@{testng.build.file}" property="testng.file" />
<fail unless="testng.file" message="TestNG build file does not exist at @{testng.build.file}" />
<testng suitename="${testng.suite.name}" jvm="${jdkHome}/bin/java" outputdir="@{reports.dir}" configfailurepolicy="${testng.configfailurepolicy}">
<sysproperty key="baseUrl" value="${url}" />
<sysproperty key="port" value="@{port}" />
<classpath refid="lib.classpath" />
<classpath path="@{classes.dir}" />
<xmlfileset file="@{testng.build.file}" />
</testng>
</sequential>
</macrodef>
<macrodef name="usage" description="Print Target Descriptions">
<sequential>
<condition property="antHome" value="${ant.home}" else="${env.ANT_HOME}">
<and>
<isset property="ant.home" />
<available file="${ant.home}" type="dir" />
</and>
</condition>
<path id="ant.classpath">
<fileset dir="${antHome}/lib">
<include name="*.jar" />
</fileset>
</path>
<java classname="org.apache.tools.ant.Main" jvm="${jdkHome}/bin/java" fork="true">
<classpath refid="ant.classpath" />
<arg value="-projecthelp" />
<arg value="-buildfile" />
<arg value="${basedir}/build.xml" />
</java>
</sequential>
</macrodef>
<!-- check-server-running -->
<macrodef name="check-server-running">
<element name="server-on" optional="true" />
<element name="server-off" optional="true" />
<attribute name="server" />
<attribute name="port" />
<sequential>
<echo message="Checking if server is already running on @{server}:@{port}" />
<condition property="server.running">
<not>
<socket server="@{server}" port="@{port}" />
</not>
</condition>
<if-contrib>
<equals arg1="${server.running}" arg2="true" />
<then>
<server-off />
<echo message="=========================================================" />
<echo message="= Server Not Started. All TestNG Tests will now skip. =" />
<echo message="= Please start the Selenium server by running the build =" />
<echo message="= ant start-server =" />
<echo message="=========================================================" />
</then>
<else>
<echo message="Server is running on @{server}:@{port}" />
<server-on />
</else>
</if-contrib>
</sequential>
</macrodef>
<macrodef name="set-base-url" description="Sets the baseUrl for testing">
<attribute name="target" />
<sequential>
<condition property="baseUrl" value="${@{target}}" else="${test.url}">
<isset property="@{target}" />
</condition>
</sequential>
</macrodef>
<macrodef name="create-hot-deploy" description="Sets the baseUrl for testing">
<sequential>
<available type="dir" file="${hot.deploy}/${user.name}" property="testng.file" />
<if-contrib>
<available file="${hot.deploy}/${user.name}" type="dir" />
<else>
<echo message="Created hot-deploy folder at ${hot.deploy}/${user.name}" />
<mkdir dir="${hot.deploy}/${user.name}" />
</else>
</if-contrib>
</sequential>
</macrodef>
<macrodef name="convert-to-unix" description="Normalizes a path to UNIX format">
<attribute name="path" />
<attribute name="var" />
<sequential>
<path id="path-id">
<pathelement location="@{path}" />
</path>
<!-- Remove Windows Specific drive letters -->
<pathconvert targetos="unix" property="@{var}" refid="path-id">
<map from="c:" to="" />
<map from="d:" to="" />
<map from="e:" to="" />
<map from="f:" to="" />
<map from="g:" to="" />
<map from="h:" to="" />
</pathconvert>
</sequential>
</macrodef>
<macrodef name="validate-build">
<element name="pre-validate" optional="true" />
<element name="post-validate" optional="true" />
<sequential>
<!-- validate java version is 1.6 or higher
<fail message="Unsupported Java version: ${java.version}. Build requires Java version 1.6+">
<condition>
<not>
<or>
<contains string="${java.version}" substring="1.6" casesensitive="false" />
<contains string="${java.version}" substring="1.7" casesensitive="false" />
<contains string="${java.version}" substring="1.8" casesensitive="false" />
<contains string="${java.version}" substring="1.9" casesensitive="false" />
</or>
</not>
</condition>
</fail>
-->
</sequential>
</macrodef>
<!-- Refreshed the eclipse workspace. This only works if the eclipse ANT is set run in the same jvm as eclipse -->
<macrodef name="refresh-eclipse">
<attribute name="on" default="false" />
<sequential>
<if-contrib>
<equals arg1="@{on}" arg2="true" />
<then>
<eclipse.refreshLocal resource="${basedir}" depth="infinite" />
</then>
</if-contrib>
</sequential>
</macrodef>
<!-- Common Targets -->
<target name="generate-testng" if="testng.run">
<generate-testng-xml src.dir="${src.dir}" build.dir="${build.dir}" classes.dir="${classes.dir}" testng.build.file="${testng.build.file}" />
</target>
</project>