Вы находитесь на странице: 1из 8

Requirement: Budng a Casper|S Framework (CFW)

Programming Language to be used: Node|S


Summary:
We currenty have a testng framework usng Seenum wth Phantom|S as the
browser. We woud ke transton from usng Seenum to usng soey Phantom|S.
We have a arge number of seenum tests that are but on a framework that uses
XML to create the test nputs. Instead of rewrtng a these test scrpts n Casper|S,
we woud ke to bud a framework around the XML. The framework woud
dynamcay generate the Casper|S nstead of wrtng statc Casper|S scrpts. In
order to accompsh ths we requre software that can read the XML and generate
the approprate Casper|S, to be wrtten n Node|S
FrameWork Confguration Requirements:
The Casper|S Framework (referred to as CFW) woud need to be abe to read nputs
from a cong e and perform the foowng conguratons on Phantom|S. We are
exbe on how the at e s structured.

1. Abty to Set Custom Headers for a pages/requests (eg:-
phantom|s.page.customHeaders.Accept-Language=en-US)
2. Abty to pass command ne arguments to Phantom|S (eg:- oad-mages,
dsk-cache, cookes-e, etc)
3. Appyng page.settngs to Phantom|S (eg:- resourceTmeout, etc)
4. Abty to Set Phantom|S wndow Sze (Important: - Not VewPort Sze but
Wndow Sze)
5. Abty to Add Cookes to Phantom|S Cooke|ar
6. Abty to extract ALL cookes from Phantom|S cooke|ar
7. Abty to Incude mutpe |S es to a pages/requests (eg:- |Ouery, etc)
XML Structure:
The CFW s to parse the XML and generate Casper|S code. If the XML code s
updated, runnng t through the CFW w produce an updated Casper|S scrpt.
The XML structure s composed of tags wth mutpe attrbutes and each tag may or
may not have content (Some tags are empty whe others are not). A sampe of the
XML structure and detas of the tags are provded beow
Sampe XML
<actvty actve="true">
<ste d="1" name="googe" actve="true">
<steps>
<goto ur="http://www.googe.com/" />
<wat type="s" vaue="3" mutper="1" />
<cear by="cssseector" eement="nput|type='text'|" />
<type by="cssseector" eement="nput|type='text'|" keys="what s
casper|s" />
<acton vaue="Enter" />
<wat type="s" vaue="5" />
<oop count="4">
<cck by="cssseector" eement="dv#search h3.r a" eementndex="I" />
<wat type="s" vaue="20" />
<screenshot/>
<navgateback />
</oop>
</steps>
</ste>
</actvty>
<actvty>
Ths s the root tag whch denotes the start of an actvty and smar to openng a
new browser wndow. The actvty tag s composed of one or more <ste></ste>
tag chdren. Note: Pror to the actvty tag s when a the Conguraton tems are
set
</actvty>
The end of the actvty tag (smar to cosng your browser) s where you ext
Phantom|S. Pror to extng, a the cookes w need to be extracted and passed to
the cang appcaton/scrpt (or wrtten to a e)
<ste >
Attrbutes:
d="1" (1,2,3, etc)
name="XYZ"
actve="true" (true OR fase) - Stes that have ths ag set to fase are NOT
to be processed
The ste tag denotes the start of a ste wthn an actvty. The ste tag w consst 1
chd tag <steps></steps>
</ste>
Ths s the end of the ste tag
<steps></steps>
The content wthn the steps tags s what needs to be processed
<goto />
Attrbutes:
ur="http://www.googe.com"
The goto tag s a straghtforward tag whch speces the URL of the webste. It s an
empty tag (no content)
<wat />
Attrbutes:
type="s" (s=seconds, m=mnutes)
vaue="6" (number of seconds/mnutes to wat)
mutper="1" (mutpes of vaue to wat, so mutper =2 sgnes watng
for 12 seconds)
<screenshot />
Take a screenshot of the page and save e wth ename
"screenshot_yyyyMMddhhmmss.png"
<navgateback />
Back button on browser
<navgateforward />
Forward button on browser
<refresh />
Refresh current browser tab/wndow
<swtchtab />
Attrbutes:
ndex="0" (0, 1, 2, etc.) - Swtch tab/wndow to the ndex speced (0 s the
rst tab/wndow)
Note: If the attrbute "ndex" s not speced then swtch to the most recent
tab/wndow (eg: f there are 5 wndows, swtch to the fth tab). When swtchng to
another tab/wndow, a conguratons especay wndow sze shoud be
mantaned
<cosetab />
Attrbutes:
ndex="0" (0, 1, 2, etc.) - Cose tab/wndow of the ndex speced (0 s the
rst tab/wndow)
Note: If the attrbute "ndex" s not speced then cose a tabs/wndows except the
orgna tab/wndow (ndex="0"). Snce a other tabs are cosed, contro shoud
automatcay shft to orgna tab wth ndex="0"
<cear/>
Attrbutes:
by="cssseector" (cssseector, d, name, cassname, xpath, partanktext) -
by attrbute used to nd the eement
eement=" dv#search h3.r a" - css seector (n ths case) to nd eement
If mutpe eements are found, then pck the rst eement
<type/>
Attrbutes:
by="cssseector" (cssseector, d, name, cassname, xpath, partanktext) -
by attrbute used to nd the eement
eement=" dv#search h3.r a" - css seector (n ths case) to nd eement
keys = "what s casper|s" - Text that s to be typed nto the eement
If mutpe eements are found, then pck the rst eement
<acton/>
Attrbutes:
vaue="PageUp" (PageUp, PageDown, Enter, Escape, Tab, Backspace, Deete,
Contro, Up, Rght, Left, Down) - Execute ths acton on the current page.
Note: The CFW shoud be abe to read ths vaue rrespectve of Case. So
PageUp and pageup shoud both be processed the same
<executescrpt/>
Attrbutes:
name="bahbah.|s" In|ect the |avascrpt n ths e to run on the current page
<swtchto/>
Attrbutes:
by="cssseector" (cssseector, d, name, cassname, xpath, partanktext) -
by attrbute used to nd the eement
eement=" dv#search h3.r a" - css seector (n ths case) to nd eement
Ths tag s typcay used when the webpage has IFrames. In order to nteract wth
eements wthn the frame, one must rst swtch to the frame
<oop></oop>
Attrbutes:
count="4" (1, 2, 3, etc.) Number of tmes to oop
Loop through a the content wthn the oop tags mutpe tmes (speced by the
count attrbute)
<assert></assert>
Attrbutes:
by="cssseector" (cssseector, d, name, cassname, xpath, partanktext) -
by attrbute used to nd the eement
eement=" dv#search h3.r a" - css seector (n ths case) to nd eement
Assert f there are any eements that can be found. If one or more eements are
found, then execute a the steps wthn the <assert></assert> tags. If no eements
are found then skp everythng wthn the assert tags
<cck/>
Attrbutes:
by="partanktext" (cssseector, d, name, cassname, xpath, partanktext)
- by attrbute used to nd the eement
eement=" Search Resuts" - parta strng of the nk on the webpage
eementndex="I" (I, R, R21) - Ths attrbute s reevant ony when mutpe
eements are found
o f ths attrbute s not speced, then return the rst eement
o R - use a random number generator to return a random eement from
st of eements found
o R21 - use a random number generator to pck an eement ony from
the rst 21 eements. Note: If there are ess than 21 eements found,
then randomy pck from number of eements found (21 s |ust used
here as an exampe, t coud be anythng)
o I - Ths w be used when the cck s wthn the oop tags and the oop
ndex s to be used to return the eement. Exampe f there s a oop
wth count=5, then on the rst go around, return the rst eement; on
the second go around of the oop, return the second eement, etc.
Note: f the oop ndex s hgher than the tota number of eements
found, then |ust randomy pck an eement (usng random number
generator)
contnue="true" (true or fase)- f no eements are found, do not throw an
error, |ust contnue. If ths s attrbute s not speced, then throw an error f
no eement s found
The cck tag shoud have the same underyng ogc as the <assert> tags; If no
eements are found, ether throw an error or contnue based on the contnue
attrbute. When mutpe eements are found, use the ogc descrbed n the
eementndex attrbute and cck on the reevant eement
<hover/>
Attrbutes:
by="partanktext" (cssseector, d, name, cassname, xpath, partanktext)
- by attrbute used to nd the eement
eement=" Search Resuts" - parta strng of the nk on the webpage
eementndex="I" (I, R, R21) - Ths attrbute s reevant ony when mutpe
eements are found
o f ths attrbute s not speced, then return the rst eement
o R - use a random number generator to return a random eement from
st of eements found
o R21 - use a random number generator to pck an eement ony from
the rst 21 eements. Note: If there are ess than 21 eements found,
then randomy pck from number of eements found (21 s |ust used
here as an exampe, t coud be anythng)
o I - Ths w be used when the cck s wthn the oop tags and the oop
ndex s to be used to return the eement. Exampe f there s a oop
wth count=5, then on the rst go around, return the rst eement; on
the second go around of the oop, return the second eement, etc.
Note: f the oop ndex s hgher than the tota number of eements
found, then |ust randomy pck an eement (usng random number
generator)
contnue="true" (true or fase)- f no eements are found, do not throw an
error, |ust contnue. If ths s attrbute s not speced, then throw an error f
no eement s found
The hover tag shoud have the same underyng ogc as the <assert> tags; If no
eements are found, ether throw an error or contnue based on the contnue
attrbute. When mutpe eements are found, use the ogc descrbed n the
eementndex attrbute and hover on the reevant eement
<hovercck/>
Attrbutes:
by="partanktext" (cssseector, d, name, cassname, xpath, partanktext)
- by attrbute used to nd the eement
eement=" Search Resuts" - parta strng of the nk on the webpage
eementndex="I" (I, R, R21) - Ths attrbute s reevant ony when mutpe
eements are found
o f ths attrbute s not speced, then return the rst eement
o R - use a random number generator to return a random eement from
st of eements found
o R21 - use a random number generator to pck an eement ony from
the rst 21 eements. Note: If there are ess than 21 eements found,
then randomy pck from number of eements found (21 s |ust used
here as an exampe, t coud be anythng)
o I - Ths w be used when the cck s wthn the oop tags and the oop
ndex s to be used to return the eement. Exampe f there s a oop
wth count=5, then on the rst go around, return the rst eement; on
the second go around of the oop, return the second eement, etc.
Note: f the oop ndex s hgher than the tota number of eements
found, then |ust randomy pck an eement (usng random number
generator)
contnue="true" (true or fase)- f no eements are found, do not throw an
error, |ust contnue. If ths s attrbute s not speced, then throw an error f
no eement s found
The hovercck tag shoud have the same underyng ogc as the <assert> tags; If
no eements are found, ether throw an error or contnue based on the contnue
attrbute. When mutpe eements are found, use the ogc descrbed n the
eementndex attrbute and hover on the reevant eement foowed by a cck n
the same page ocaton of the hover
<seect/>
Attrbutes:
by="cssseector" (cssseector, d, name, cassname, xpath, partanktext) -
by attrbute used to nd the eement
eement=" dv#search h3.r a" - css seector (n ths case) to nd eement
seectbytext="A" - seect opton based on text wthn opton
seectbyvaue="a" - seect opton based on vaue of opton
seectbyndex="1" (0, 1, 2, 3, etc) - seect opton based on ts ndex (startng
from 0)
If mutpe eements are found, then pck the rst eement. Of the attrbutes ony
one of the "seectby" attrbutes w be speced (seectbytext OR seectbyvaue OR
seectbyndex)
RunTime Confgurations:
Durng the runnng of Casper|S, the foowng optons are needed wth the abty to
congure them
1. Loggng
a. Entry n Cong e to specfy the Loggng drectory
b. Log es w be of format "yyyyMMdd.og" and a new e w be
created for each new day. A og entres n a gven day to be appended
to the end of e for that day
c. Entry n Cong e to specfy oggng eve - Verbose OR Concse
d. Verbose Loggng w ncude ogs for each xm tag processed
e. Concse Loggng w ony specfy when Actvtes and Stes are started
and nshed
2. Force Page Stop
a. Due to varous reasons ke ads takng too ong to oad, a page may not
oad for a consderabe tme. Hence we need to force the page oad to
stop after 60 seconds
b. Ths tme (n seconds) shoud be an entry n the cong e
Error and!ing:
Durng the course of any gven run, errors occur for a varety of reasons. We are
open to suggestons on better handng these, but we have outned a few optons
here that need to be but n. IMPORTANTLY: Once these optons are attempted, t s
mportant to retry the operaton that caused the error (Most of the tme t s a cck
operaton)
1. Handng Modas: Many tmes eements on a page or not vsbe or cckabe
because of modas. We are open to suggestons on how to dea wth these. If
there are no better suggestons, we suggest dong the foowng n the same
order as suggested beow.
a. Ht the Escape key (Ths sometmes coses modas)
b. Refresh the page
c. Cck on the cose con for the moda. Snce these are not easy to nd
for a headess browser, cck on eements that are read from a
CoseCong e. The e contents are shown beow. Fnd each of these
eements usng the by attrbute and f an eement s found, cck t.
<cose>
<type vaue="|tte*='cose'|" by="cssseector" />
<type vaue="|cass*='DecneButton'|" by="cssseector" />
<type vaue="|cass*='CoseBtn'|" by="cssseector" />
<type vaue="|cass*='Cose'|" by="cssseector" />
</cose>
d. In|ect a |avascrpt e "ErrModa.|s" nto the current page
2. Server Errors: Sometmes there are server errors, and these can be handed
as foows
a. 408 Errors: Refresh the page (ths s the best way to dea wth 408
errors)
If tryng to x the errors and retryng does not resove the error, then, the foowng
steps need to be taken
1. Save a Screenshot e of the current page (ename:
error_yyyyMMddHHmmss.png)
2. Make note of the partcuar ste wthn the actvty that faed, and at the end
of the actvty, rerun any faed stes 1 more tme (Do not rerun f t fas agan
as ths w cause an nnte oop)

Вам также может понравиться