selenium-webdriver.d.ts 192 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864
  1. // Type definitions for Selenium WebDriverJS 2.44.0
  2. // Project: https://code.google.com/p/selenium/
  3. // Definitions by: Bill Armstrong <https://github.com/BillArmstrong>
  4. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  5. declare module chrome {
  6. /**
  7. * Creates a new WebDriver client for Chrome.
  8. *
  9. * @extends {webdriver.WebDriver}
  10. */
  11. class Driver extends webdriver.WebDriver {
  12. /**
  13. * @param {(webdriver.Capabilities|Options)=} opt_config The configuration
  14. * options.
  15. * @param {remote.DriverService=} opt_service The session to use; will use
  16. * the {@link getDefaultService default service} by default.
  17. * @param {webdriver.promise.ControlFlow=} opt_flow The control flow to use, or
  18. * {@code null} to use the currently active flow.
  19. * @constructor
  20. */
  21. constructor(opt_config?: webdriver.Capabilities, opt_service?: any, opt_flow?: webdriver.promise.ControlFlow);
  22. constructor(opt_config?: Options, opt_service?: any, opt_flow?: webdriver.promise.ControlFlow);
  23. }
  24. interface IOptionsValues {
  25. args: string[];
  26. binary?: string;
  27. detach: boolean;
  28. extensions: string[];
  29. localState?: any;
  30. logFile?: string;
  31. prefs?: any;
  32. }
  33. /**
  34. * Class for managing ChromeDriver specific options.
  35. */
  36. class Options {
  37. /**
  38. * @constructor
  39. */
  40. constructor();
  41. /**
  42. * Extracts the ChromeDriver specific options from the given capabilities
  43. * object.
  44. * @param {!webdriver.Capabilities} capabilities The capabilities object.
  45. * @return {!Options} The ChromeDriver options.
  46. */
  47. static fromCapabilities(capabilities: webdriver.Capabilities): Options;
  48. /**
  49. * Add additional command line arguments to use when launching the Chrome
  50. * browser. Each argument may be specified with or without the "--" prefix
  51. * (e.g. "--foo" and "foo"). Arguments with an associated value should be
  52. * delimited by an "=": "foo=bar".
  53. * @param {...(string|!Array.<string>)} var_args The arguments to add.
  54. * @return {!Options} A self reference.
  55. */
  56. addArguments(...var_args: string[]): Options;
  57. /**
  58. * Add additional extensions to install when launching Chrome. Each extension
  59. * should be specified as the path to the packed CRX file, or a Buffer for an
  60. * extension.
  61. * @param {...(string|!Buffer|!Array.<(string|!Buffer)>)} var_args The
  62. * extensions to add.
  63. * @return {!Options} A self reference.
  64. */
  65. addExtensions(...var_args: any[]): Options;
  66. /**
  67. * Sets the path to the Chrome binary to use. On Mac OS X, this path should
  68. * reference the actual Chrome executable, not just the application binary
  69. * (e.g. "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome").
  70. *
  71. * The binary path be absolute or relative to the chromedriver server
  72. * executable, but it must exist on the machine that will launch Chrome.
  73. *
  74. * @param {string} path The path to the Chrome binary to use.
  75. * @return {!Options} A self reference.
  76. */
  77. setChromeBinaryPath(path: string): Options;
  78. /**
  79. * Sets whether to leave the started Chrome browser running if the controlling
  80. * ChromeDriver service is killed before {@link webdriver.WebDriver#quit()} is
  81. * called.
  82. * @param {boolean} detach Whether to leave the browser running if the
  83. * chromedriver service is killed before the session.
  84. * @return {!Options} A self reference.
  85. */
  86. detachDriver(detach: boolean): Options;
  87. /**
  88. * Sets the user preferences for Chrome's user profile. See the "Preferences"
  89. * file in Chrome's user data directory for examples.
  90. * @param {!Object} prefs Dictionary of user preferences to use.
  91. * @return {!Options} A self reference.
  92. */
  93. setUserPreferences(prefs: any): Options;
  94. /**
  95. * Sets the logging preferences for the new session.
  96. * @param {!webdriver.logging.Preferences} prefs The logging preferences.
  97. * @return {!Options} A self reference.
  98. */
  99. setLoggingPrefs(prefs: webdriver.logging.Preferences): Options;
  100. /**
  101. * Sets preferences for the "Local State" file in Chrome's user data
  102. * directory.
  103. * @param {!Object} state Dictionary of local state preferences.
  104. * @return {!Options} A self reference.
  105. */
  106. setLocalState(state: any): Options;
  107. /**
  108. * Sets the path to Chrome's log file. This path should exist on the machine
  109. * that will launch Chrome.
  110. * @param {string} path Path to the log file to use.
  111. * @return {!Options} A self reference.
  112. */
  113. setChromeLogFile(path: string): Options;
  114. /**
  115. * Sets the proxy settings for the new session.
  116. * @param {webdriver.ProxyConfig} proxy The proxy configuration to use.
  117. * @return {!Options} A self reference.
  118. */
  119. setProxy(proxy: webdriver.ProxyConfig): Options;
  120. /**
  121. * Converts this options instance to a {@link webdriver.Capabilities} object.
  122. * @param {webdriver.Capabilities=} opt_capabilities The capabilities to merge
  123. * these options into, if any.
  124. * @return {!webdriver.Capabilities} The capabilities.
  125. */
  126. toCapabilities(opt_capabilities?: webdriver.Capabilities): webdriver.Capabilities;
  127. /**
  128. * Converts this instance to its JSON wire protocol representation. Note this
  129. * function is an implementation not intended for general use.
  130. * @return {{args: !Array.<string>,
  131. * binary: (string|undefined),
  132. * detach: boolean,
  133. * extensions: !Array.<string>,
  134. * localState: (Object|undefined),
  135. * logFile: (string|undefined),
  136. * prefs: (Object|undefined)}} The JSON wire protocol representation
  137. * of this instance.
  138. */
  139. toJSON(): IOptionsValues;
  140. }
  141. /**
  142. * Creates {@link remote.DriverService} instances that manage a ChromeDriver
  143. * server.
  144. */
  145. class ServiceBuilder {
  146. /**
  147. * @param {string=} opt_exe Path to the server executable to use. If omitted,
  148. * the builder will attempt to locate the chromedriver on the current
  149. * PATH.
  150. * @throws {Error} If provided executable does not exist, or the chromedriver
  151. * cannot be found on the PATH.
  152. * @constructor
  153. */
  154. constructor(opt_exe?: string);
  155. /**
  156. * Sets the port to start the ChromeDriver on.
  157. * @param {number} port The port to use, or 0 for any free port.
  158. * @return {!ServiceBuilder} A self reference.
  159. * @throws {Error} If the port is invalid.
  160. */
  161. usingPort(port: number): ServiceBuilder;
  162. /**
  163. * Sets the path of the log file the driver should log to. If a log file is
  164. * not specified, the driver will log to stderr.
  165. * @param {string} path Path of the log file to use.
  166. * @return {!ServiceBuilder} A self reference.
  167. */
  168. loggingTo(path: string): ServiceBuilder;
  169. /**
  170. * Enables verbose logging.
  171. * @return {!ServiceBuilder} A self reference.
  172. */
  173. enableVerboseLogging(): ServiceBuilder;
  174. /**
  175. * Sets the number of threads the driver should use to manage HTTP requests.
  176. * By default, the driver will use 4 threads.
  177. * @param {number} n The number of threads to use.
  178. * @return {!ServiceBuilder} A self reference.
  179. */
  180. setNumHttpThreads(n: number): ServiceBuilder;
  181. /**
  182. * Sets the base path for WebDriver REST commands (e.g. "/wd/hub").
  183. * By default, the driver will accept commands relative to "/".
  184. * @param {string} path The base path to use.
  185. * @return {!ServiceBuilder} A self reference.
  186. */
  187. setUrlBasePath(path: string): ServiceBuilder;
  188. /**
  189. * Defines the stdio configuration for the driver service. See
  190. * {@code child_process.spawn} for more information.
  191. * @param {(string|!Array.<string|number|!Stream|null|undefined>)} config The
  192. * configuration to use.
  193. * @return {!ServiceBuilder} A self reference.
  194. */
  195. setStdio(config: string): ServiceBuilder;
  196. setStdio(config: any[]): ServiceBuilder;
  197. /**
  198. * Defines the environment to start the server under. This settings will be
  199. * inherited by every browser session started by the server.
  200. * @param {!Object.<string, string>} env The environment to use.
  201. * @return {!ServiceBuilder} A self reference.
  202. */
  203. withEnvironment(env: { [key: string]: string }): ServiceBuilder;
  204. /**
  205. * Creates a new DriverService using this instance's current configuration.
  206. * @return {remote.DriverService} A new driver service using this instance's
  207. * current configuration.
  208. * @throws {Error} If the driver exectuable was not specified and a default
  209. * could not be found on the current PATH.
  210. */
  211. build(): any;
  212. }
  213. /**
  214. * Returns the default ChromeDriver service. If such a service has not been
  215. * configured, one will be constructed using the default configuration for
  216. * a ChromeDriver executable found on the system PATH.
  217. * @return {!remote.DriverService} The default ChromeDriver service.
  218. */
  219. function getDefaultService(): any;
  220. /**
  221. * Sets the default service to use for new ChromeDriver instances.
  222. * @param {!remote.DriverService} service The service to use.
  223. * @throws {Error} If the default service is currently running.
  224. */
  225. function setDefaultService(service: any): void;
  226. }
  227. declare module firefox {
  228. /**
  229. * Manages a Firefox subprocess configured for use with WebDriver.
  230. */
  231. class Binary {
  232. /**
  233. * @param {string=} opt_exe Path to the Firefox binary to use. If not
  234. * specified, will attempt to locate Firefox on the current system.
  235. * @constructor
  236. */
  237. constructor(opt_exe?: string);
  238. /**
  239. * Add arguments to the command line used to start Firefox.
  240. * @param {...(string|!Array.<string>)} var_args Either the arguments to add as
  241. * varargs, or the arguments as an array.
  242. */
  243. addArguments(...var_args: string[]): void;
  244. /**
  245. * Launches Firefox and eturns a promise that will be fulfilled when the process
  246. * terminates.
  247. * @param {string} profile Path to the profile directory to use.
  248. * @return {!promise.Promise.<!exec.Result>} A promise for the process result.
  249. * @throws {Error} If this instance has already been started.
  250. */
  251. launch(profile: string): webdriver.promise.Promise<any>;
  252. /**
  253. * Kills the managed Firefox process.
  254. * @return {!promise.Promise} A promise for when the process has terminated.
  255. */
  256. kill(): webdriver.promise.Promise<void>;
  257. }
  258. /**
  259. * A WebDriver client for Firefox.
  260. *
  261. * @extends {webdriver.WebDriver}
  262. */
  263. class Driver extends webdriver.WebDriver {
  264. /**
  265. * @param {(Options|webdriver.Capabilities|Object)=} opt_config The
  266. * configuration options for this driver, specified as either an
  267. * {@link Options} or {@link webdriver.Capabilities}, or as a raw hash
  268. * object.
  269. * @param {webdriver.promise.ControlFlow=} opt_flow The flow to
  270. * schedule commands through. Defaults to the active flow object.
  271. * @constructor
  272. */
  273. constructor(opt_config?: webdriver.Capabilities, opt_flow?: webdriver.promise.ControlFlow);
  274. constructor(opt_config?: any, opt_flow?: webdriver.promise.ControlFlow);
  275. }
  276. /**
  277. * Configuration options for the FirefoxDriver.
  278. */
  279. class Options {
  280. /**
  281. * @constructor
  282. */
  283. constructor();
  284. /**
  285. * Sets the profile to use. The profile may be specified as a
  286. * {@link Profile} object or as the path to an existing Firefox profile to use
  287. * as a template.
  288. *
  289. * @param {(string|!Profile)} profile The profile to use.
  290. * @return {!Options} A self reference.
  291. */
  292. setProfile(profile: string): Options;
  293. setProfile(profile: Profile): Options;
  294. /**
  295. * Sets the binary to use. The binary may be specified as the path to a Firefox
  296. * executable, or as a {@link Binary} object.
  297. *
  298. * @param {(string|!Binary)} binary The binary to use.
  299. * @return {!Options} A self reference.
  300. */
  301. setBinary(binary: string): Options;
  302. setBinary(binary: Binary): Options;
  303. /**
  304. * Sets the logging preferences for the new session.
  305. * @param {webdriver.logging.Preferences} prefs The logging preferences.
  306. * @return {!Options} A self reference.
  307. */
  308. setLoggingPreferences(prefs: webdriver.logging.Preferences): Options;
  309. /**
  310. * Sets the proxy to use.
  311. *
  312. * @param {webdriver.ProxyConfig} proxy The proxy configuration to use.
  313. * @return {!Options} A self reference.
  314. */
  315. setProxy(proxy: webdriver.ProxyConfig): Options;
  316. /**
  317. * Converts these options to a {@link webdriver.Capabilities} instance.
  318. *
  319. * @return {!webdriver.Capabilities} A new capabilities object.
  320. */
  321. toCapabilities(opt_remote?: any): webdriver.Capabilities;
  322. }
  323. /**
  324. * Models a Firefox proifle directory for use with the FirefoxDriver. The
  325. * {@code Proifle} directory uses an in-memory model until {@link #writeToDisk}
  326. * is called.
  327. */
  328. class Profile {
  329. /**
  330. * @param {string=} opt_dir Path to an existing Firefox profile directory to
  331. * use a template for this profile. If not specified, a blank profile will
  332. * be used.
  333. * @constructor
  334. */
  335. constructor(opt_dir?: string);
  336. /**
  337. * Registers an extension to be included with this profile.
  338. * @param {string} extension Path to the extension to include, as either an
  339. * unpacked extension directory or the path to a xpi file.
  340. */
  341. addExtension(extension: string): void;
  342. /**
  343. * Sets a desired preference for this profile.
  344. * @param {string} key The preference key.
  345. * @param {(string|number|boolean)} value The preference value.
  346. * @throws {Error} If attempting to set a frozen preference.
  347. */
  348. setPreference(key: string, value: string): void;
  349. setPreference(key: string, value: number): void;
  350. setPreference(key: string, value: boolean): void;
  351. /**
  352. * Returns the currently configured value of a profile preference. This does
  353. * not include any defaults defined in the profile's template directory user.js
  354. * file (if a template were specified on construction).
  355. * @param {string} key The desired preference.
  356. * @return {(string|number|boolean|undefined)} The current value of the
  357. * requested preference.
  358. */
  359. getPreference(key: string): any;
  360. /**
  361. * @return {number} The port this profile is currently configured to use, or
  362. * 0 if the port will be selected at random when the profile is written
  363. * to disk.
  364. */
  365. getPort(): number;
  366. /**
  367. * Sets the port to use for the WebDriver extension loaded by this profile.
  368. * @param {number} port The desired port, or 0 to use any free port.
  369. */
  370. setPort(port: number): void;
  371. /**
  372. * @return {boolean} Whether the FirefoxDriver is configured to automatically
  373. * accept untrusted SSL certificates.
  374. */
  375. acceptUntrustedCerts(): boolean;
  376. /**
  377. * Sets whether the FirefoxDriver should automatically accept untrusted SSL
  378. * certificates.
  379. * @param {boolean} value .
  380. */
  381. setAcceptUntrustedCerts(value: boolean): void;
  382. /**
  383. * Sets whether to assume untrusted certificates come from untrusted issuers.
  384. * @param {boolean} value .
  385. */
  386. setAssumeUntrustedCertIssuer(value: boolean): void;
  387. /**
  388. * @return {boolean} Whether to assume untrusted certs come from untrusted
  389. * issuers.
  390. */
  391. assumeUntrustedCertIssuer(): boolean;
  392. /**
  393. * Sets whether to use native events with this profile.
  394. * @param {boolean} enabled .
  395. */
  396. setNativeEventsEnabled(enabled: boolean): void;
  397. /**
  398. * Returns whether native events are enabled in this profile.
  399. * @return {boolean} .
  400. */
  401. nativeEventsEnabled(): boolean;
  402. /**
  403. * Writes this profile to disk.
  404. * @param {boolean=} opt_excludeWebDriverExt Whether to exclude the WebDriver
  405. * extension from the generated profile. Used to reduce the size of an
  406. * {@link #encode() encoded profile} since the server will always install
  407. * the extension itself.
  408. * @return {!promise.Promise.<string>} A promise for the path to the new
  409. * profile directory.
  410. */
  411. writeToDisk(opt_excludeWebDriverExt?: boolean): webdriver.promise.Promise<string>;
  412. /**
  413. * Encodes this profile as a zipped, base64 encoded directory.
  414. * @return {!promise.Promise.<string>} A promise for the encoded profile.
  415. */
  416. encode(): webdriver.promise.Promise<string>;
  417. }
  418. }
  419. declare module executors {
  420. /**
  421. * Creates a command executor that uses WebDriver's JSON wire protocol.
  422. * @param url The server's URL, or a promise that will resolve to that URL.
  423. * @returns {!webdriver.CommandExecutor} The new command executor.
  424. */
  425. function createExecutor(url: string): webdriver.CommandExecutor;
  426. function createExecutor(url: webdriver.promise.Promise<string>): webdriver.CommandExecutor;
  427. }
  428. declare module webdriver {
  429. module error {
  430. interface IErrorCode {
  431. SUCCESS: number;
  432. NO_SUCH_ELEMENT: number;
  433. NO_SUCH_FRAME: number;
  434. UNKNOWN_COMMAND: number;
  435. UNSUPPORTED_OPERATION: number; // Alias for UNKNOWN_COMMAND.
  436. STALE_ELEMENT_REFERENCE: number;
  437. ELEMENT_NOT_VISIBLE: number;
  438. INVALID_ELEMENT_STATE: number;
  439. UNKNOWN_ERROR: number;
  440. ELEMENT_NOT_SELECTABLE: number;
  441. JAVASCRIPT_ERROR: number;
  442. XPATH_LOOKUP_ERROR: number;
  443. TIMEOUT: number;
  444. NO_SUCH_WINDOW: number;
  445. INVALID_COOKIE_DOMAIN: number;
  446. UNABLE_TO_SET_COOKIE: number;
  447. MODAL_DIALOG_OPENED: number;
  448. UNEXPECTED_ALERT_OPEN: number;
  449. NO_SUCH_ALERT: number;
  450. NO_MODAL_DIALOG_OPEN: number;
  451. SCRIPT_TIMEOUT: number;
  452. INVALID_ELEMENT_COORDINATES: number;
  453. IME_NOT_AVAILABLE: number;
  454. IME_ENGINE_ACTIVATION_FAILED: number;
  455. INVALID_SELECTOR_ERROR: number;
  456. SESSION_NOT_CREATED: number;
  457. MOVE_TARGET_OUT_OF_BOUNDS: number;
  458. SQL_DATABASE_ERROR: number;
  459. INVALID_XPATH_SELECTOR: number;
  460. INVALID_XPATH_SELECTOR_RETURN_TYPE: number;
  461. // The following error codes are derived straight from HTTP return codes.
  462. METHOD_NOT_ALLOWED: number;
  463. }
  464. var ErrorCode: IErrorCode;
  465. /**
  466. * Error extension that includes error status codes from the WebDriver wire
  467. * protocol:
  468. * http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes
  469. *
  470. * @extends {Error}
  471. */
  472. class Error {
  473. //region Constructors
  474. /**
  475. * @param {!bot.ErrorCode} code The error's status code.
  476. * @param {string=} opt_message Optional error message.
  477. * @constructor
  478. */
  479. constructor(code: number, opt_message?: string);
  480. //endregion
  481. //region Static Properties
  482. /**
  483. * Status strings enumerated in the W3C WebDriver working draft.
  484. * @enum {string}
  485. * @see http://www.w3.org/TR/webdriver/#status-codes
  486. */
  487. static State: {
  488. ELEMENT_NOT_SELECTABLE: string;
  489. ELEMENT_NOT_VISIBLE: string;
  490. IME_ENGINE_ACTIVATION_FAILED: string;
  491. IME_NOT_AVAILABLE: string;
  492. INVALID_COOKIE_DOMAIN: string;
  493. INVALID_ELEMENT_COORDINATES: string;
  494. INVALID_ELEMENT_STATE: string;
  495. INVALID_SELECTOR: string;
  496. JAVASCRIPT_ERROR: string;
  497. MOVE_TARGET_OUT_OF_BOUNDS: string;
  498. NO_SUCH_ALERT: string;
  499. NO_SUCH_DOM: string;
  500. NO_SUCH_ELEMENT: string;
  501. NO_SUCH_FRAME: string;
  502. NO_SUCH_WINDOW: string;
  503. SCRIPT_TIMEOUT: string;
  504. SESSION_NOT_CREATED: string;
  505. STALE_ELEMENT_REFERENCE: string;
  506. SUCCESS: string;
  507. TIMEOUT: string;
  508. UNABLE_TO_SET_COOKIE: string;
  509. UNEXPECTED_ALERT_OPEN: string;
  510. UNKNOWN_COMMAND: string;
  511. UNKNOWN_ERROR: string;
  512. UNSUPPORTED_OPERATION: string;
  513. }
  514. //endregion
  515. //region Properties
  516. /**
  517. * This error's status code.
  518. * @type {!bot.ErrorCode}
  519. */
  520. code: number;
  521. /** @type {string} */
  522. state: string;
  523. /** @override */
  524. message: string;
  525. /** @override */
  526. name: string;
  527. /** @override */
  528. stack: string;
  529. /**
  530. * Flag used for duck-typing when this code is embedded in a Firefox extension.
  531. * This is required since an Error thrown in one component and then reported
  532. * to another will fail instanceof checks in the second component.
  533. * @type {boolean}
  534. */
  535. isAutomationError: boolean;
  536. //endregion
  537. //region Methods
  538. /** @return {string} The string representation of this error. */
  539. toString(): string;
  540. //endregion
  541. }
  542. }
  543. module logging {
  544. /**
  545. * A hash describing log preferences.
  546. * @typedef {Object.<webdriver.logging.Type, webdriver.logging.LevelName>}
  547. */
  548. class Preferences {
  549. setLevel(type: string, level: ILevel): void;
  550. toJSON(): { [key: string]: string };
  551. }
  552. interface IType {
  553. /** Logs originating from the browser. */
  554. BROWSER: string;
  555. /** Logs from a WebDriver client. */
  556. CLIENT: string;
  557. /** Logs from a WebDriver implementation. */
  558. DRIVER: string;
  559. /** Logs related to performance. */
  560. PERFORMANCE: string;
  561. /** Logs from the remote server. */
  562. SERVER: string;
  563. }
  564. /**
  565. * Common log types.
  566. * @enum {string}
  567. */
  568. var Type: IType;
  569. /**
  570. * Logging levels.
  571. * @enum {{value: number, name: webdriver.logging.LevelName}}
  572. */
  573. interface ILevel {
  574. value: number;
  575. name: string;
  576. }
  577. interface ILevelValues {
  578. ALL: ILevel;
  579. DEBUG: ILevel;
  580. INFO: ILevel;
  581. WARNING: ILevel;
  582. SEVERE: ILevel;
  583. OFF: ILevel;
  584. }
  585. var Level: ILevelValues;
  586. /**
  587. * Converts a level name or value to a {@link webdriver.logging.Level} value.
  588. * If the name/value is not recognized, {@link webdriver.logging.Level.ALL}
  589. * will be returned.
  590. * @param {(number|string)} nameOrValue The log level name, or value, to
  591. * convert .
  592. * @return {!webdriver.logging.Level} The converted level.
  593. */
  594. function getLevel(nameOrValue: string): ILevel;
  595. function getLevel(nameOrValue: number): ILevel;
  596. interface IEntryJSON {
  597. level: string;
  598. message: string;
  599. timestamp: number;
  600. type: string;
  601. }
  602. /**
  603. * A single log entry.
  604. */
  605. class Entry {
  606. //region Constructors
  607. /**
  608. * @param {(!webdriver.logging.Level|string)} level The entry level.
  609. * @param {string} message The log message.
  610. * @param {number=} opt_timestamp The time this entry was generated, in
  611. * milliseconds since 0:00:00, January 1, 1970 UTC. If omitted, the
  612. * current time will be used.
  613. * @param {string=} opt_type The log type, if known.
  614. * @constructor
  615. */
  616. constructor(level: ILevel, message: string, opt_timestamp?:number, opt_type?:string);
  617. constructor(level: string, message: string, opt_timestamp?:number, opt_type?:string);
  618. //endregion
  619. //region Public Properties
  620. /** @type {!webdriver.logging.Level} */
  621. level: ILevel;
  622. /** @type {string} */
  623. message: string;
  624. /** @type {number} */
  625. timestamp: number;
  626. /** @type {string} */
  627. type: string;
  628. //endregion
  629. //region Static Methods
  630. /**
  631. * Converts a {@link goog.debug.LogRecord} into a
  632. * {@link webdriver.logging.Entry}.
  633. * @param {!goog.debug.LogRecord} logRecord The record to convert.
  634. * @param {string=} opt_type The log type.
  635. * @return {!webdriver.logging.Entry} The converted entry.
  636. */
  637. static fromClosureLogRecord(logRecord: any, opt_type?:string): Entry;
  638. //endregion
  639. //region Methods
  640. /**
  641. * @return {{level: string, message: string, timestamp: number,
  642. * type: string}} The JSON representation of this entry.
  643. */
  644. toJSON(): IEntryJSON;
  645. //endregion
  646. }
  647. }
  648. module promise {
  649. //region Functions
  650. /**
  651. * Given an array of promises, will return a promise that will be fulfilled
  652. * with the fulfillment values of the input array's values. If any of the
  653. * input array's promises are rejected, the returned promise will be rejected
  654. * with the same reason.
  655. *
  656. * @param {!Array.<(T|!webdriver.promise.Promise.<T>)>} arr An array of
  657. * promises to wait on.
  658. * @return {!webdriver.promise.Promise.<!Array.<T>>} A promise that is
  659. * fulfilled with an array containing the fulfilled values of the
  660. * input array, or rejected with the same reason as the first
  661. * rejected value.
  662. * @template T
  663. */
  664. function all(arr: Promise<any>[]): Promise<any[]>;
  665. /**
  666. * Invokes the appropriate callback function as soon as a promised
  667. * {@code value} is resolved. This function is similar to
  668. * {@link webdriver.promise.when}, except it does not return a new promise.
  669. * @param {*} value The value to observe.
  670. * @param {Function} callback The function to call when the value is
  671. * resolved successfully.
  672. * @param {Function=} opt_errback The function to call when the value is
  673. * rejected.
  674. */
  675. function asap(value: any, callback: Function, opt_errback?: Function): void;
  676. /**
  677. * @return {!webdriver.promise.ControlFlow} The currently active control flow.
  678. */
  679. function controlFlow(): ControlFlow;
  680. /**
  681. * Creates a new control flow. The provided callback will be invoked as the
  682. * first task within the new flow, with the flow as its sole argument. Returns
  683. * a promise that resolves to the callback result.
  684. * @param {function(!webdriver.promise.ControlFlow)} callback The entry point
  685. * to the newly created flow.
  686. * @return {!webdriver.promise.Promise} A promise that resolves to the callback
  687. * result.
  688. */
  689. function createFlow<R>(callback: (flow: ControlFlow) => R): Promise<R>;
  690. /**
  691. * Determines whether a {@code value} should be treated as a promise.
  692. * Any object whose "then" property is a function will be considered a promise.
  693. *
  694. * @param {*} value The value to test.
  695. * @return {boolean} Whether the value is a promise.
  696. */
  697. function isPromise(value: any): boolean;
  698. /**
  699. * Tests is a function is a generator.
  700. * @param {!Function} fn The function to test.
  701. * @return {boolean} Whether the function is a generator.
  702. */
  703. function isGenerator(fn: Function): boolean;
  704. /**
  705. * Creates a promise that will be resolved at a set time in the future.
  706. * @param {number} ms The amount of time, in milliseconds, to wait before
  707. * resolving the promise.
  708. * @return {!webdriver.promise.Promise} The promise.
  709. */
  710. function delayed(ms: number): Promise<void>;
  711. /**
  712. * Calls a function for each element in an array, and if the function returns
  713. * true adds the element to a new array.
  714. *
  715. * <p>If the return value of the filter function is a promise, this function
  716. * will wait for it to be fulfilled before determining whether to insert the
  717. * element into the new array.
  718. *
  719. * <p>If the filter function throws or returns a rejected promise, the promise
  720. * returned by this function will be rejected with the same reason. Only the
  721. * first failure will be reported; all subsequent errors will be silently
  722. * ignored.
  723. *
  724. * @param {!(Array.<TYPE>|webdriver.promise.Promise.<!Array.<TYPE>>)} arr The
  725. * array to iterator over, or a promise that will resolve to said array.
  726. * @param {function(this: SELF, TYPE, number, !Array.<TYPE>): (
  727. * boolean|webdriver.promise.Promise.<boolean>)} fn The function
  728. * to call for each element in the array.
  729. * @param {SELF=} opt_self The object to be used as the value of 'this' within
  730. * {@code fn}.
  731. * @template TYPE, SELF
  732. */
  733. function filter<T>(arr: T[], fn: (element: T, index: number, array: T[]) => any, opt_self?: any): Promise<T[]>;
  734. function filter<T>(arr: Promise<T[]>, fn: (element: T, index: number, array: T[]) => any, opt_self?: any): Promise<T[]>
  735. /**
  736. * Creates a new deferred object.
  737. * @return {!webdriver.promise.Deferred} The new deferred object.
  738. */
  739. function defer<T>(): Deferred<T>;
  740. /**
  741. * Creates a promise that has been resolved with the given value.
  742. * @param {*=} opt_value The resolved value.
  743. * @return {!webdriver.promise.Promise} The resolved promise.
  744. */
  745. function fulfilled<T>(opt_value?: T): Promise<T>;
  746. /**
  747. * Calls a function for each element in an array and inserts the result into a
  748. * new array, which is used as the fulfillment value of the promise returned
  749. * by this function.
  750. *
  751. * <p>If the return value of the mapping function is a promise, this function
  752. * will wait for it to be fulfilled before inserting it into the new array.
  753. *
  754. * <p>If the mapping function throws or returns a rejected promise, the
  755. * promise returned by this function will be rejected with the same reason.
  756. * Only the first failure will be reported; all subsequent errors will be
  757. * silently ignored.
  758. *
  759. * @param {!(Array.<TYPE>|webdriver.promise.Promise.<!Array.<TYPE>>)} arr The
  760. * array to iterator over, or a promise that will resolve to said array.
  761. * @param {function(this: SELF, TYPE, number, !Array.<TYPE>): ?} fn The
  762. * function to call for each element in the array. This function should
  763. * expect three arguments (the element, the index, and the array itself.
  764. * @param {SELF=} opt_self The object to be used as the value of 'this' within
  765. * {@code fn}.
  766. * @template TYPE, SELF
  767. */
  768. function map<T>(arr: T[], fn: (element: T, index: number, array: T[]) => any, opt_self?: any): Promise<T[]>
  769. function map<T>(arr: Promise<T[]>, fn: (element: T, index: number, array: T[]) => any, opt_self?: any): Promise<T[]>
  770. /**
  771. * Creates a promise that has been rejected with the given reason.
  772. * @param {*=} opt_reason The rejection reason; may be any value, but is
  773. * usually an Error or a string.
  774. * @return {!webdriver.promise.Promise} The rejected promise.
  775. */
  776. function rejected(opt_reason?: any): Promise<void>;
  777. /**
  778. * Wraps a function that is assumed to be a node-style callback as its final
  779. * argument. This callback takes two arguments: an error value (which will be
  780. * null if the call succeeded), and the success value as the second argument.
  781. * If the call fails, the returned promise will be rejected, otherwise it will
  782. * be resolved with the result.
  783. * @param {!Function} fn The function to wrap.
  784. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  785. * result of the provided function's callback.
  786. */
  787. function checkedNodeCall<T>(fn: Function, ...var_args: any[]): Promise<T>;
  788. /**
  789. * Consumes a {@code GeneratorFunction}. Each time the generator yields a
  790. * promise, this function will wait for it to be fulfilled before feeding the
  791. * fulfilled value back into {@code next}. Likewise, if a yielded promise is
  792. * rejected, the rejection error will be passed to {@code throw}.
  793. *
  794. * <p>Example 1: the Fibonacci Sequence.
  795. * <pre><code>
  796. * webdriver.promise.consume(function* fibonacci() {
  797. * var n1 = 1, n2 = 1;
  798. * for (var i = 0; i < 4; ++i) {
  799. * var tmp = yield n1 + n2;
  800. * n1 = n2;
  801. * n2 = tmp;
  802. * }
  803. * return n1 + n2;
  804. * }).then(function(result) {
  805. * console.log(result); // 13
  806. * });
  807. * </code></pre>
  808. *
  809. * <p>Example 2: a generator that throws.
  810. * <pre><code>
  811. * webdriver.promise.consume(function* () {
  812. * yield webdriver.promise.delayed(250).then(function() {
  813. * throw Error('boom');
  814. * });
  815. * }).thenCatch(function(e) {
  816. * console.log(e.toString()); // Error: boom
  817. * });
  818. * </code></pre>
  819. *
  820. * @param {!Function} generatorFn The generator function to execute.
  821. * @param {Object=} opt_self The object to use as "this" when invoking the
  822. * initial generator.
  823. * @param {...*} var_args Any arguments to pass to the initial generator.
  824. * @return {!webdriver.promise.Promise.<?>} A promise that will resolve to the
  825. * generator's final result.
  826. * @throws {TypeError} If the given function is not a generator.
  827. */
  828. function consume<T>(generatorFn: Function, opt_self?: any, ...var_args: any[]): Promise<T>;
  829. /**
  830. * Registers an observer on a promised {@code value}, returning a new promise
  831. * that will be resolved when the value is. If {@code value} is not a promise,
  832. * then the return promise will be immediately resolved.
  833. * @param {*} value The value to observe.
  834. * @param {Function=} opt_callback The function to call when the value is
  835. * resolved successfully.
  836. * @param {Function=} opt_errback The function to call when the value is
  837. * rejected.
  838. * @return {!webdriver.promise.Promise} A new promise.
  839. */
  840. function when<T,R>(value: T, opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): Promise<R>;
  841. function when<T,R>(value: Promise<T>, opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): Promise<R>;
  842. /**
  843. * Returns a promise that will be resolved with the input value in a
  844. * fully-resolved state. If the value is an array, each element will be fully
  845. * resolved. Likewise, if the value is an object, all keys will be fully
  846. * resolved. In both cases, all nested arrays and objects will also be
  847. * fully resolved. All fields are resolved in place; the returned promise will
  848. * resolve on {@code value} and not a copy.
  849. *
  850. * Warning: This function makes no checks against objects that contain
  851. * cyclical references:
  852. *
  853. * var value = {};
  854. * value['self'] = value;
  855. * webdriver.promise.fullyResolved(value); // Stack overflow.
  856. *
  857. * @param {*} value The value to fully resolve.
  858. * @return {!webdriver.promise.Promise} A promise for a fully resolved version
  859. * of the input value.
  860. */
  861. function fullyResolved<T>(value: any): Promise<T>;
  862. /**
  863. * Changes the default flow to use when no others are active.
  864. * @param {!webdriver.promise.ControlFlow} flow The new default flow.
  865. * @throws {Error} If the default flow is not currently active.
  866. */
  867. function setDefaultFlow(flow: ControlFlow): void;
  868. //endregion
  869. /**
  870. * Error used when the computation of a promise is cancelled.
  871. *
  872. * @extends {goog.debug.Error}
  873. * @final
  874. */
  875. class CancellationError {
  876. /**
  877. * @param {string=} opt_msg The cancellation message.
  878. * @constructor
  879. */
  880. constructor(opt_msg?: string);
  881. name: string;
  882. message: string;
  883. }
  884. interface IThenable<T> {
  885. /**
  886. * Cancels the computation of this promise's value, rejecting the promise in the
  887. * process. This method is a no-op if the promise has alreayd been resolved.
  888. *
  889. * @param {string=} opt_reason The reason this promise is being cancelled.
  890. */
  891. cancel(opt_reason?: string): void;
  892. /** @return {boolean} Whether this promise's value is still being computed. */
  893. isPending(): boolean;
  894. /**
  895. * Registers listeners for when this instance is resolved.
  896. *
  897. * @param opt_callback The
  898. * function to call if this promise is successfully resolved. The function
  899. * should expect a single argument: the promise's resolved value.
  900. * @param opt_errback The
  901. * function to call if this promise is rejected. The function should expect
  902. * a single argument: the rejection reason.
  903. * @return A new promise which will be
  904. * resolved with the result of the invoked callback.
  905. */
  906. then<R>(opt_callback?: (value: T) => Promise<R>, opt_errback?: (error: any) => any): Promise<R>;
  907. /**
  908. * Registers listeners for when this instance is resolved.
  909. *
  910. * @param opt_callback The
  911. * function to call if this promise is successfully resolved. The function
  912. * should expect a single argument: the promise's resolved value.
  913. * @param opt_errback The
  914. * function to call if this promise is rejected. The function should expect
  915. * a single argument: the rejection reason.
  916. * @return A new promise which will be
  917. * resolved with the result of the invoked callback.
  918. */
  919. then<R>(opt_callback?: (value: T) => R, opt_errback?: (error: any) => any): Promise<R>;
  920. /**
  921. * Registers a listener for when this promise is rejected. This is synonymous
  922. * with the {@code catch} clause in a synchronous API:
  923. * <pre><code>
  924. * // Synchronous API:
  925. * try {
  926. * doSynchronousWork();
  927. * } catch (ex) {
  928. * console.error(ex);
  929. * }
  930. *
  931. * // Asynchronous promise API:
  932. * doAsynchronousWork().thenCatch(function(ex) {
  933. * console.error(ex);
  934. * });
  935. * </code></pre>
  936. *
  937. * @param {function(*): (R|webdriver.promise.Promise.<R>)} errback The function
  938. * to call if this promise is rejected. The function should expect a single
  939. * argument: the rejection reason.
  940. * @return {!webdriver.promise.Promise.<R>} A new promise which will be
  941. * resolved with the result of the invoked callback.
  942. * @template R
  943. */
  944. thenCatch<R>(errback: (error: any) => any): Promise<R>;
  945. /**
  946. * Registers a listener to invoke when this promise is resolved, regardless
  947. * of whether the promise's value was successfully computed. This function
  948. * is synonymous with the {@code finally} clause in a synchronous API:
  949. * <pre><code>
  950. * // Synchronous API:
  951. * try {
  952. * doSynchronousWork();
  953. * } finally {
  954. * cleanUp();
  955. * }
  956. *
  957. * // Asynchronous promise API:
  958. * doAsynchronousWork().thenFinally(cleanUp);
  959. * </code></pre>
  960. *
  961. * <b>Note:</b> similar to the {@code finally} clause, if the registered
  962. * callback returns a rejected promise or throws an error, it will silently
  963. * replace the rejection error (if any) from this promise:
  964. * <pre><code>
  965. * try {
  966. * throw Error('one');
  967. * } finally {
  968. * throw Error('two'); // Hides Error: one
  969. * }
  970. *
  971. * webdriver.promise.rejected(Error('one'))
  972. * .thenFinally(function() {
  973. * throw Error('two'); // Hides Error: one
  974. * });
  975. * </code></pre>
  976. *
  977. *
  978. * @param {function(): (R|webdriver.promise.Promise.<R>)} callback The function
  979. * to call when this promise is resolved.
  980. * @return {!webdriver.promise.Promise.<R>} A promise that will be fulfilled
  981. * with the callback result.
  982. * @template R
  983. */
  984. thenFinally<R>(callback: () => any): Promise<R>;
  985. }
  986. /**
  987. * Thenable is a promise-like object with a {@code then} method which may be
  988. * used to schedule callbacks on a promised value.
  989. *
  990. * @interface
  991. * @template T
  992. */
  993. class Thenable<T> implements IThenable<T> {
  994. /**
  995. * Cancels the computation of this promise's value, rejecting the promise in the
  996. * process. This method is a no-op if the promise has alreayd been resolved.
  997. *
  998. * @param {string=} opt_reason The reason this promise is being cancelled.
  999. */
  1000. cancel(opt_reason?: string): void;
  1001. /** @return {boolean} Whether this promise's value is still being computed. */
  1002. isPending(): boolean;
  1003. /**
  1004. * Registers listeners for when this instance is resolved.
  1005. *
  1006. * @param opt_callback The
  1007. * function to call if this promise is successfully resolved. The function
  1008. * should expect a single argument: the promise's resolved value.
  1009. * @param opt_errback The
  1010. * function to call if this promise is rejected. The function should expect
  1011. * a single argument: the rejection reason.
  1012. * @return A new promise which will be
  1013. * resolved with the result of the invoked callback.
  1014. */
  1015. then<R>(opt_callback?: (value: T) => Promise<R>, opt_errback?: (error: any) => any): Promise<R>;
  1016. /**
  1017. * Registers listeners for when this instance is resolved.
  1018. *
  1019. * @param opt_callback The
  1020. * function to call if this promise is successfully resolved. The function
  1021. * should expect a single argument: the promise's resolved value.
  1022. * @param opt_errback The
  1023. * function to call if this promise is rejected. The function should expect
  1024. * a single argument: the rejection reason.
  1025. * @return A new promise which will be
  1026. * resolved with the result of the invoked callback.
  1027. */
  1028. then<R>(opt_callback?: (value: T) => R, opt_errback?: (error: any) => any): Promise<R>;
  1029. /**
  1030. * Registers a listener for when this promise is rejected. This is synonymous
  1031. * with the {@code catch} clause in a synchronous API:
  1032. * <pre><code>
  1033. * // Synchronous API:
  1034. * try {
  1035. * doSynchronousWork();
  1036. * } catch (ex) {
  1037. * console.error(ex);
  1038. * }
  1039. *
  1040. * // Asynchronous promise API:
  1041. * doAsynchronousWork().thenCatch(function(ex) {
  1042. * console.error(ex);
  1043. * });
  1044. * </code></pre>
  1045. *
  1046. * @param {function(*): (R|webdriver.promise.Promise.<R>)} errback The function
  1047. * to call if this promise is rejected. The function should expect a single
  1048. * argument: the rejection reason.
  1049. * @return {!webdriver.promise.Promise.<R>} A new promise which will be
  1050. * resolved with the result of the invoked callback.
  1051. * @template R
  1052. */
  1053. thenCatch<R>(errback: (error: any) => any): Promise<R>;
  1054. /**
  1055. * Registers a listener to invoke when this promise is resolved, regardless
  1056. * of whether the promise's value was successfully computed. This function
  1057. * is synonymous with the {@code finally} clause in a synchronous API:
  1058. * <pre><code>
  1059. * // Synchronous API:
  1060. * try {
  1061. * doSynchronousWork();
  1062. * } finally {
  1063. * cleanUp();
  1064. * }
  1065. *
  1066. * // Asynchronous promise API:
  1067. * doAsynchronousWork().thenFinally(cleanUp);
  1068. * </code></pre>
  1069. *
  1070. * <b>Note:</b> similar to the {@code finally} clause, if the registered
  1071. * callback returns a rejected promise or throws an error, it will silently
  1072. * replace the rejection error (if any) from this promise:
  1073. * <pre><code>
  1074. * try {
  1075. * throw Error('one');
  1076. * } finally {
  1077. * throw Error('two'); // Hides Error: one
  1078. * }
  1079. *
  1080. * webdriver.promise.rejected(Error('one'))
  1081. * .thenFinally(function() {
  1082. * throw Error('two'); // Hides Error: one
  1083. * });
  1084. * </code></pre>
  1085. *
  1086. *
  1087. * @param {function(): (R|webdriver.promise.Promise.<R>)} callback The function
  1088. * to call when this promise is resolved.
  1089. * @return {!webdriver.promise.Promise.<R>} A promise that will be fulfilled
  1090. * with the callback result.
  1091. * @template R
  1092. */
  1093. thenFinally<R>(callback: () => any): Promise<R>;
  1094. /**
  1095. * Adds a property to a class prototype to allow runtime checks of whether
  1096. * instances of that class implement the Thenable interface. This function will
  1097. * also ensure the prototype's {@code then} function is exported from compiled
  1098. * code.
  1099. * @param {function(new: webdriver.promise.Thenable, ...[?])} ctor The
  1100. * constructor whose prototype to modify.
  1101. */
  1102. static addImplementation(ctor: Function): void;
  1103. /**
  1104. * Checks if an object has been tagged for implementing the Thenable interface
  1105. * as defined by {@link webdriver.promise.Thenable.addImplementation}.
  1106. * @param {*} object The object to test.
  1107. * @return {boolean} Whether the object is an implementation of the Thenable
  1108. * interface.
  1109. */
  1110. static isImplementation(object: any): boolean;
  1111. }
  1112. /**
  1113. * Represents the eventual value of a completed operation. Each promise may be
  1114. * in one of three states: pending, resolved, or rejected. Each promise starts
  1115. * in the pending state and may make a single transition to either a
  1116. * fulfilled or failed state.
  1117. *
  1118. * <p/>This class is based on the Promise/A proposal from CommonJS. Additional
  1119. * functions are provided for API compatibility with Dojo Deferred objects.
  1120. *
  1121. * @see http://wiki.commonjs.org/wiki/Promises/A
  1122. */
  1123. class Promise<T> implements IThenable<T> {
  1124. //region Constructors
  1125. /**
  1126. * @constructor
  1127. * @see http://wiki.commonjs.org/wiki/Promises/A
  1128. */
  1129. constructor();
  1130. //endregion
  1131. //region Methods
  1132. /**
  1133. * Cancels the computation of this promise's value, rejecting the promise in the
  1134. * process.
  1135. * @param {*} reason The reason this promise is being cancelled. If not an
  1136. * {@code Error}, one will be created using the value's string
  1137. * representation.
  1138. */
  1139. cancel(reason: any): void;
  1140. /** @return {boolean} Whether this promise's value is still being computed. */
  1141. isPending(): boolean;
  1142. /**
  1143. * Registers listeners for when this instance is resolved. This function most
  1144. * overridden by subtypes.
  1145. *
  1146. * @param opt_callback The function to call if this promise is
  1147. * successfully resolved. The function should expect a single argument: the
  1148. * promise's resolved value.
  1149. * @param opt_errback The function to call if this promise is
  1150. * rejected. The function should expect a single argument: the rejection
  1151. * reason.
  1152. * @return A new promise which will be resolved
  1153. * with the result of the invoked callback.
  1154. */
  1155. then<R>(opt_callback?: (value: T) => Promise<R>, opt_errback?: (error: any) => any): Promise<R>;
  1156. /**
  1157. * Registers listeners for when this instance is resolved. This function most
  1158. * overridden by subtypes.
  1159. *
  1160. * @param opt_callback The function to call if this promise is
  1161. * successfully resolved. The function should expect a single argument: the
  1162. * promise's resolved value.
  1163. * @param opt_errback The function to call if this promise is
  1164. * rejected. The function should expect a single argument: the rejection
  1165. * reason.
  1166. * @return A new promise which will be resolved
  1167. * with the result of the invoked callback.
  1168. */
  1169. then<R>(opt_callback?: (value: T) => R, opt_errback?: (error: any) => any): Promise<R>;
  1170. /**
  1171. * Registers a listener for when this promise is rejected. This is synonymous
  1172. * with the {@code catch} clause in a synchronous API:
  1173. * <pre><code>
  1174. * // Synchronous API:
  1175. * try {
  1176. * doSynchronousWork();
  1177. * } catch (ex) {
  1178. * console.error(ex);
  1179. * }
  1180. *
  1181. * // Asynchronous promise API:
  1182. * doAsynchronousWork().thenCatch(function(ex) {
  1183. * console.error(ex);
  1184. * });
  1185. * </code></pre>
  1186. *
  1187. * @param {function(*): (R|webdriver.promise.Promise.<R>)} errback The function
  1188. * to call if this promise is rejected. The function should expect a single
  1189. * argument: the rejection reason.
  1190. * @return {!webdriver.promise.Promise.<R>} A new promise which will be
  1191. * resolved with the result of the invoked callback.
  1192. * @template R
  1193. */
  1194. thenCatch<R>(errback: (error: any) => any): Promise<R>;
  1195. /**
  1196. * Registers a listener to invoke when this promise is resolved, regardless
  1197. * of whether the promise's value was successfully computed. This function
  1198. * is synonymous with the {@code finally} clause in a synchronous API:
  1199. * <pre><code>
  1200. * // Synchronous API:
  1201. * try {
  1202. * doSynchronousWork();
  1203. * } finally {
  1204. * cleanUp();
  1205. * }
  1206. *
  1207. * // Asynchronous promise API:
  1208. * doAsynchronousWork().thenFinally(cleanUp);
  1209. * </code></pre>
  1210. *
  1211. * <b>Note:</b> similar to the {@code finally} clause, if the registered
  1212. * callback returns a rejected promise or throws an error, it will silently
  1213. * replace the rejection error (if any) from this promise:
  1214. * <pre><code>
  1215. * try {
  1216. * throw Error('one');
  1217. * } finally {
  1218. * throw Error('two'); // Hides Error: one
  1219. * }
  1220. *
  1221. * webdriver.promise.rejected(Error('one'))
  1222. * .thenFinally(function() {
  1223. * throw Error('two'); // Hides Error: one
  1224. * });
  1225. * </code></pre>
  1226. *
  1227. *
  1228. * @param {function(): (R|webdriver.promise.Promise.<R>)} callback The function
  1229. * to call when this promise is resolved.
  1230. * @return {!webdriver.promise.Promise.<R>} A promise that will be fulfilled
  1231. * with the callback result.
  1232. * @template R
  1233. */
  1234. thenFinally<R>(callback: () => any): Promise<R>;
  1235. //endregion
  1236. }
  1237. /**
  1238. * Represents a value that will be resolved at some point in the future. This
  1239. * class represents the protected "producer" half of a Promise - each Deferred
  1240. * has a {@code promise} property that may be returned to consumers for
  1241. * registering callbacks, reserving the ability to resolve the deferred to the
  1242. * producer.
  1243. *
  1244. * <p>If this Deferred is rejected and there are no listeners registered before
  1245. * the next turn of the event loop, the rejection will be passed to the
  1246. * {@link webdriver.promise.ControlFlow} as an unhandled failure.
  1247. *
  1248. * <p>If this Deferred is cancelled, the cancellation reason will be forward to
  1249. * the Deferred's canceller function (if provided). The canceller may return a
  1250. * truth-y value to override the reason provided for rejection.
  1251. *
  1252. * @extends {webdriver.promise.Promise}
  1253. */
  1254. class Deferred<T> extends Promise<T> {
  1255. //region Constructors
  1256. /**
  1257. *
  1258. * @param {webdriver.promise.ControlFlow=} opt_flow The control flow
  1259. * this instance was created under. This should only be provided during
  1260. * unit tests.
  1261. * @constructor
  1262. */
  1263. constructor(opt_flow?: ControlFlow);
  1264. //endregion
  1265. static State_: {
  1266. BLOCKED: number;
  1267. PENDING: number;
  1268. REJECTED: number;
  1269. RESOLVED: number;
  1270. }
  1271. //region Properties
  1272. /**
  1273. * The consumer promise for this instance. Provides protected access to the
  1274. * callback registering functions.
  1275. * @type {!webdriver.promise.Promise}
  1276. */
  1277. promise: Promise<T>;
  1278. //endregion
  1279. //region Methods
  1280. /**
  1281. * Rejects this promise. If the error is itself a promise, this instance will
  1282. * be chained to it and be rejected with the error's resolved value.
  1283. * @param {*=} opt_error The rejection reason, typically either a
  1284. * {@code Error} or a {@code string}.
  1285. */
  1286. reject(opt_error?: any): void;
  1287. errback(opt_error?: any): void;
  1288. /**
  1289. * Resolves this promise with the given value. If the value is itself a
  1290. * promise and not a reference to this deferred, this instance will wait for
  1291. * it before resolving.
  1292. * @param {*=} opt_value The resolved value.
  1293. */
  1294. fulfill(opt_value?: T): void;
  1295. /**
  1296. * Removes all of the listeners previously registered on this deferred.
  1297. * @throws {Error} If this deferred has already been resolved.
  1298. */
  1299. removeAll(): void;
  1300. //endregion
  1301. }
  1302. interface IControlFlowTimer {
  1303. clearInterval: (ms: number) => void;
  1304. clearTimeout: (ms: number) => void;
  1305. setInterval: (fn: Function, ms: number) => number;
  1306. setTimeout: (fn: Function, ms: number) => number;
  1307. }
  1308. /**
  1309. * Handles the execution of scheduled tasks, each of which may be an
  1310. * asynchronous operation. The control flow will ensure tasks are executed in
  1311. * the ordered scheduled, starting each task only once those before it have
  1312. * completed.
  1313. *
  1314. * <p>Each task scheduled within this flow may return a
  1315. * {@link webdriver.promise.Promise} to indicate it is an asynchronous
  1316. * operation. The ControlFlow will wait for such promises to be resolved before
  1317. * marking the task as completed.
  1318. *
  1319. * <p>Tasks and each callback registered on a {@link webdriver.promise.Deferred}
  1320. * will be run in their own ControlFlow frame. Any tasks scheduled within a
  1321. * frame will have priority over previously scheduled tasks. Furthermore, if
  1322. * any of the tasks in the frame fails, the remainder of the tasks in that frame
  1323. * will be discarded and the failure will be propagated to the user through the
  1324. * callback/task's promised result.
  1325. *
  1326. * <p>Each time a ControlFlow empties its task queue, it will fire an
  1327. * {@link webdriver.promise.ControlFlow.EventType.IDLE} event. Conversely,
  1328. * whenever the flow terminates due to an unhandled error, it will remove all
  1329. * remaining tasks in its queue and fire an
  1330. * {@link webdriver.promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION} event. If
  1331. * there are no listeners registered with the flow, the error will be
  1332. * rethrown to the global error handler.
  1333. *
  1334. * @extends {webdriver.EventEmitter}
  1335. */
  1336. class ControlFlow extends EventEmitter {
  1337. //region Constructors
  1338. /**
  1339. * @param {webdriver.promise.ControlFlow.Timer=} opt_timer The timer object
  1340. * to use. Should only be set for testing.
  1341. * @constructor
  1342. */
  1343. constructor(opt_timer?: IControlFlowTimer);
  1344. //endregion
  1345. //region Properties
  1346. /**
  1347. * The timer used by this instance.
  1348. * @type {webdriver.promise.ControlFlow.Timer}
  1349. */
  1350. timer: IControlFlowTimer;
  1351. //endregion
  1352. //region Static Properties
  1353. /**
  1354. * The default timer object, which uses the global timer functions.
  1355. * @type {webdriver.promise.ControlFlow.Timer}
  1356. */
  1357. static defaultTimer: IControlFlowTimer;
  1358. /**
  1359. * Events that may be emitted by an {@link webdriver.promise.ControlFlow}.
  1360. * @enum {string}
  1361. */
  1362. static EventType: {
  1363. /** Emitted when all tasks have been successfully executed. */
  1364. IDLE: string;
  1365. /** Emitted when a ControlFlow has been reset. */
  1366. RESET: string;
  1367. /** Emitted whenever a new task has been scheduled. */
  1368. SCHEDULE_TASK: string;
  1369. /**
  1370. * Emitted whenever a control flow aborts due to an unhandled promise
  1371. * rejection. This event will be emitted along with the offending rejection
  1372. * reason. Upon emitting this event, the control flow will empty its task
  1373. * queue and revert to its initial state.
  1374. */
  1375. UNCAUGHT_EXCEPTION: string;
  1376. };
  1377. /**
  1378. * How often, in milliseconds, the event loop should run.
  1379. * @type {number}
  1380. * @const
  1381. */
  1382. static EVENT_LOOP_FREQUENCY: number;
  1383. //endregion
  1384. //region Methods
  1385. /**
  1386. * Resets this instance, clearing its queue and removing all event listeners.
  1387. */
  1388. reset(): void;
  1389. /**
  1390. * Returns a summary of the recent task activity for this instance. This
  1391. * includes the most recently completed task, as well as any parent tasks. In
  1392. * the returned summary, the task at index N is considered a sub-task of the
  1393. * task at index N+1.
  1394. * @return {!Array.<string>} A summary of this instance's recent task
  1395. * activity.
  1396. */
  1397. getHistory(): string[];
  1398. /** Clears this instance's task history. */
  1399. clearHistory(): void;
  1400. /**
  1401. * Appends a summary of this instance's recent task history to the given
  1402. * error's stack trace. This function will also ensure the error's stack trace
  1403. * is in canonical form.
  1404. * @param {!(Error|goog.testing.JsUnitException)} e The error to annotate.
  1405. * @return {!(Error|goog.testing.JsUnitException)} The annotated error.
  1406. */
  1407. annotateError(e: any): any;
  1408. /**
  1409. * @return {string} The scheduled tasks still pending with this instance.
  1410. */
  1411. getSchedule(): string;
  1412. /**
  1413. * Schedules a task for execution. If there is nothing currently in the
  1414. * queue, the task will be executed in the next turn of the event loop.
  1415. *
  1416. * @param {!Function} fn The function to call to start the task. If the
  1417. * function returns a {@link webdriver.promise.Promise}, this instance
  1418. * will wait for it to be resolved before starting the next task.
  1419. * @param {string=} opt_description A description of the task.
  1420. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  1421. * the result of the action.
  1422. */
  1423. execute<T>(fn: Function, opt_description?: string): Promise<T>;
  1424. /**
  1425. * Inserts a {@code setTimeout} into the command queue. This is equivalent to
  1426. * a thread sleep in a synchronous programming language.
  1427. *
  1428. * @param {number} ms The timeout delay, in milliseconds.
  1429. * @param {string=} opt_description A description to accompany the timeout.
  1430. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  1431. * the result of the action.
  1432. */
  1433. timeout(ms: number, opt_description?: string): Promise<void>;
  1434. /**
  1435. * Schedules a task that shall wait for a condition to hold. Each condition
  1436. * function may return any value, but it will always be evaluated as a boolean.
  1437. *
  1438. * <p>Condition functions may schedule sub-tasks with this instance, however,
  1439. * their execution time will be factored into whether a wait has timed out.
  1440. *
  1441. * <p>In the event a condition returns a Promise, the polling loop will wait for
  1442. * it to be resolved before evaluating whether the condition has been satisfied.
  1443. * The resolution time for a promise is factored into whether a wait has timed
  1444. * out.
  1445. *
  1446. * <p>If the condition function throws, or returns a rejected promise, the
  1447. * wait task will fail.
  1448. *
  1449. * @param {!Function} condition The condition function to poll.
  1450. * @param {number} timeout How long to wait, in milliseconds, for the condition
  1451. * to hold before timing out.
  1452. * @param {string=} opt_message An optional error message to include if the
  1453. * wait times out; defaults to the empty string.
  1454. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  1455. * condition has been satisified. The promise shall be rejected if the wait
  1456. * times out waiting for the condition.
  1457. */
  1458. wait(condition: Function, timeout: number, opt_message?: string): Promise<void>;
  1459. /**
  1460. * Schedules a task that will wait for another promise to resolve. The resolved
  1461. * promise's value will be returned as the task result.
  1462. * @param {!webdriver.promise.Promise} promise The promise to wait on.
  1463. * @return {!webdriver.promise.Promise} A promise that will resolve when the
  1464. * task has completed.
  1465. */
  1466. await<T>(promise: Promise<T>): Promise<T>;
  1467. //endregion
  1468. }
  1469. }
  1470. module stacktrace {
  1471. /**
  1472. * Class representing one stack frame.
  1473. */
  1474. class Frame {
  1475. /**
  1476. * @param {(string|undefined)} context Context object, empty in case of global
  1477. * functions or if the browser doesn't provide this information.
  1478. * @param {(string|undefined)} name Function name, empty in case of anonymous
  1479. * functions.
  1480. * @param {(string|undefined)} alias Alias of the function if available. For
  1481. * example the function name will be 'c' and the alias will be 'b' if the
  1482. * function is defined as <code>a.b = function c() {};</code>.
  1483. * @param {(string|undefined)} path File path or URL including line number and
  1484. * optionally column number separated by colons.
  1485. * @constructor
  1486. */
  1487. constructor(context?: string, name?: string, alias?: string, path?: string);
  1488. /**
  1489. * @return {string} The function name or empty string if the function is
  1490. * anonymous and the object field which it's assigned to is unknown.
  1491. */
  1492. getName(): string;
  1493. /**
  1494. * @return {string} The url or empty string if it is unknown.
  1495. */
  1496. getUrl(): string;
  1497. /**
  1498. * @return {number} The line number if known or -1 if it is unknown.
  1499. */
  1500. getLine(): number;
  1501. /**
  1502. * @return {number} The column number if known and -1 if it is unknown.
  1503. */
  1504. getColumn(): number;
  1505. /**
  1506. * @return {boolean} Whether the stack frame contains an anonymous function.
  1507. */
  1508. isAnonymous(): boolean;
  1509. /**
  1510. * Converts this frame to its string representation using V8's stack trace
  1511. * format: http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  1512. * @return {string} The string representation of this frame.
  1513. * @override
  1514. */
  1515. toString(): string;
  1516. }
  1517. /**
  1518. * Stores a snapshot of the stack trace at the time this instance was created.
  1519. * The stack trace will always be adjusted to exclude this function call.
  1520. */
  1521. class Snapshot {
  1522. /**
  1523. * @param {number=} opt_slice The number of frames to remove from the top of
  1524. * the generated stack trace.
  1525. * @constructor
  1526. */
  1527. constructor(opt_slice?: number);
  1528. /**
  1529. * @return {!Array.<!webdriver.stacktrace.Frame>} The parsed stack trace.
  1530. */
  1531. getStacktrace(): Frame[];
  1532. }
  1533. /**
  1534. * Formats an error's stack trace.
  1535. * @param {!(Error|goog.testing.JsUnitException)} error The error to format.
  1536. * @return {!(Error|goog.testing.JsUnitException)} The formatted error.
  1537. */
  1538. function format(error: any): any;
  1539. /**
  1540. * Gets the native stack trace if available otherwise follows the call chain.
  1541. * The generated trace will exclude all frames up to and including the call to
  1542. * this function.
  1543. * @return {!Array.<!webdriver.stacktrace.Frame>} The frames of the stack trace.
  1544. */
  1545. function get(): Frame[];
  1546. /**
  1547. * Whether the current browser supports stack traces.
  1548. *
  1549. * @type {boolean}
  1550. * @const
  1551. */
  1552. var BROWSER_SUPPORTED: boolean;
  1553. }
  1554. module until {
  1555. /**
  1556. * Defines a condition to
  1557. */
  1558. class Condition<T> {
  1559. /**
  1560. * @param {string} message A descriptive error message. Should complete the
  1561. * sentence "Waiting [...]"
  1562. * @param {function(!webdriver.WebDriver): OUT} fn The condition function to
  1563. * evaluate on each iteration of the wait loop.
  1564. * @constructor
  1565. */
  1566. constructor(message: string, fn: (webdriver: WebDriver) => any);
  1567. /** @return {string} A description of this condition. */
  1568. description(): string;
  1569. /** @type {function(!webdriver.WebDriver): OUT} */
  1570. fn(webdriver: WebDriver): any;
  1571. }
  1572. /**
  1573. * Creates a condition that will wait until the input driver is able to switch
  1574. * to the designated frame. The target frame may be specified as:
  1575. * <ol>
  1576. * <li>A numeric index into {@code window.frames} for the currently selected
  1577. * frame.
  1578. * <li>A {@link webdriver.WebElement}, which must reference a FRAME or IFRAME
  1579. * element on the current page.
  1580. * <li>A locator which may be used to first locate a FRAME or IFRAME on the
  1581. * current page before attempting to switch to it.
  1582. * </ol>
  1583. *
  1584. * <p>Upon successful resolution of this condition, the driver will be left
  1585. * focused on the new frame.
  1586. *
  1587. * @param {!(number|webdriver.WebElement|
  1588. * webdriver.Locator|webdriver.By.Hash|
  1589. * function(!webdriver.WebDriver): !webdriver.WebElement)} frame
  1590. * The frame identifier.
  1591. * @return {!until.Condition.<boolean>} A new condition.
  1592. */
  1593. function ableToSwitchToFrame(frame: number): Condition<boolean>;
  1594. function ableToSwitchToFrame(frame: IWebElement): Condition<boolean>;
  1595. function ableToSwitchToFrame(frame: Locator): Condition<boolean>;
  1596. function ableToSwitchToFrame(frame: (webdriver: WebDriver) => IWebElement): Condition<boolean>;
  1597. function ableToSwitchToFrame(frame: any): Condition<boolean>;
  1598. /**
  1599. * Creates a condition that waits for an alert to be opened. Upon success, the
  1600. * returned promise will be fulfilled with the handle for the opened alert.
  1601. *
  1602. * @return {!until.Condition.<!webdriver.Alert>} The new condition.
  1603. */
  1604. function alertIsPresent(): Condition<Alert>;
  1605. /**
  1606. * Creates a condition that will wait for the given element to be disabled.
  1607. *
  1608. * @param {!webdriver.WebElement} element The element to test.
  1609. * @return {!until.Condition.<boolean>} The new condition.
  1610. * @see webdriver.WebDriver#isEnabled
  1611. */
  1612. function elementIsDisabled(element: IWebElement): Condition<boolean>;
  1613. /**
  1614. * Creates a condition that will wait for the given element to be enabled.
  1615. *
  1616. * @param {!webdriver.WebElement} element The element to test.
  1617. * @return {!until.Condition.<boolean>} The new condition.
  1618. * @see webdriver.WebDriver#isEnabled
  1619. */
  1620. function elementIsEnabled(element: IWebElement): Condition<boolean>;
  1621. /**
  1622. * Creates a condition that will wait for the given element to be deselected.
  1623. *
  1624. * @param {!webdriver.WebElement} element The element to test.
  1625. * @return {!until.Condition.<boolean>} The new condition.
  1626. * @see webdriver.WebDriver#isSelected
  1627. */
  1628. function elementIsNotSelected(element: IWebElement): Condition<boolean>;
  1629. /**
  1630. * Creates a condition that will wait for the given element to be in the DOM,
  1631. * yet not visible to the user.
  1632. *
  1633. * @param {!webdriver.WebElement} element The element to test.
  1634. * @return {!until.Condition.<boolean>} The new condition.
  1635. * @see webdriver.WebDriver#isDisplayed
  1636. */
  1637. function elementIsNotVisible(element: IWebElement): Condition<boolean>;
  1638. /**
  1639. * Creates a condition that will wait for the given element to be selected.
  1640. * @param {!webdriver.WebElement} element The element to test.
  1641. * @return {!until.Condition.<boolean>} The new condition.
  1642. * @see webdriver.WebDriver#isSelected
  1643. */
  1644. function elementIsSelected(element: IWebElement): Condition<boolean>;
  1645. /**
  1646. * Creates a condition that will wait for the given element to become visible.
  1647. *
  1648. * @param {!webdriver.WebElement} element The element to test.
  1649. * @return {!until.Condition.<boolean>} The new condition.
  1650. * @see webdriver.WebDriver#isDisplayed
  1651. */
  1652. function elementIsVisible(element: IWebElement): Condition<boolean>;
  1653. /**
  1654. * Creates a condition that will loop until an element is
  1655. * {@link webdriver.WebDriver#findElement found} with the given locator.
  1656. *
  1657. * @param {!(webdriver.Locator|webdriver.By.Hash|Function)} locator The locator
  1658. * to use.
  1659. * @return {!until.Condition.<!webdriver.WebElement>} The new condition.
  1660. */
  1661. function elementLocated(locator: Locator): Condition<IWebElement>;
  1662. function elementLocated(locator: any): Condition<IWebElement>;
  1663. /**
  1664. * Creates a condition that will wait for the given element's
  1665. * {@link webdriver.WebDriver#getText visible text} to contain the given
  1666. * substring.
  1667. *
  1668. * @param {!webdriver.WebElement} element The element to test.
  1669. * @param {string} substr The substring to search for.
  1670. * @return {!until.Condition.<boolean>} The new condition.
  1671. * @see webdriver.WebDriver#getText
  1672. */
  1673. function elementTextContains(element: IWebElement, substr: string): Condition<boolean>;
  1674. /**
  1675. * Creates a condition that will wait for the given element's
  1676. * {@link webdriver.WebDriver#getText visible text} to match the given
  1677. * {@code text} exactly.
  1678. *
  1679. * @param {!webdriver.WebElement} element The element to test.
  1680. * @param {string} text The expected text.
  1681. * @return {!until.Condition.<boolean>} The new condition.
  1682. * @see webdriver.WebDriver#getText
  1683. */
  1684. function elementTextIs(element: IWebElement, text: string): Condition<boolean>;
  1685. /**
  1686. * Creates a condition that will wait for the given element's
  1687. * {@link webdriver.WebDriver#getText visible text} to match a regular
  1688. * expression.
  1689. *
  1690. * @param {!webdriver.WebElement} element The element to test.
  1691. * @param {!RegExp} regex The regular expression to test against.
  1692. * @return {!until.Condition.<boolean>} The new condition.
  1693. * @see webdriver.WebDriver#getText
  1694. */
  1695. function elementTextMatches(element: IWebElement, regex: RegExp): Condition<boolean>;
  1696. /**
  1697. * Creates a condition that will loop until at least one element is
  1698. * {@link webdriver.WebDriver#findElement found} with the given locator.
  1699. *
  1700. * @param {!(webdriver.Locator|webdriver.By.Hash|Function)} locator The locator
  1701. * to use.
  1702. * @return {!until.Condition.<!Array.<!webdriver.WebElement>>} The new
  1703. * condition.
  1704. */
  1705. function elementsLocated(locator: Locator): Condition<IWebElement[]>;
  1706. function elementsLocated(locator: any): Condition<IWebElement[]>;
  1707. /**
  1708. * Creates a condition that will wait for the given element to become stale. An
  1709. * element is considered stale once it is removed from the DOM, or a new page
  1710. * has loaded.
  1711. *
  1712. * @param {!webdriver.WebElement} element The element that should become stale.
  1713. * @return {!until.Condition.<boolean>} The new condition.
  1714. */
  1715. function stalenessOf(element: IWebElement): Condition<boolean>;
  1716. /**
  1717. * Creates a condition that will wait for the current page's title to contain
  1718. * the given substring.
  1719. *
  1720. * @param {string} substr The substring that should be present in the page
  1721. * title.
  1722. * @return {!until.Condition.<boolean>} The new condition.
  1723. */
  1724. function titleContains(substr: string): Condition<boolean>;
  1725. /**
  1726. * Creates a condition that will wait for the current page's title to match the
  1727. * given value.
  1728. *
  1729. * @param {string} title The expected page title.
  1730. * @return {!until.Condition.<boolean>} The new condition.
  1731. */
  1732. function titleIs(title: string): Condition<boolean>;
  1733. /**
  1734. * Creates a condition that will wait for the current page's title to match the
  1735. * given regular expression.
  1736. *
  1737. * @param {!RegExp} regex The regular expression to test against.
  1738. * @return {!until.Condition.<boolean>} The new condition.
  1739. */
  1740. function titleMatches(regex: RegExp): Condition<boolean>;
  1741. }
  1742. interface ILocation {
  1743. x: number;
  1744. y: number;
  1745. }
  1746. interface ISize {
  1747. width: number;
  1748. height: number;
  1749. }
  1750. /**
  1751. * Enumeration of the buttons used in the advanced interactions API.
  1752. * NOTE: A TypeScript enum was not used so that this class could be extended in Protractor.
  1753. * @enum {number}
  1754. */
  1755. interface IButton {
  1756. LEFT: number;
  1757. MIDDLE: number;
  1758. RIGHT: number;
  1759. }
  1760. var Button: IButton
  1761. /**
  1762. * Representations of pressable keys that aren't text. These are stored in
  1763. * the Unicode PUA (Private Use Area) code points, 0xE000-0xF8FF. Refer to
  1764. * http://www.google.com.au/search?&q=unicode+pua&btnG=Search
  1765. *
  1766. * @enum {string}
  1767. */
  1768. interface IKey {
  1769. NULL: string;
  1770. CANCEL: string; // ^break
  1771. HELP: string;
  1772. BACK_SPACE: string;
  1773. TAB: string;
  1774. CLEAR: string;
  1775. RETURN: string;
  1776. ENTER: string;
  1777. SHIFT: string;
  1778. CONTROL: string;
  1779. ALT: string;
  1780. PAUSE: string;
  1781. ESCAPE: string;
  1782. SPACE: string;
  1783. PAGE_UP: string;
  1784. PAGE_DOWN: string;
  1785. END: string;
  1786. HOME: string;
  1787. ARROW_LEFT: string;
  1788. LEFT: string;
  1789. ARROW_UP: string;
  1790. UP: string;
  1791. ARROW_RIGHT: string;
  1792. RIGHT: string;
  1793. ARROW_DOWN: string;
  1794. DOWN: string;
  1795. INSERT: string;
  1796. DELETE: string;
  1797. SEMICOLON: string;
  1798. EQUALS: string;
  1799. NUMPAD0: string; // number pad keys
  1800. NUMPAD1: string;
  1801. NUMPAD2: string;
  1802. NUMPAD3: string;
  1803. NUMPAD4: string;
  1804. NUMPAD5: string;
  1805. NUMPAD6: string;
  1806. NUMPAD7: string;
  1807. NUMPAD8: string;
  1808. NUMPAD9: string;
  1809. MULTIPLY: string;
  1810. ADD: string;
  1811. SEPARATOR: string;
  1812. SUBTRACT: string;
  1813. DECIMAL: string;
  1814. DIVIDE: string;
  1815. F1: string; // function keys
  1816. F2: string;
  1817. F3: string;
  1818. F4: string;
  1819. F5: string;
  1820. F6: string;
  1821. F7: string;
  1822. F8: string;
  1823. F9: string;
  1824. F10: string;
  1825. F11: string;
  1826. F12: string;
  1827. COMMAND: string; // Apple command key
  1828. META: string; // alias for Windows key
  1829. /**
  1830. * Simulate pressing many keys at once in a "chord". Takes a sequence of
  1831. * {@link webdriver.Key}s or strings, appends each of the values to a string,
  1832. * and adds the chord termination key ({@link webdriver.Key.NULL}) and returns
  1833. * the resultant string.
  1834. *
  1835. * Note: when the low-level webdriver key handlers see Keys.NULL, active
  1836. * modifier keys (CTRL/ALT/SHIFT/etc) release via a keyup event.
  1837. *
  1838. * @param {...string} var_args The key sequence to concatenate.
  1839. * @return {string} The null-terminated key sequence.
  1840. * @see http://code.google.com/p/webdriver/issues/detail?id=79
  1841. */
  1842. chord: (...var_args: string[]) => string;
  1843. }
  1844. var Key: IKey;
  1845. /**
  1846. * Class for defining sequences of complex user interactions. Each sequence
  1847. * will not be executed until {@link #perform} is called.
  1848. *
  1849. * <p>Example:<pre><code>
  1850. * new webdriver.ActionSequence(driver).
  1851. * keyDown(webdriver.Key.SHIFT).
  1852. * click(element1).
  1853. * click(element2).
  1854. * dragAndDrop(element3, element4).
  1855. * keyUp(webdriver.Key.SHIFT).
  1856. * perform();
  1857. * </pre></code>
  1858. *
  1859. */
  1860. class ActionSequence {
  1861. //region Constructors
  1862. /**
  1863. * @param {!webdriver.WebDriver} driver The driver instance to use.
  1864. * @constructor
  1865. */
  1866. constructor(driver: WebDriver);
  1867. //endregion
  1868. //region Methods
  1869. /**
  1870. * Executes this action sequence.
  1871. * @return {!webdriver.promise.Promise} A promise that will be resolved once
  1872. * this sequence has completed.
  1873. */
  1874. perform(): webdriver.promise.Promise<void>;
  1875. /**
  1876. * Moves the mouse. The location to move to may be specified in terms of the
  1877. * mouse's current location, an offset relative to the top-left corner of an
  1878. * element, or an element (in which case the middle of the element is used).
  1879. * @param {(!webdriver.WebElement|{x: number, y: number})} location The
  1880. * location to drag to, as either another WebElement or an offset in pixels.
  1881. * @param {{x: number, y: number}=} opt_offset An optional offset, in pixels.
  1882. * Defaults to (0, 0).
  1883. * @return {!webdriver.ActionSequence} A self reference.
  1884. */
  1885. mouseMove(location: IWebElement, opt_offset?: ILocation): ActionSequence;
  1886. mouseMove(location: ILocation): ActionSequence;
  1887. /**
  1888. * Presses a mouse button. The mouse button will not be released until
  1889. * {@link #mouseUp} is called, regardless of whether that call is made in this
  1890. * sequence or another. The behavior for out-of-order events (e.g. mouseDown,
  1891. * click) is undefined.
  1892. *
  1893. * <p>If an element is provided, the mouse will first be moved to the center
  1894. * of that element. This is equivalent to:
  1895. * <pre><code>sequence.mouseMove(element).mouseDown()</code></pre>
  1896. *
  1897. * <p>Warning: this method currently only supports the left mouse button. See
  1898. * http://code.google.com/p/selenium/issues/detail?id=4047
  1899. *
  1900. * @param {(webdriver.WebElement|webdriver.Button)=} opt_elementOrButton Either
  1901. * the element to interact with or the button to click with.
  1902. * Defaults to {@link webdriver.Button.LEFT} if neither an element nor
  1903. * button is specified.
  1904. * @param {webdriver.Button=} opt_button The button to use. Defaults to
  1905. * {@link webdriver.Button.LEFT}. Ignored if a button is provided as the
  1906. * first argument.
  1907. * @return {!webdriver.ActionSequence} A self reference.
  1908. */
  1909. mouseDown(opt_elementOrButton?: IWebElement, opt_button?: number): ActionSequence;
  1910. mouseDown(opt_elementOrButton?: number): ActionSequence;
  1911. /**
  1912. * Releases a mouse button. Behavior is undefined for calling this function
  1913. * without a previous call to {@link #mouseDown}.
  1914. *
  1915. * <p>If an element is provided, the mouse will first be moved to the center
  1916. * of that element. This is equivalent to:
  1917. * <pre><code>sequence.mouseMove(element).mouseUp()</code></pre>
  1918. *
  1919. * <p>Warning: this method currently only supports the left mouse button. See
  1920. * http://code.google.com/p/selenium/issues/detail?id=4047
  1921. *
  1922. * @param {(webdriver.WebElement|webdriver.Button)=} opt_elementOrButton Either
  1923. * the element to interact with or the button to click with.
  1924. * Defaults to {@link webdriver.Button.LEFT} if neither an element nor
  1925. * button is specified.
  1926. * @param {webdriver.Button=} opt_button The button to use. Defaults to
  1927. * {@link webdriver.Button.LEFT}. Ignored if a button is provided as the
  1928. * first argument.
  1929. * @return {!webdriver.ActionSequence} A self reference.
  1930. */
  1931. mouseUp(opt_elementOrButton?: IWebElement, opt_button?: number): ActionSequence;
  1932. mouseUp(opt_elementOrButton?: number): ActionSequence;
  1933. /**
  1934. * Convenience function for performing a "drag and drop" manuever. The target
  1935. * element may be moved to the location of another element, or by an offset (in
  1936. * pixels).
  1937. * @param {!webdriver.WebElement} element The element to drag.
  1938. * @param {(!webdriver.WebElement|{x: number, y: number})} location The
  1939. * location to drag to, either as another WebElement or an offset in pixels.
  1940. * @return {!webdriver.ActionSequence} A self reference.
  1941. */
  1942. dragAndDrop(element: IWebElement, location: IWebElement): ActionSequence;
  1943. dragAndDrop(element: IWebElement, location: ILocation): ActionSequence;
  1944. /**
  1945. * Clicks a mouse button.
  1946. *
  1947. * <p>If an element is provided, the mouse will first be moved to the center
  1948. * of that element. This is equivalent to:
  1949. * <pre><code>sequence.mouseMove(element).click()</code></pre>
  1950. *
  1951. * @param {(webdriver.WebElement|webdriver.Button)=} opt_elementOrButton Either
  1952. * the element to interact with or the button to click with.
  1953. * Defaults to {@link webdriver.Button.LEFT} if neither an element nor
  1954. * button is specified.
  1955. * @param {webdriver.Button=} opt_button The button to use. Defaults to
  1956. * {@link webdriver.Button.LEFT}. Ignored if a button is provided as the
  1957. * first argument.
  1958. * @return {!webdriver.ActionSequence} A self reference.
  1959. */
  1960. click(opt_elementOrButton?: IWebElement, opt_button?: number): ActionSequence;
  1961. click(opt_elementOrButton?: number): ActionSequence;
  1962. /**
  1963. * Double-clicks a mouse button.
  1964. *
  1965. * <p>If an element is provided, the mouse will first be moved to the center of
  1966. * that element. This is equivalent to:
  1967. * <pre><code>sequence.mouseMove(element).doubleClick()</code></pre>
  1968. *
  1969. * <p>Warning: this method currently only supports the left mouse button. See
  1970. * http://code.google.com/p/selenium/issues/detail?id=4047
  1971. *
  1972. * @param {(webdriver.WebElement|webdriver.Button)=} opt_elementOrButton Either
  1973. * the element to interact with or the button to click with.
  1974. * Defaults to {@link webdriver.Button.LEFT} if neither an element nor
  1975. * button is specified.
  1976. * @param {webdriver.Button=} opt_button The button to use. Defaults to
  1977. * {@link webdriver.Button.LEFT}. Ignored if a button is provided as the
  1978. * first argument.
  1979. * @return {!webdriver.ActionSequence} A self reference.
  1980. */
  1981. doubleClick(opt_elementOrButton?: IWebElement, opt_button?: number): ActionSequence;
  1982. doubleClick(opt_elementOrButton?: number): ActionSequence;
  1983. /**
  1984. * Performs a modifier key press. The modifier key is <em>not released</em>
  1985. * until {@link #keyUp} or {@link #sendKeys} is called. The key press will be
  1986. * targetted at the currently focused element.
  1987. * @param {!webdriver.Key} key The modifier key to push. Must be one of
  1988. * {ALT, CONTROL, SHIFT, COMMAND, META}.
  1989. * @return {!webdriver.ActionSequence} A self reference.
  1990. * @throws {Error} If the key is not a valid modifier key.
  1991. */
  1992. keyDown(key: string): ActionSequence;
  1993. /**
  1994. * Performs a modifier key release. The release is targetted at the currently
  1995. * focused element.
  1996. * @param {!webdriver.Key} key The modifier key to release. Must be one of
  1997. * {ALT, CONTROL, SHIFT, COMMAND, META}.
  1998. * @return {!webdriver.ActionSequence} A self reference.
  1999. * @throws {Error} If the key is not a valid modifier key.
  2000. */
  2001. keyUp(key: string): ActionSequence;
  2002. /**
  2003. * Simulates typing multiple keys. Each modifier key encountered in the
  2004. * sequence will not be released until it is encountered again. All key events
  2005. * will be targetted at the currently focused element.
  2006. * @param {...(string|!webdriver.Key|!Array.<(string|!webdriver.Key)>)} var_args
  2007. * The keys to type.
  2008. * @return {!webdriver.ActionSequence} A self reference.
  2009. * @throws {Error} If the key is not a valid modifier key.
  2010. */
  2011. sendKeys(...var_args: any[]): ActionSequence;
  2012. //endregion
  2013. }
  2014. /**
  2015. * Represents a modal dialog such as {@code alert}, {@code confirm}, or
  2016. * {@code prompt}. Provides functions to retrieve the message displayed with
  2017. * the alert, accept or dismiss the alert, and set the response text (in the
  2018. * case of {@code prompt}).
  2019. */
  2020. interface Alert {
  2021. //region Methods
  2022. /**
  2023. * Retrieves the message text displayed with this alert. For instance, if the
  2024. * alert were opened with alert("hello"), then this would return "hello".
  2025. * @return {!webdriver.promise.Promise} A promise that will be resolved to the
  2026. * text displayed with this alert.
  2027. */
  2028. getText(): webdriver.promise.Promise<string>;
  2029. /**
  2030. * Accepts this alert.
  2031. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  2032. * this command has completed.
  2033. */
  2034. accept(): webdriver.promise.Promise<void>;
  2035. /**
  2036. * Dismisses this alert.
  2037. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  2038. * this command has completed.
  2039. */
  2040. dismiss(): webdriver.promise.Promise<void>;
  2041. /**
  2042. * Sets the response text on this alert. This command will return an error if
  2043. * the underlying alert does not support response text (e.g. window.alert and
  2044. * window.confirm).
  2045. * @param {string} text The text to set.
  2046. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  2047. * this command has completed.
  2048. */
  2049. sendKeys(text: string): webdriver.promise.Promise<void>;
  2050. //endregion
  2051. }
  2052. /**
  2053. * AlertPromise is a promise that will be fulfilled with an Alert. This promise
  2054. * serves as a forward proxy on an Alert, allowing calls to be scheduled
  2055. * directly on this instance before the underlying Alert has been fulfilled. In
  2056. * other words, the following two statements are equivalent:
  2057. * <pre><code>
  2058. * driver.switchTo().alert().dismiss();
  2059. * driver.switchTo().alert().then(function(alert) {
  2060. * return alert.dismiss();
  2061. * });
  2062. * </code></pre>
  2063. *
  2064. * @param {!webdriver.WebDriver} driver The driver controlling the browser this
  2065. * alert is attached to.
  2066. * @param {!webdriver.promise.Thenable.<!webdriver.Alert>} alert A thenable
  2067. * that will be fulfilled with the promised alert.
  2068. * @constructor
  2069. * @extends {webdriver.Alert}
  2070. * @implements {webdriver.promise.Thenable.<!webdriver.Alert>}
  2071. * @final
  2072. */
  2073. interface AlertPromise extends Alert, webdriver.promise.IThenable<Alert> {
  2074. }
  2075. /**
  2076. * An error returned to indicate that there is an unhandled modal dialog on the
  2077. * current page.
  2078. * @extends {bot.Error}
  2079. */
  2080. interface UnhandledAlertError extends webdriver.error.Error {
  2081. //region Methods
  2082. /**
  2083. * @return {string} The text displayed with the unhandled alert.
  2084. */
  2085. getAlertText(): string;
  2086. /**
  2087. * @return {!webdriver.Alert} The open alert.
  2088. * @deprecated Use {@link #getAlertText}. This method will be removed in
  2089. * 2.45.0.
  2090. */
  2091. getAlert(): Alert;
  2092. //endregion
  2093. }
  2094. /**
  2095. * Recognized browser names.
  2096. * @enum {string}
  2097. */
  2098. interface IBrowser {
  2099. ANDROID: string;
  2100. CHROME: string;
  2101. FIREFOX: string;
  2102. INTERNET_EXPLORER: string;
  2103. IPAD: string;
  2104. IPHONE: string;
  2105. OPERA: string;
  2106. PHANTOM_JS: string;
  2107. SAFARI: string;
  2108. HTMLUNIT: string;
  2109. }
  2110. var Browser: IBrowser
  2111. interface ProxyConfig {
  2112. proxyType: string;
  2113. proxyAutoconfigUrl?: string;
  2114. ftpProxy?: string;
  2115. httpProxy?: string;
  2116. sslProxy?: string;
  2117. noProxy?: string;
  2118. }
  2119. class Builder {
  2120. //region Constructors
  2121. /**
  2122. * @constructor
  2123. */
  2124. constructor();
  2125. //endregion
  2126. //region Methods
  2127. /**
  2128. * Creates a new WebDriver client based on this builder's current
  2129. * configuration.
  2130. *
  2131. * @return {!webdriver.WebDriver} A new WebDriver instance.
  2132. * @throws {Error} If the current configuration is invalid.
  2133. */
  2134. build(): WebDriver;
  2135. /**
  2136. * Configures the target browser for clients created by this instance.
  2137. * Any calls to {@link #withCapabilities} after this function will
  2138. * overwrite these settings.
  2139. *
  2140. * <p>You may also define the target browser using the {@code SELENIUM_BROWSER}
  2141. * environment variable. If set, this environment variable should be of the
  2142. * form {@code browser[:[version][:platform]]}.
  2143. *
  2144. * @param {(string|webdriver.Browser)} name The name of the target browser;
  2145. * common defaults are available on the {@link webdriver.Browser} enum.
  2146. * @param {string=} opt_version A desired version; may be omitted if any
  2147. * version should be used.
  2148. * @param {string=} opt_platform The desired platform; may be omitted if any
  2149. * version may be used.
  2150. * @return {!Builder} A self reference.
  2151. */
  2152. forBrowser(name: string, opt_version?: string, opt_platform?: string): Builder;
  2153. /**
  2154. * Returns the base set of capabilities this instance is currently configured
  2155. * to use.
  2156. * @return {!webdriver.Capabilities} The current capabilities for this builder.
  2157. */
  2158. getCapabilities(): Capabilities;
  2159. /**
  2160. * @return {string} The URL of the WebDriver server this instance is configured
  2161. * to use.
  2162. */
  2163. getServerUrl(): string;
  2164. /**
  2165. * Sets the default action to take with an unexpected alert before returning
  2166. * an error.
  2167. * @param {string} beahvior The desired behavior; should be "accept", "dismiss",
  2168. * or "ignore". Defaults to "dismiss".
  2169. * @return {!Builder} A self reference.
  2170. */
  2171. setAlertBehavior(behavior: string): Builder;
  2172. /**
  2173. * Sets Chrome-specific options for drivers created by this builder. Any
  2174. * logging or proxy settings defined on the given options will take precedence
  2175. * over those set through {@link #setLoggingPrefs} and {@link #setProxy},
  2176. * respectively.
  2177. *
  2178. * @param {!chrome.Options} options The ChromeDriver options to use.
  2179. * @return {!Builder} A self reference.
  2180. */
  2181. setChromeOptions(options: chrome.Options): Builder;
  2182. /**
  2183. * Sets the control flow that created drivers should execute actions in. If
  2184. * the flow is never set, or is set to {@code null}, it will use the active
  2185. * flow at the time {@link #build()} is called.
  2186. * @param {webdriver.promise.ControlFlow} flow The control flow to use, or
  2187. * {@code null} to
  2188. * @return {!Builder} A self reference.
  2189. */
  2190. setControlFlow(flow: webdriver.promise.ControlFlow): Builder;
  2191. /**
  2192. * Sets whether native events should be used.
  2193. * @param {boolean} enabled Whether to enable native events.
  2194. * @return {!Builder} A self reference.
  2195. */
  2196. setEnableNativeEvents(enabled: boolean): Builder;
  2197. /**
  2198. * Sets Firefox-specific options for drivers created by this builder. Any
  2199. * logging or proxy settings defined on the given options will take precedence
  2200. * over those set through {@link #setLoggingPrefs} and {@link #setProxy},
  2201. * respectively.
  2202. *
  2203. * @param {!firefox.Options} options The FirefoxDriver options to use.
  2204. * @return {!Builder} A self reference.
  2205. */
  2206. setFirefoxOptions(options: firefox.Options): Builder;
  2207. /**
  2208. * Sets the logging preferences for the created session. Preferences may be
  2209. * changed by repeated calls, or by calling {@link #withCapabilities}.
  2210. * @param {!(webdriver.logging.Preferences|Object.<string, string>)} prefs The
  2211. * desired logging preferences.
  2212. * @return {!Builder} A self reference.
  2213. */
  2214. setLoggingPrefs(prefs: webdriver.logging.Preferences): Builder;
  2215. setLoggingPrefs(prefs: { [key: string]: string }): Builder;
  2216. /**
  2217. * Sets the proxy configuration to use for WebDriver clients created by this
  2218. * builder. Any calls to {@link #withCapabilities} after this function will
  2219. * overwrite these settings.
  2220. * @param {!webdriver.ProxyConfig} config The configuration to use.
  2221. * @return {!Builder} A self reference.
  2222. */
  2223. setProxy(config: ProxyConfig): Builder;
  2224. /**
  2225. * Sets how elements should be scrolled into view for interaction.
  2226. * @param {number} behavior The desired scroll behavior: either 0 to align with
  2227. * the top of the viewport or 1 to align with the bottom.
  2228. * @return {!Builder} A self reference.
  2229. */
  2230. setScrollBehavior(behavior: number): Builder;
  2231. /**
  2232. * Sets the URL of a remote WebDriver server to use. Once a remote URL has been
  2233. * specified, the builder direct all new clients to that server. If this method
  2234. * is never called, the Builder will attempt to create all clients locally.
  2235. *
  2236. * <p>As an alternative to this method, you may also set the
  2237. * {@code SELENIUM_REMOTE_URL} environment variable.
  2238. *
  2239. * @param {string} url The URL of a remote server to use.
  2240. * @return {!Builder} A self reference.
  2241. */
  2242. usingServer(url: string): Builder;
  2243. /**
  2244. * Sets the desired capabilities when requesting a new session. This will
  2245. * overwrite any previously set capabilities.
  2246. * @param {!(Object|webdriver.Capabilities)} capabilities The desired
  2247. * capabilities for a new session.
  2248. * @return {!Builder} A self reference.
  2249. */
  2250. withCapabilities(capabilities: Capabilities): Builder;
  2251. withCapabilities(capabilities: any): Builder;
  2252. //endregion
  2253. }
  2254. /**
  2255. * Common webdriver capability keys.
  2256. * @enum {string}
  2257. */
  2258. interface ICapability {
  2259. /**
  2260. * Indicates whether a driver should accept all SSL certs by default. This
  2261. * capability only applies when requesting a new session. To query whether
  2262. * a driver can handle insecure SSL certs, see
  2263. * {@link webdriver.Capability.SECURE_SSL}.
  2264. */
  2265. ACCEPT_SSL_CERTS: string;
  2266. /**
  2267. * The browser name. Common browser names are defined in the
  2268. * {@link webdriver.Browser} enum.
  2269. */
  2270. BROWSER_NAME: string;
  2271. /**
  2272. * Defines how elements should be scrolled into the viewport for interaction.
  2273. * This capability will be set to zero (0) if elements are aligned with the
  2274. * top of the viewport, or one (1) if aligned with the bottom. The default
  2275. * behavior is to align with the top of the viewport.
  2276. */
  2277. ELEMENT_SCROLL_BEHAVIOR: string;
  2278. /**
  2279. * Whether the driver is capable of handling modal alerts (e.g. alert,
  2280. * confirm, prompt). To define how a driver <i>should</i> handle alerts,
  2281. * use {@link webdriver.Capability.UNEXPECTED_ALERT_BEHAVIOR}.
  2282. */
  2283. HANDLES_ALERTS: string;
  2284. /**
  2285. * Key for the logging driver logging preferences.
  2286. */
  2287. LOGGING_PREFS: string;
  2288. /**
  2289. * Whether this session generates native events when simulating user input.
  2290. */
  2291. NATIVE_EVENTS: string;
  2292. /**
  2293. * Describes the platform the browser is running on. Will be one of
  2294. * ANDROID, IOS, LINUX, MAC, UNIX, or WINDOWS. When <i>requesting</i> a
  2295. * session, ANY may be used to indicate no platform preference (this is
  2296. * semantically equivalent to omitting the platform capability).
  2297. */
  2298. PLATFORM: string;
  2299. /**
  2300. * Describes the proxy configuration to use for a new WebDriver session.
  2301. */
  2302. PROXY: string;
  2303. /** Whether the driver supports changing the brower's orientation. */
  2304. ROTATABLE: string;
  2305. /**
  2306. * Whether a driver is only capable of handling secure SSL certs. To request
  2307. * that a driver accept insecure SSL certs by default, use
  2308. * {@link webdriver.Capability.ACCEPT_SSL_CERTS}.
  2309. */
  2310. SECURE_SSL: string;
  2311. /** Whether the driver supports manipulating the app cache. */
  2312. SUPPORTS_APPLICATION_CACHE: string;
  2313. /** Whether the driver supports locating elements with CSS selectors. */
  2314. SUPPORTS_CSS_SELECTORS: string;
  2315. /** Whether the browser supports JavaScript. */
  2316. SUPPORTS_JAVASCRIPT: string;
  2317. /** Whether the driver supports controlling the browser's location info. */
  2318. SUPPORTS_LOCATION_CONTEXT: string;
  2319. /** Whether the driver supports taking screenshots. */
  2320. TAKES_SCREENSHOT: string;
  2321. /**
  2322. * Defines how the driver should handle unexpected alerts. The value should
  2323. * be one of "accept", "dismiss", or "ignore.
  2324. */
  2325. UNEXPECTED_ALERT_BEHAVIOR: string;
  2326. /** Defines the browser version. */
  2327. VERSION: string;
  2328. }
  2329. var Capability: ICapability;
  2330. class Capabilities {
  2331. //region Constructors
  2332. /**
  2333. * @param {(webdriver.Capabilities|Object)=} opt_other Another set of
  2334. * capabilities to merge into this instance.
  2335. * @constructor
  2336. */
  2337. constructor(opt_other?: Capabilities);
  2338. constructor(opt_other?: any);
  2339. //endregion
  2340. //region Methods
  2341. /** @return {!Object} The JSON representation of this instance. */
  2342. toJSON(): any;
  2343. /**
  2344. * Merges another set of capabilities into this instance. Any duplicates in
  2345. * the provided set will override those already set on this instance.
  2346. * @param {!(webdriver.Capabilities|Object)} other The capabilities to
  2347. * merge into this instance.
  2348. * @return {!webdriver.Capabilities} A self reference.
  2349. */
  2350. merge(other: Capabilities): Capabilities;
  2351. merge(other: any): Capabilities;
  2352. /**
  2353. * @param {string} key The capability to set.
  2354. * @param {*} value The capability value. Capability values must be JSON
  2355. * serializable. Pass {@code null} to unset the capability.
  2356. * @return {!webdriver.Capabilities} A self reference.
  2357. */
  2358. set(key: string, value: any): Capabilities;
  2359. /**
  2360. * Sets the logging preferences. Preferences may be specified as a
  2361. * {@link webdriver.logging.Preferences} instance, or a as a map of log-type to
  2362. * log-level.
  2363. * @param {!(webdriver.logging.Preferences|Object.<string, string>)} prefs The
  2364. * logging preferences.
  2365. * @return {!webdriver.Capabilities} A self reference.
  2366. */
  2367. setLoggingPrefs(prefs: webdriver.logging.Preferences): Capabilities;
  2368. setLoggingPrefs(prefs: { [key: string]: string }): Capabilities;
  2369. /**
  2370. * Sets the proxy configuration for this instance.
  2371. * @param {webdriver.ProxyConfig} proxy The desired proxy configuration.
  2372. * @return {!webdriver.Capabilities} A self reference.
  2373. */
  2374. setProxy(proxy: ProxyConfig): Capabilities;
  2375. /**
  2376. * Sets whether native events should be used.
  2377. * @param {boolean} enabled Whether to enable native events.
  2378. * @return {!webdriver.Capabilities} A self reference.
  2379. */
  2380. setEnableNativeEvents(enabled: boolean): Capabilities;
  2381. /**
  2382. * Sets how elements should be scrolled into view for interaction.
  2383. * @param {number} behavior The desired scroll behavior: either 0 to align with
  2384. * the top of the viewport or 1 to align with the bottom.
  2385. * @return {!webdriver.Capabilities} A self reference.
  2386. */
  2387. setScrollBehavior(behavior: number): Capabilities;
  2388. /**
  2389. * Sets the default action to take with an unexpected alert before returning
  2390. * an error.
  2391. * @param {string} behavior The desired behavior; should be "accept", "dismiss",
  2392. * or "ignore". Defaults to "dismiss".
  2393. * @return {!webdriver.Capabilities} A self reference.
  2394. */
  2395. setAlertBehavior(behavior: string): Capabilities;
  2396. /**
  2397. * @param {string} key The capability to return.
  2398. * @return {*} The capability with the given key, or {@code null} if it has
  2399. * not been set.
  2400. */
  2401. get(key: string): any;
  2402. /**
  2403. * @param {string} key The capability to check.
  2404. * @return {boolean} Whether the specified capability is set.
  2405. */
  2406. has(key: string): boolean;
  2407. //endregion
  2408. //region Static Methods
  2409. /**
  2410. * @return {!webdriver.Capabilities} A basic set of capabilities for Android.
  2411. */
  2412. static android(): Capabilities;
  2413. /**
  2414. * @return {!webdriver.Capabilities} A basic set of capabilities for Chrome.
  2415. */
  2416. static chrome(): Capabilities;
  2417. /**
  2418. * @return {!webdriver.Capabilities} A basic set of capabilities for Firefox.
  2419. */
  2420. static firefox(): Capabilities;
  2421. /**
  2422. * @return {!webdriver.Capabilities} A basic set of capabilities for
  2423. * Internet Explorer.
  2424. */
  2425. static ie(): Capabilities;
  2426. /**
  2427. * @return {!webdriver.Capabilities} A basic set of capabilities for iPad.
  2428. */
  2429. static ipad(): Capabilities;
  2430. /**
  2431. * @return {!webdriver.Capabilities} A basic set of capabilities for iPhone.
  2432. */
  2433. static iphone(): Capabilities;
  2434. /**
  2435. * @return {!webdriver.Capabilities} A basic set of capabilities for Opera.
  2436. */
  2437. static opera(): Capabilities;
  2438. /**
  2439. * @return {!webdriver.Capabilities} A basic set of capabilities for
  2440. * PhantomJS.
  2441. */
  2442. static phantomjs(): Capabilities;
  2443. /**
  2444. * @return {!webdriver.Capabilities} A basic set of capabilities for Safari.
  2445. */
  2446. static safari(): Capabilities;
  2447. /**
  2448. * @return {!webdriver.Capabilities} A basic set of capabilities for HTMLUnit.
  2449. */
  2450. static htmlunit(): Capabilities;
  2451. /**
  2452. * @return {!webdriver.Capabilities} A basic set of capabilities for HTMLUnit
  2453. * with enabled Javascript.
  2454. */
  2455. static htmlunitwithjs(): Capabilities;
  2456. //endregion
  2457. }
  2458. /**
  2459. * An enumeration of valid command string.
  2460. */
  2461. interface ICommandName {
  2462. GET_SERVER_STATUS: string;
  2463. NEW_SESSION: string;
  2464. GET_SESSIONS: string;
  2465. DESCRIBE_SESSION: string;
  2466. CLOSE: string;
  2467. QUIT: string;
  2468. GET_CURRENT_URL: string;
  2469. GET: string;
  2470. GO_BACK: string;
  2471. GO_FORWARD: string;
  2472. REFRESH: string;
  2473. ADD_COOKIE: string;
  2474. GET_COOKIE: string;
  2475. GET_ALL_COOKIES: string;
  2476. DELETE_COOKIE: string;
  2477. DELETE_ALL_COOKIES: string;
  2478. GET_ACTIVE_ELEMENT: string;
  2479. FIND_ELEMENT: string;
  2480. FIND_ELEMENTS: string;
  2481. FIND_CHILD_ELEMENT: string;
  2482. FIND_CHILD_ELEMENTS: string;
  2483. CLEAR_ELEMENT: string;
  2484. CLICK_ELEMENT: string;
  2485. SEND_KEYS_TO_ELEMENT: string;
  2486. SUBMIT_ELEMENT: string;
  2487. GET_CURRENT_WINDOW_HANDLE: string;
  2488. GET_WINDOW_HANDLES: string;
  2489. GET_WINDOW_POSITION: string;
  2490. SET_WINDOW_POSITION: string;
  2491. GET_WINDOW_SIZE: string;
  2492. SET_WINDOW_SIZE: string;
  2493. MAXIMIZE_WINDOW: string;
  2494. SWITCH_TO_WINDOW: string;
  2495. SWITCH_TO_FRAME: string;
  2496. GET_PAGE_SOURCE: string;
  2497. GET_TITLE: string;
  2498. EXECUTE_SCRIPT: string;
  2499. EXECUTE_ASYNC_SCRIPT: string;
  2500. GET_ELEMENT_TEXT: string;
  2501. GET_ELEMENT_TAG_NAME: string;
  2502. IS_ELEMENT_SELECTED: string;
  2503. IS_ELEMENT_ENABLED: string;
  2504. IS_ELEMENT_DISPLAYED: string;
  2505. GET_ELEMENT_LOCATION: string;
  2506. GET_ELEMENT_LOCATION_IN_VIEW: string;
  2507. GET_ELEMENT_SIZE: string;
  2508. GET_ELEMENT_ATTRIBUTE: string;
  2509. GET_ELEMENT_VALUE_OF_CSS_PROPERTY: string;
  2510. ELEMENT_EQUALS: string;
  2511. SCREENSHOT: string;
  2512. IMPLICITLY_WAIT: string;
  2513. SET_SCRIPT_TIMEOUT: string;
  2514. SET_TIMEOUT: string;
  2515. ACCEPT_ALERT: string;
  2516. DISMISS_ALERT: string;
  2517. GET_ALERT_TEXT: string;
  2518. SET_ALERT_TEXT: string;
  2519. EXECUTE_SQL: string;
  2520. GET_LOCATION: string;
  2521. SET_LOCATION: string;
  2522. GET_APP_CACHE: string;
  2523. GET_APP_CACHE_STATUS: string;
  2524. CLEAR_APP_CACHE: string;
  2525. IS_BROWSER_ONLINE: string;
  2526. SET_BROWSER_ONLINE: string;
  2527. GET_LOCAL_STORAGE_ITEM: string;
  2528. GET_LOCAL_STORAGE_KEYS: string;
  2529. SET_LOCAL_STORAGE_ITEM: string;
  2530. REMOVE_LOCAL_STORAGE_ITEM: string;
  2531. CLEAR_LOCAL_STORAGE: string;
  2532. GET_LOCAL_STORAGE_SIZE: string;
  2533. GET_SESSION_STORAGE_ITEM: string;
  2534. GET_SESSION_STORAGE_KEYS: string;
  2535. SET_SESSION_STORAGE_ITEM: string;
  2536. REMOVE_SESSION_STORAGE_ITEM: string;
  2537. CLEAR_SESSION_STORAGE: string;
  2538. GET_SESSION_STORAGE_SIZE: string;
  2539. SET_SCREEN_ORIENTATION: string;
  2540. GET_SCREEN_ORIENTATION: string;
  2541. // These belong to the Advanced user interactions - an element is
  2542. // optional for these commands.
  2543. CLICK: string;
  2544. DOUBLE_CLICK: string;
  2545. MOUSE_DOWN: string;
  2546. MOUSE_UP: string;
  2547. MOVE_TO: string;
  2548. SEND_KEYS_TO_ACTIVE_ELEMENT: string;
  2549. // These belong to the Advanced Touch API
  2550. TOUCH_SINGLE_TAP: string;
  2551. TOUCH_DOWN: string;
  2552. TOUCH_UP: string;
  2553. TOUCH_MOVE: string;
  2554. TOUCH_SCROLL: string;
  2555. TOUCH_DOUBLE_TAP: string;
  2556. TOUCH_LONG_PRESS: string;
  2557. TOUCH_FLICK: string;
  2558. GET_AVAILABLE_LOG_TYPES: string;
  2559. GET_LOG: string;
  2560. GET_SESSION_LOGS: string;
  2561. }
  2562. var CommandName: ICommandName;
  2563. /**
  2564. * Describes a command to be executed by the WebDriverJS framework.
  2565. * @param {!webdriver.CommandName} name The name of this command.
  2566. * @constructor
  2567. */
  2568. class Command {
  2569. //region Constructors
  2570. /**
  2571. * @param {!webdriver.CommandName} name The name of this command.
  2572. * @constructor
  2573. */
  2574. constructor(name: string);
  2575. //endregion
  2576. //region Methods
  2577. /**
  2578. * @return {!webdriver.CommandName} This command's name.
  2579. */
  2580. getName(): string;
  2581. /**
  2582. * Sets a parameter to send with this command.
  2583. * @param {string} name The parameter name.
  2584. * @param {*} value The parameter value.
  2585. * @return {!webdriver.Command} A self reference.
  2586. */
  2587. setParameter(name: string, value: any): Command;
  2588. /**
  2589. * Sets the parameters for this command.
  2590. * @param {!Object.<*>} parameters The command parameters.
  2591. * @return {!webdriver.Command} A self reference.
  2592. */
  2593. setParameters(parameters: any): Command;
  2594. /**
  2595. * Returns a named command parameter.
  2596. * @param {string} key The parameter key to look up.
  2597. * @return {*} The parameter value, or undefined if it has not been set.
  2598. */
  2599. getParameter(key: string): any;
  2600. /**
  2601. * @return {!Object.<*>} The parameters to send with this command.
  2602. */
  2603. getParameters(): any;
  2604. //endregion
  2605. }
  2606. /**
  2607. * Handles the execution of {@code webdriver.Command} objects.
  2608. */
  2609. interface CommandExecutor {
  2610. /**
  2611. * Executes the given {@code command}. If there is an error executing the
  2612. * command, the provided callback will be invoked with the offending error.
  2613. * Otherwise, the callback will be invoked with a null Error and non-null
  2614. * {@link bot.response.ResponseObject} object.
  2615. * @param {!webdriver.Command} command The command to execute.
  2616. * @param {function(Error, !bot.response.ResponseObject=)} callback the function
  2617. * to invoke when the command response is ready.
  2618. */
  2619. execute(command: Command, callback: (error: Error, responseObject: any) => any ): void;
  2620. }
  2621. /**
  2622. * Object that can emit events for others to listen for. This is used instead
  2623. * of Closure's event system because it is much more light weight. The API is
  2624. * based on Node's EventEmitters.
  2625. */
  2626. class EventEmitter {
  2627. //region Constructors
  2628. /**
  2629. * @constructor
  2630. */
  2631. constructor();
  2632. //endregion
  2633. //region Methods
  2634. /**
  2635. * Fires an event and calls all listeners.
  2636. * @param {string} type The type of event to emit.
  2637. * @param {...*} var_args Any arguments to pass to each listener.
  2638. */
  2639. emit(type: string, ...var_args: any[]): void;
  2640. /**
  2641. * Returns a mutable list of listeners for a specific type of event.
  2642. * @param {string} type The type of event to retrieve the listeners for.
  2643. * @return {!Array.<{fn: !Function, oneshot: boolean,
  2644. * scope: (Object|undefined)}>} The registered listeners for
  2645. * the given event type.
  2646. */
  2647. listeners(type: string): Array<{fn: Function; oneshot: boolean; scope: any;}>;
  2648. /**
  2649. * Registers a listener.
  2650. * @param {string} type The type of event to listen for.
  2651. * @param {!Function} listenerFn The function to invoke when the event is fired.
  2652. * @param {Object=} opt_scope The object in whose scope to invoke the listener.
  2653. * @return {!webdriver.EventEmitter} A self reference.
  2654. */
  2655. addListener(type: string, listenerFn: Function, opt_scope?:any): EventEmitter;
  2656. /**
  2657. * Registers a one-time listener which will be called only the first time an
  2658. * event is emitted, after which it will be removed.
  2659. * @param {string} type The type of event to listen for.
  2660. * @param {!Function} listenerFn The function to invoke when the event is fired.
  2661. * @param {Object=} opt_scope The object in whose scope to invoke the listener.
  2662. * @return {!webdriver.EventEmitter} A self reference.
  2663. */
  2664. once(type: string, listenerFn: any, opt_scope?: any): EventEmitter;
  2665. /**
  2666. * An alias for {@code #addListener()}.
  2667. * @param {string} type The type of event to listen for.
  2668. * @param {!Function} listenerFn The function to invoke when the event is fired.
  2669. * @param {Object=} opt_scope The object in whose scope to invoke the listener.
  2670. * @return {!webdriver.EventEmitter} A self reference.
  2671. */
  2672. on(type: string, listenerFn: Function, opt_scope?:any): EventEmitter;
  2673. /**
  2674. * Removes a previously registered event listener.
  2675. * @param {string} type The type of event to unregister.
  2676. * @param {!Function} listenerFn The handler function to remove.
  2677. * @return {!webdriver.EventEmitter} A self reference.
  2678. */
  2679. removeListener(type: string, listenerFn: Function): EventEmitter;
  2680. /**
  2681. * Removes all listeners for a specific type of event. If no event is
  2682. * specified, all listeners across all types will be removed.
  2683. * @param {string=} opt_type The type of event to remove listeners from.
  2684. * @return {!webdriver.EventEmitter} A self reference.
  2685. */
  2686. removeAllListeners(opt_type?: string): EventEmitter;
  2687. //endregion
  2688. }
  2689. /**
  2690. * Interface for navigating back and forth in the browser history.
  2691. */
  2692. interface WebDriverNavigation {
  2693. //region Constructors
  2694. /**
  2695. * @param {!webdriver.WebDriver} driver The parent driver.
  2696. * @constructor
  2697. */
  2698. new (driver: WebDriver): WebDriverNavigation;
  2699. //endregion
  2700. //region Methods
  2701. /**
  2702. * Schedules a command to navigate to a new URL.
  2703. * @param {string} url The URL to navigate to.
  2704. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2705. * URL has been loaded.
  2706. */
  2707. to(url: string): webdriver.promise.Promise<void>;
  2708. /**
  2709. * Schedules a command to move backwards in the browser history.
  2710. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2711. * navigation event has completed.
  2712. */
  2713. back(): webdriver.promise.Promise<void>;
  2714. /**
  2715. * Schedules a command to move forwards in the browser history.
  2716. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2717. * navigation event has completed.
  2718. */
  2719. forward(): webdriver.promise.Promise<void>;
  2720. /**
  2721. * Schedules a command to refresh the current page.
  2722. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2723. * navigation event has completed.
  2724. */
  2725. refresh(): webdriver.promise.Promise<void>;
  2726. //endregion
  2727. }
  2728. interface IWebDriverOptionsCookie {
  2729. name: string;
  2730. value: string;
  2731. path?: string;
  2732. domain?: string;
  2733. secure?: boolean;
  2734. expiry?: number;
  2735. }
  2736. /**
  2737. * Provides methods for managing browser and driver state.
  2738. */
  2739. interface WebDriverOptions {
  2740. //region Constructors
  2741. /**
  2742. * @param {!webdriver.WebDriver} driver The parent driver.
  2743. * @constructor
  2744. */
  2745. new (driver: webdriver.WebDriver): WebDriverOptions;
  2746. //endregion
  2747. //region Methods
  2748. /**
  2749. * Schedules a command to add a cookie.
  2750. * @param {string} name The cookie name.
  2751. * @param {string} value The cookie value.
  2752. * @param {string=} opt_path The cookie path.
  2753. * @param {string=} opt_domain The cookie domain.
  2754. * @param {boolean=} opt_isSecure Whether the cookie is secure.
  2755. * @param {(number|!Date)=} opt_expiry When the cookie expires. If specified as
  2756. * a number, should be in milliseconds since midnight, January 1, 1970 UTC.
  2757. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2758. * cookie has been added to the page.
  2759. */
  2760. addCookie(name: string, value: string, opt_path?: string, opt_domain?: string, opt_isSecure?: boolean, opt_expiry?: number): webdriver.promise.Promise<void>;
  2761. addCookie(name: string, value: string, opt_path?: string, opt_domain?: string, opt_isSecure?: boolean, opt_expiry?: Date): webdriver.promise.Promise<void>;
  2762. /**
  2763. * Schedules a command to delete all cookies visible to the current page.
  2764. * @return {!webdriver.promise.Promise} A promise that will be resolved when all
  2765. * cookies have been deleted.
  2766. */
  2767. deleteAllCookies(): webdriver.promise.Promise<void>;
  2768. /**
  2769. * Schedules a command to delete the cookie with the given name. This command is
  2770. * a no-op if there is no cookie with the given name visible to the current
  2771. * page.
  2772. * @param {string} name The name of the cookie to delete.
  2773. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2774. * cookie has been deleted.
  2775. */
  2776. deleteCookie(name: string): webdriver.promise.Promise<void>;
  2777. /**
  2778. * Schedules a command to retrieve all cookies visible to the current page.
  2779. * Each cookie will be returned as a JSON object as described by the WebDriver
  2780. * wire protocol.
  2781. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  2782. * cookies visible to the current page.
  2783. * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object
  2784. */
  2785. getCookies(): webdriver.promise.Promise<IWebDriverOptionsCookie[]>;
  2786. /**
  2787. * Schedules a command to retrieve the cookie with the given name. Returns null
  2788. * if there is no such cookie. The cookie will be returned as a JSON object as
  2789. * described by the WebDriver wire protocol.
  2790. * @param {string} name The name of the cookie to retrieve.
  2791. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  2792. * named cookie, or {@code null} if there is no such cookie.
  2793. * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object
  2794. */
  2795. getCookie(name: string): webdriver.promise.Promise<IWebDriverOptionsCookie>;
  2796. /**
  2797. * @return {!webdriver.WebDriver.Logs} The interface for managing driver
  2798. * logs.
  2799. */
  2800. logs(): WebDriverLogs;
  2801. /**
  2802. * @return {!webdriver.WebDriver.Timeouts} The interface for managing driver
  2803. * timeouts.
  2804. */
  2805. timeouts(): WebDriverTimeouts;
  2806. /**
  2807. * @return {!webdriver.WebDriver.Window} The interface for managing the
  2808. * current window.
  2809. */
  2810. window(): WebDriverWindow;
  2811. //endregion
  2812. }
  2813. /**
  2814. * An interface for managing timeout behavior for WebDriver instances.
  2815. */
  2816. interface WebDriverTimeouts {
  2817. //region Constructors
  2818. /**
  2819. * @param {!webdriver.WebDriver} driver The parent driver.
  2820. * @constructor
  2821. */
  2822. new (driver: WebDriver): WebDriverTimeouts;
  2823. //endregion
  2824. //region Methods
  2825. /**
  2826. * Specifies the amount of time the driver should wait when searching for an
  2827. * element if it is not immediately present.
  2828. * <p/>
  2829. * When searching for a single element, the driver should poll the page
  2830. * until the element has been found, or this timeout expires before failing
  2831. * with a {@code bot.ErrorCode.NO_SUCH_ELEMENT} error. When searching
  2832. * for multiple elements, the driver should poll the page until at least one
  2833. * element has been found or this timeout has expired.
  2834. * <p/>
  2835. * Setting the wait timeout to 0 (its default value), disables implicit
  2836. * waiting.
  2837. * <p/>
  2838. * Increasing the implicit wait timeout should be used judiciously as it
  2839. * will have an adverse effect on test run time, especially when used with
  2840. * slower location strategies like XPath.
  2841. *
  2842. * @param {number} ms The amount of time to wait, in milliseconds.
  2843. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2844. * implicit wait timeout has been set.
  2845. */
  2846. implicitlyWait(ms: number): webdriver.promise.Promise<void>;
  2847. /**
  2848. * Sets the amount of time to wait, in milliseconds, for an asynchronous script
  2849. * to finish execution before returning an error. If the timeout is less than or
  2850. * equal to 0, the script will be allowed to run indefinitely.
  2851. *
  2852. * @param {number} ms The amount of time to wait, in milliseconds.
  2853. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2854. * script timeout has been set.
  2855. */
  2856. setScriptTimeout(ms: number): webdriver.promise.Promise<void>;
  2857. /**
  2858. * Sets the amount of time to wait for a page load to complete before returning
  2859. * an error. If the timeout is negative, page loads may be indefinite.
  2860. * @param {number} ms The amount of time to wait, in milliseconds.
  2861. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  2862. * the timeout has been set.
  2863. */
  2864. pageLoadTimeout(ms: number): webdriver.promise.Promise<void>;
  2865. //endregion
  2866. }
  2867. /**
  2868. * An interface for managing the current window.
  2869. */
  2870. interface WebDriverWindow {
  2871. //region Constructors
  2872. /**
  2873. * @param {!webdriver.WebDriver} driver The parent driver.
  2874. * @constructor
  2875. */
  2876. new (driver: WebDriver): WebDriverWindow;
  2877. //endregion
  2878. //region Methods
  2879. /**
  2880. * Retrieves the window's current position, relative to the top left corner of
  2881. * the screen.
  2882. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  2883. * window's position in the form of a {x:number, y:number} object literal.
  2884. */
  2885. getPosition(): webdriver.promise.Promise<ILocation>;
  2886. /**
  2887. * Repositions the current window.
  2888. * @param {number} x The desired horizontal position, relative to the left side
  2889. * of the screen.
  2890. * @param {number} y The desired vertical position, relative to the top of the
  2891. * of the screen.
  2892. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2893. * command has completed.
  2894. */
  2895. setPosition(x: number, y: number): webdriver.promise.Promise<void>;
  2896. /**
  2897. * Retrieves the window's current size.
  2898. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  2899. * window's size in the form of a {width:number, height:number} object
  2900. * literal.
  2901. */
  2902. getSize(): webdriver.promise.Promise<ISize>;
  2903. /**
  2904. * Resizes the current window.
  2905. * @param {number} width The desired window width.
  2906. * @param {number} height The desired window height.
  2907. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2908. * command has completed.
  2909. */
  2910. setSize(width: number, height: number): webdriver.promise.Promise<void>;
  2911. /**
  2912. * Maximizes the current window.
  2913. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2914. * command has completed.
  2915. */
  2916. maximize(): webdriver.promise.Promise<void>;
  2917. //endregion
  2918. }
  2919. /**
  2920. * Interface for managing WebDriver log records.
  2921. */
  2922. interface WebDriverLogs {
  2923. //region Constructors
  2924. /**
  2925. * @param {!webdriver.WebDriver} driver The parent driver.
  2926. * @constructor
  2927. */
  2928. new (driver: WebDriver): WebDriverLogs;
  2929. //endregion
  2930. //region
  2931. /**
  2932. * Fetches available log entries for the given type.
  2933. *
  2934. * <p/>Note that log buffers are reset after each call, meaning that
  2935. * available log entries correspond to those entries not yet returned for a
  2936. * given log type. In practice, this means that this call will return the
  2937. * available log entries since the last call, or from the start of the
  2938. * session.
  2939. *
  2940. * @param {!webdriver.logging.Type} type The desired log type.
  2941. * @return {!webdriver.promise.Promise.<!Array.<!webdriver.logging.Entry>>} A
  2942. * promise that will resolve to a list of log entries for the specified
  2943. * type.
  2944. */
  2945. get(type: string): webdriver.promise.Promise<webdriver.logging.Entry[]>;
  2946. /**
  2947. * Retrieves the log types available to this driver.
  2948. * @return {!webdriver.promise.Promise.<!Array.<!webdriver.logging.Type>>} A
  2949. * promise that will resolve to a list of available log types.
  2950. */
  2951. getAvailableLogTypes(): webdriver.promise.Promise<string[]>;
  2952. //endregion
  2953. }
  2954. /**
  2955. * An interface for changing the focus of the driver to another frame or window.
  2956. */
  2957. interface WebDriverTargetLocator {
  2958. //region Constructors
  2959. /**
  2960. * @param {!webdriver.WebDriver} driver The parent driver.
  2961. * @constructor
  2962. */
  2963. new (driver: WebDriver): WebDriverTargetLocator;
  2964. //endregion
  2965. //region Methods
  2966. /**
  2967. * Schedules a command retrieve the {@code document.activeElement} element on
  2968. * the current document, or {@code document.body} if activeElement is not
  2969. * available.
  2970. * @return {!webdriver.WebElement} The active element.
  2971. */
  2972. activeElement(): WebElementPromise;
  2973. /**
  2974. * Schedules a command to switch focus of all future commands to the first frame
  2975. * on the page.
  2976. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2977. * driver has changed focus to the default content.
  2978. */
  2979. defaultContent(): webdriver.promise.Promise<void>;
  2980. /**
  2981. * Schedules a command to switch the focus of all future commands to another
  2982. * frame on the page.
  2983. * <p/>
  2984. * If the frame is specified by a number, the command will switch to the frame
  2985. * by its (zero-based) index into the {@code window.frames} collection.
  2986. * <p/>
  2987. * If the frame is specified by a string, the command will select the frame by
  2988. * its name or ID. To select sub-frames, simply separate the frame names/IDs by
  2989. * dots. As an example, "main.child" will select the frame with the name "main"
  2990. * and then its child "child".
  2991. * <p/>
  2992. * If the specified frame can not be found, the deferred result will errback
  2993. * with a {@code bot.ErrorCode.NO_SUCH_FRAME} error.
  2994. * @param {string|number} nameOrIndex The frame locator.
  2995. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  2996. * driver has changed focus to the specified frame.
  2997. */
  2998. frame(nameOrIndex: string): webdriver.promise.Promise<void>;
  2999. frame(nameOrIndex: number): webdriver.promise.Promise<void>;
  3000. /**
  3001. * Schedules a command to switch the focus of all future commands to another
  3002. * window. Windows may be specified by their {@code window.name} attribute or
  3003. * by its handle (as returned by {@code webdriver.WebDriver#getWindowHandles}).
  3004. * <p/>
  3005. * If the specificed window can not be found, the deferred result will errback
  3006. * with a {@code bot.ErrorCode.NO_SUCH_WINDOW} error.
  3007. * @param {string} nameOrHandle The name or window handle of the window to
  3008. * switch focus to.
  3009. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  3010. * driver has changed focus to the specified window.
  3011. */
  3012. window(nameOrHandle: string): webdriver.promise.Promise<void>;
  3013. /**
  3014. * Schedules a command to change focus to the active alert dialog. This command
  3015. * will return a {@link bot.ErrorCode.NO_MODAL_DIALOG_OPEN} error if a modal
  3016. * dialog is not currently open.
  3017. * @return {!webdriver.Alert} The open alert.
  3018. */
  3019. alert(): AlertPromise;
  3020. //endregion
  3021. }
  3022. /**
  3023. * Creates a new WebDriver client, which provides control over a browser.
  3024. *
  3025. * Every WebDriver command returns a {@code webdriver.promise.Promise} that
  3026. * represents the result of that command. Callbacks may be registered on this
  3027. * object to manipulate the command result or catch an expected error. Any
  3028. * commands scheduled with a callback are considered sub-commands and will
  3029. * execute before the next command in the current frame. For example:
  3030. *
  3031. * var message = [];
  3032. * driver.call(message.push, message, 'a').then(function() {
  3033. * driver.call(message.push, message, 'b');
  3034. * });
  3035. * driver.call(message.push, message, 'c');
  3036. * driver.call(function() {
  3037. * alert('message is abc? ' + (message.join('') == 'abc'));
  3038. * });
  3039. *
  3040. */
  3041. class WebDriver {
  3042. //region Constructors
  3043. /**
  3044. * @param {!(webdriver.Session|webdriver.promise.Promise)} session Either a
  3045. * known session or a promise that will be resolved to a session.
  3046. * @param {!webdriver.CommandExecutor} executor The executor to use when
  3047. * sending commands to the browser.
  3048. * @param {webdriver.promise.ControlFlow=} opt_flow The flow to
  3049. * schedule commands through. Defaults to the active flow object.
  3050. * @constructor
  3051. */
  3052. constructor(session: Session, executor: CommandExecutor, opt_flow?: webdriver.promise.ControlFlow);
  3053. constructor(session: webdriver.promise.Promise<Session>, executor: CommandExecutor, opt_flow?: webdriver.promise.ControlFlow);
  3054. //endregion
  3055. //region Static Properties
  3056. static Navigation: WebDriverNavigation;
  3057. static Options: WebDriverOptions;
  3058. static Timeouts: WebDriverTimeouts;
  3059. static Window: WebDriverWindow;
  3060. static Logs: WebDriverLogs;
  3061. static TargetLocator: WebDriverTargetLocator;
  3062. //endregion
  3063. //region StaticMethods
  3064. /**
  3065. * Creates a new WebDriver client for an existing session.
  3066. * @param {!webdriver.CommandExecutor} executor Command executor to use when
  3067. * querying for session details.
  3068. * @param {string} sessionId ID of the session to attach to.
  3069. * @param {webdriver.promise.ControlFlow=} opt_flow The control flow all driver
  3070. * commands should execute under. Defaults to the
  3071. * {@link webdriver.promise.controlFlow() currently active} control flow.
  3072. * @return {!webdriver.WebDriver} A new client for the specified session.
  3073. */
  3074. static attachToSession(executor: CommandExecutor, sessionId: string, opt_flow?: webdriver.promise.ControlFlow): WebDriver;
  3075. /**
  3076. * Creates a new WebDriver session.
  3077. * @param {!webdriver.CommandExecutor} executor The executor to create the new
  3078. * session with.
  3079. * @param {!webdriver.Capabilities} desiredCapabilities The desired
  3080. * capabilities for the new session.
  3081. * @param {webdriver.promise.ControlFlow=} opt_flow The control flow all driver
  3082. * commands should execute under, including the initial session creation.
  3083. * Defaults to the {@link webdriver.promise.controlFlow() currently active}
  3084. * control flow.
  3085. * @return {!webdriver.WebDriver} The driver for the newly created session.
  3086. */
  3087. static createSession(executor: CommandExecutor, desiredCapabilities: Capabilities, opt_flow?: webdriver.promise.ControlFlow): WebDriver;
  3088. //endregion
  3089. //region Methods
  3090. /**
  3091. * @return {!webdriver.promise.ControlFlow} The control flow used by this
  3092. * instance.
  3093. */
  3094. controlFlow(): webdriver.promise.ControlFlow;
  3095. /**
  3096. * Schedules a {@code webdriver.Command} to be executed by this driver's
  3097. * {@code webdriver.CommandExecutor}.
  3098. * @param {!webdriver.Command} command The command to schedule.
  3099. * @param {string} description A description of the command for debugging.
  3100. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  3101. * the command result.
  3102. */
  3103. schedule<T>(command: Command, description: string): webdriver.promise.Promise<T>;
  3104. /**
  3105. * @return {!webdriver.promise.Promise} A promise for this client's session.
  3106. */
  3107. getSession(): webdriver.promise.Promise<Session>;
  3108. /**
  3109. * @return {!webdriver.promise.Promise} A promise that will resolve with the
  3110. * this instance's capabilities.
  3111. */
  3112. getCapabilities(): webdriver.promise.Promise<Capabilities>;
  3113. /**
  3114. * Schedules a command to quit the current session. After calling quit, this
  3115. * instance will be invalidated and may no longer be used to issue commands
  3116. * against the browser.
  3117. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  3118. * the command has completed.
  3119. */
  3120. quit(): webdriver.promise.Promise<void>;
  3121. /**
  3122. * Creates a new action sequence using this driver. The sequence will not be
  3123. * scheduled for execution until {@link webdriver.ActionSequence#perform} is
  3124. * called. Example:
  3125. * <pre><code>
  3126. * driver.actions().
  3127. * mouseDown(element1).
  3128. * mouseMove(element2).
  3129. * mouseUp().
  3130. * perform();
  3131. * </code></pre>
  3132. * @return {!webdriver.ActionSequence} A new action sequence for this instance.
  3133. */
  3134. actions(): ActionSequence;
  3135. /**
  3136. * Schedules a command to execute JavaScript in the context of the currently
  3137. * selected frame or window. The script fragment will be executed as the body
  3138. * of an anonymous function. If the script is provided as a function object,
  3139. * that function will be converted to a string for injection into the target
  3140. * window.
  3141. *
  3142. * Any arguments provided in addition to the script will be included as script
  3143. * arguments and may be referenced using the {@code arguments} object.
  3144. * Arguments may be a boolean, number, string, or {@code webdriver.WebElement}.
  3145. * Arrays and objects may also be used as script arguments as long as each item
  3146. * adheres to the types previously mentioned.
  3147. *
  3148. * The script may refer to any variables accessible from the current window.
  3149. * Furthermore, the script will execute in the window's context, thus
  3150. * {@code document} may be used to refer to the current document. Any local
  3151. * variables will not be available once the script has finished executing,
  3152. * though global variables will persist.
  3153. *
  3154. * If the script has a return value (i.e. if the script contains a return
  3155. * statement), then the following steps will be taken for resolving this
  3156. * functions return value:
  3157. * <ul>
  3158. * <li>For a HTML element, the value will resolve to a
  3159. * {@code webdriver.WebElement}</li>
  3160. * <li>Null and undefined return values will resolve to null</li>
  3161. * <li>Booleans, numbers, and strings will resolve as is</li>
  3162. * <li>Functions will resolve to their string representation</li>
  3163. * <li>For arrays and objects, each member item will be converted according to
  3164. * the rules above</li>
  3165. * </ul>
  3166. *
  3167. * @param {!(string|Function)} script The script to execute.
  3168. * @param {...*} var_args The arguments to pass to the script.
  3169. * @return {!webdriver.promise.Promise} A promise that will resolve to the
  3170. * scripts return value.
  3171. */
  3172. executeScript<T>(script: string, ...var_args: any[]): webdriver.promise.Promise<T>;
  3173. executeScript<T>(script: Function, ...var_args: any[]): webdriver.promise.Promise<T>;
  3174. /**
  3175. * Schedules a command to execute asynchronous JavaScript in the context of the
  3176. * currently selected frame or window. The script fragment will be executed as
  3177. * the body of an anonymous function. If the script is provided as a function
  3178. * object, that function will be converted to a string for injection into the
  3179. * target window.
  3180. *
  3181. * Any arguments provided in addition to the script will be included as script
  3182. * arguments and may be referenced using the {@code arguments} object.
  3183. * Arguments may be a boolean, number, string, or {@code webdriver.WebElement}.
  3184. * Arrays and objects may also be used as script arguments as long as each item
  3185. * adheres to the types previously mentioned.
  3186. *
  3187. * Unlike executing synchronous JavaScript with
  3188. * {@code webdriver.WebDriver.prototype.executeScript}, scripts executed with
  3189. * this function must explicitly signal they are finished by invoking the
  3190. * provided callback. This callback will always be injected into the
  3191. * executed function as the last argument, and thus may be referenced with
  3192. * {@code arguments[arguments.length - 1]}. The following steps will be taken
  3193. * for resolving this functions return value against the first argument to the
  3194. * script's callback function:
  3195. * <ul>
  3196. * <li>For a HTML element, the value will resolve to a
  3197. * {@code webdriver.WebElement}</li>
  3198. * <li>Null and undefined return values will resolve to null</li>
  3199. * <li>Booleans, numbers, and strings will resolve as is</li>
  3200. * <li>Functions will resolve to their string representation</li>
  3201. * <li>For arrays and objects, each member item will be converted according to
  3202. * the rules above</li>
  3203. * </ul>
  3204. *
  3205. * Example #1: Performing a sleep that is synchronized with the currently
  3206. * selected window:
  3207. * <code><pre>
  3208. * var start = new Date().getTime();
  3209. * driver.executeAsyncScript(
  3210. * 'window.setTimeout(arguments[arguments.length - 1], 500);').
  3211. * then(function() {
  3212. * console.log('Elapsed time: ' + (new Date().getTime() - start) + ' ms');
  3213. * });
  3214. * </pre></code>
  3215. *
  3216. * Example #2: Synchronizing a test with an AJAX application:
  3217. * <code><pre>
  3218. * var button = driver.findElement(By.id('compose-button'));
  3219. * button.click();
  3220. * driver.executeAsyncScript(
  3221. * 'var callback = arguments[arguments.length - 1];' +
  3222. * 'mailClient.getComposeWindowWidget().onload(callback);');
  3223. * driver.switchTo().frame('composeWidget');
  3224. * driver.findElement(By.id('to')).sendKEys('dog@example.com');
  3225. * </pre></code>
  3226. *
  3227. * Example #3: Injecting a XMLHttpRequest and waiting for the result. In this
  3228. * example, the inject script is specified with a function literal. When using
  3229. * this format, the function is converted to a string for injection, so it
  3230. * should not reference any symbols not defined in the scope of the page under
  3231. * test.
  3232. * <code><pre>
  3233. * driver.executeAsyncScript(function() {
  3234. * var callback = arguments[arguments.length - 1];
  3235. * var xhr = new XMLHttpRequest();
  3236. * xhr.open("GET", "/resource/data.json", true);
  3237. * xhr.onreadystatechange = function() {
  3238. * if (xhr.readyState == 4) {
  3239. * callback(xhr.resposneText);
  3240. * }
  3241. * }
  3242. * xhr.send('');
  3243. * }).then(function(str) {
  3244. * console.log(JSON.parse(str)['food']);
  3245. * });
  3246. * </pre></code>
  3247. *
  3248. * @param {!(string|Function)} script The script to execute.
  3249. * @param {...*} var_args The arguments to pass to the script.
  3250. * @return {!webdriver.promise.Promise} A promise that will resolve to the
  3251. * scripts return value.
  3252. */
  3253. executeAsyncScript<T>(script: string, ...var_args: any[]): webdriver.promise.Promise<T>;
  3254. executeAsyncScript<T>(script: Function, ...var_args: any[]): webdriver.promise.Promise<T>;
  3255. /**
  3256. * Schedules a command to execute a custom function.
  3257. * @param {!Function} fn The function to execute.
  3258. * @param {Object=} opt_scope The object in whose scope to execute the function.
  3259. * @param {...*} var_args Any arguments to pass to the function.
  3260. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3261. * function's result.
  3262. */
  3263. call<T>(fn: Function, opt_scope?: any, ...var_args: any[]): webdriver.promise.Promise<T>;
  3264. /**
  3265. * Schedules a command to wait for a condition to hold, as defined by some
  3266. * user supplied function. If any errors occur while evaluating the wait, they
  3267. * will be allowed to propagate.
  3268. *
  3269. * <p>In the event a condition returns a {@link webdriver.promise.Promise}, the
  3270. * polling loop will wait for it to be resolved and use the resolved value for
  3271. * evaluating whether the condition has been satisfied. The resolution time for
  3272. * a promise is factored into whether a wait has timed out.
  3273. *
  3274. * @param {!(webdriver.until.Condition.<T>|
  3275. * function(!webdriver.WebDriver): T)} condition Either a condition
  3276. * object, or a function to evaluate as a condition.
  3277. * @param {number} timeout How long to wait for the condition to be true.
  3278. * @param {string=} opt_message An optional message to use if the wait times
  3279. * out.
  3280. * @return {!webdriver.promise.Promise.<T>} A promise that will be fulfilled
  3281. * with the first truthy value returned by the condition function, or
  3282. * rejected if the condition times out.
  3283. * @template T
  3284. */
  3285. wait<T>(condition: webdriver.until.Condition<T>, timeout: number, opt_message?: string): webdriver.promise.Promise<T>;
  3286. wait<T>(condition: (webdriver: WebDriver) => any, timeout: number, opt_message?: string): webdriver.promise.Promise<T>;
  3287. /**
  3288. * Schedules a command to make the driver sleep for the given amount of time.
  3289. * @param {number} ms The amount of time, in milliseconds, to sleep.
  3290. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  3291. * sleep has finished.
  3292. */
  3293. sleep(ms: number): webdriver.promise.Promise<void>;
  3294. /**
  3295. * Schedules a command to retrieve they current window handle.
  3296. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3297. * current window handle.
  3298. */
  3299. getWindowHandle(): webdriver.promise.Promise<string>;
  3300. /**
  3301. * Schedules a command to retrieve the current list of available window handles.
  3302. * @return {!webdriver.promise.Promise} A promise that will be resolved with an
  3303. * array of window handles.
  3304. */
  3305. getAllWindowHandles(): webdriver.promise.Promise<string[]>;
  3306. /**
  3307. * Schedules a command to retrieve the current page's source. The page source
  3308. * returned is a representation of the underlying DOM: do not expect it to be
  3309. * formatted or escaped in the same way as the response sent from the web
  3310. * server.
  3311. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3312. * current page source.
  3313. */
  3314. getPageSource(): webdriver.promise.Promise<string>;
  3315. /**
  3316. * Schedules a command to close the current window.
  3317. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  3318. * this command has completed.
  3319. */
  3320. close(): webdriver.promise.Promise<void>;
  3321. /**
  3322. * Schedules a command to navigate to the given URL.
  3323. * @param {string} url The fully qualified URL to open.
  3324. * @return {!webdriver.promise.Promise} A promise that will be resolved when the
  3325. * document has finished loading.
  3326. */
  3327. get(url: string): webdriver.promise.Promise<void>;
  3328. /**
  3329. * Schedules a command to retrieve the URL of the current page.
  3330. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3331. * current URL.
  3332. */
  3333. getCurrentUrl(): webdriver.promise.Promise<string>;
  3334. /**
  3335. * Schedules a command to retrieve the current page's title.
  3336. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3337. * current page's title.
  3338. */
  3339. getTitle(): webdriver.promise.Promise<string>;
  3340. /**
  3341. * Schedule a command to find an element on the page. If the element cannot be
  3342. * found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will be returned
  3343. * by the driver. Unlike other commands, this error cannot be suppressed. In
  3344. * other words, scheduling a command to find an element doubles as an assert
  3345. * that the element is present on the page. To test whether an element is
  3346. * present on the page, use {@code #isElementPresent} instead.
  3347. *
  3348. * <p>The search criteria for find an element may either be a
  3349. * {@code webdriver.Locator} object, or a simple JSON object whose sole key
  3350. * is one of the accepted locator strategies, as defined by
  3351. * {@code webdriver.Locator.Strategy}. For example, the following two statements
  3352. * are equivalent:
  3353. * <code><pre>
  3354. * var e1 = driver.findElement(By.id('foo'));
  3355. * var e2 = driver.findElement({id:'foo'});
  3356. * </pre></code>
  3357. *
  3358. * <p>When running in the browser, a WebDriver cannot manipulate DOM elements
  3359. * directly; it may do so only through a {@link webdriver.WebElement} reference.
  3360. * This function may be used to generate a WebElement from a DOM element. A
  3361. * reference to the DOM element will be stored in a known location and this
  3362. * driver will attempt to retrieve it through {@link #executeScript}. If the
  3363. * element cannot be found (eg, it belongs to a different document than the
  3364. * one this instance is currently focused on), a
  3365. * {@link bot.ErrorCode.NO_SUCH_ELEMENT} error will be returned.
  3366. *
  3367. * @param {!(webdriver.Locator|Object.<string>|Element)} locatorOrElement The
  3368. * locator strategy to use when searching for the element, or the actual
  3369. * DOM element to be located by the server.
  3370. * @param {...} var_args Arguments to pass to {@code #executeScript} if using a
  3371. * JavaScript locator. Otherwise ignored.
  3372. * @return {!webdriver.WebElement} A WebElement that can be used to issue
  3373. * commands against the located element. If the element is not found, the
  3374. * element will be invalidated and all scheduled commands aborted.
  3375. */
  3376. findElement(locatorOrElement: Locator, ...var_args: any[]): WebElementPromise;
  3377. findElement(locatorOrElement: any, ...var_args: any[]): WebElementPromise;
  3378. /**
  3379. * Schedules a command to test if an element is present on the page.
  3380. *
  3381. * <p>If given a DOM element, this function will check if it belongs to the
  3382. * document the driver is currently focused on. Otherwise, the function will
  3383. * test if at least one element can be found with the given search criteria.
  3384. *
  3385. * @param {!(webdriver.Locator|Object.<string>|Element)} locatorOrElement The
  3386. * locator strategy to use when searching for the element, or the actual
  3387. * DOM element to be located by the server.
  3388. * @param {...} var_args Arguments to pass to {@code #executeScript} if using a
  3389. * JavaScript locator. Otherwise ignored.
  3390. * @return {!webdriver.promise.Promise} A promise that will resolve to whether
  3391. * the element is present on the page.
  3392. */
  3393. isElementPresent(locatorOrElement: Locator, ...var_args: any[]): webdriver.promise.Promise<boolean>;
  3394. isElementPresent(locatorOrElement: any, ...var_args: any[]): webdriver.promise.Promise<boolean>;
  3395. /**
  3396. * Schedule a command to search for multiple elements on the page.
  3397. *
  3398. * @param {webdriver.Locator|Object.<string>} locator The locator
  3399. * strategy to use when searching for the element.
  3400. * @param {...} var_args Arguments to pass to {@code #executeScript} if using a
  3401. * JavaScript locator. Otherwise ignored.
  3402. * @return {!webdriver.promise.Promise} A promise that will be resolved to an
  3403. * array of the located {@link webdriver.WebElement}s.
  3404. */
  3405. findElements(locator: Locator, ...var_args: any[]): webdriver.promise.Promise<WebElement[]>;
  3406. findElements(locator: any, ...var_args: any[]): webdriver.promise.Promise<WebElement[]>;
  3407. /**
  3408. * Schedule a command to take a screenshot. The driver makes a best effort to
  3409. * return a screenshot of the following, in order of preference:
  3410. * <ol>
  3411. * <li>Entire page
  3412. * <li>Current window
  3413. * <li>Visible portion of the current frame
  3414. * <li>The screenshot of the entire display containing the browser
  3415. * </ol>
  3416. *
  3417. * @return {!webdriver.promise.Promise} A promise that will be resolved to the
  3418. * screenshot as a base-64 encoded PNG.
  3419. */
  3420. takeScreenshot(): webdriver.promise.Promise<string>;
  3421. /**
  3422. * @return {!webdriver.WebDriver.Options} The options interface for this
  3423. * instance.
  3424. */
  3425. manage(): WebDriverOptions;
  3426. /**
  3427. * @return {!webdriver.WebDriver.Navigation} The navigation interface for this
  3428. * instance.
  3429. */
  3430. navigate(): WebDriverNavigation;
  3431. /**
  3432. * @return {!webdriver.WebDriver.TargetLocator} The target locator interface for
  3433. * this instance.
  3434. */
  3435. switchTo(): WebDriverTargetLocator;
  3436. //endregion
  3437. }
  3438. interface IWebElementId {
  3439. ELEMENT: string;
  3440. }
  3441. /**
  3442. * Represents a DOM element. WebElements can be found by searching from the
  3443. * document root using a {@code webdriver.WebDriver} instance, or by searching
  3444. * under another {@code webdriver.WebElement}:
  3445. * <pre><code>
  3446. * driver.get('http://www.google.com');
  3447. * var searchForm = driver.findElement(By.tagName('form'));
  3448. * var searchBox = searchForm.findElement(By.name('q'));
  3449. * searchBox.sendKeys('webdriver');
  3450. * </code></pre>
  3451. *
  3452. * The WebElement is implemented as a promise for compatibility with the promise
  3453. * API. It will always resolve itself when its internal state has been fully
  3454. * resolved and commands may be issued against the element. This can be used to
  3455. * catch errors when an element cannot be located on the page:
  3456. * <pre><code>
  3457. * driver.findElement(By.id('not-there')).then(function(element) {
  3458. * alert('Found an element that was not expected to be there!');
  3459. * }, function(error) {
  3460. * alert('The element was not found, as expected');
  3461. * });
  3462. * </code></pre>
  3463. */
  3464. interface IWebElement {
  3465. //region Methods
  3466. /**
  3467. * Schedules a command to click on this element.
  3468. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  3469. * the click command has completed.
  3470. */
  3471. click(): webdriver.promise.Promise<void>;
  3472. /**
  3473. * Schedules a command to type a sequence on the DOM element represented by this
  3474. * instance.
  3475. * <p/>
  3476. * Modifier keys (SHIFT, CONTROL, ALT, META) are stateful; once a modifier is
  3477. * processed in the keysequence, that key state is toggled until one of the
  3478. * following occurs:
  3479. * <ul>
  3480. * <li>The modifier key is encountered again in the sequence. At this point the
  3481. * state of the key is toggled (along with the appropriate keyup/down events).
  3482. * </li>
  3483. * <li>The {@code webdriver.Key.NULL} key is encountered in the sequence. When
  3484. * this key is encountered, all modifier keys current in the down state are
  3485. * released (with accompanying keyup events). The NULL key can be used to
  3486. * simulate common keyboard shortcuts:
  3487. * <code>
  3488. * element.sendKeys("text was",
  3489. * webdriver.Key.CONTROL, "a", webdriver.Key.NULL,
  3490. * "now text is");
  3491. * // Alternatively:
  3492. * element.sendKeys("text was",
  3493. * webdriver.Key.chord(webdriver.Key.CONTROL, "a"),
  3494. * "now text is");
  3495. * </code></li>
  3496. * <li>The end of the keysequence is encountered. When there are no more keys
  3497. * to type, all depressed modifier keys are released (with accompanying keyup
  3498. * events).
  3499. * </li>
  3500. * </ul>
  3501. * <strong>Note:</strong> On browsers where native keyboard events are not yet
  3502. * supported (e.g. Firefox on OS X), key events will be synthesized. Special
  3503. * punctionation keys will be synthesized according to a standard QWERTY en-us
  3504. * keyboard layout.
  3505. *
  3506. * @param {...string} var_args The sequence of keys to
  3507. * type. All arguments will be joined into a single sequence (var_args is
  3508. * permitted for convenience).
  3509. * @return {!webdriver.promise.Promise} A promise that will be resolved when all
  3510. * keys have been typed.
  3511. */
  3512. sendKeys(...var_args: string[]): webdriver.promise.Promise<void>;
  3513. /**
  3514. * Schedules a command to query for the tag/node name of this element.
  3515. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3516. * element's tag name.
  3517. */
  3518. getTagName(): webdriver.promise.Promise<string>;
  3519. /**
  3520. * Schedules a command to query for the computed style of the element
  3521. * represented by this instance. If the element inherits the named style from
  3522. * its parent, the parent will be queried for its value. Where possible, color
  3523. * values will be converted to their hex representation (e.g. #00ff00 instead of
  3524. * rgb(0, 255, 0)).
  3525. * <p/>
  3526. * <em>Warning:</em> the value returned will be as the browser interprets it, so
  3527. * it may be tricky to form a proper assertion.
  3528. *
  3529. * @param {string} cssStyleProperty The name of the CSS style property to look
  3530. * up.
  3531. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3532. * requested CSS value.
  3533. */
  3534. getCssValue(cssStyleProperty: string): webdriver.promise.Promise<string>;
  3535. /**
  3536. * Schedules a command to query for the value of the given attribute of the
  3537. * element. Will return the current value even if it has been modified after the
  3538. * page has been loaded. More exactly, this method will return the value of the
  3539. * given attribute, unless that attribute is not present, in which case the
  3540. * value of the property with the same name is returned. If neither value is
  3541. * set, null is returned. The "style" attribute is converted as best can be to a
  3542. * text representation with a trailing semi-colon. The following are deemed to
  3543. * be "boolean" attributes and will be returned as thus:
  3544. *
  3545. * <p>async, autofocus, autoplay, checked, compact, complete, controls, declare,
  3546. * defaultchecked, defaultselected, defer, disabled, draggable, ended,
  3547. * formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope,
  3548. * loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open,
  3549. * paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
  3550. * selected, spellcheck, truespeed, willvalidate
  3551. *
  3552. * <p>Finally, the following commonly mis-capitalized attribute/property names
  3553. * are evaluated as expected:
  3554. * <ul>
  3555. * <li>"class"
  3556. * <li>"readonly"
  3557. * </ul>
  3558. * @param {string} attributeName The name of the attribute to query.
  3559. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3560. * attribute's value.
  3561. */
  3562. getAttribute(attributeName: string): webdriver.promise.Promise<string>;
  3563. /**
  3564. * Get the visible (i.e. not hidden by CSS) innerText of this element, including
  3565. * sub-elements, without any leading or trailing whitespace.
  3566. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3567. * element's visible text.
  3568. */
  3569. getText(): webdriver.promise.Promise<string>;
  3570. /**
  3571. * Schedules a command to compute the size of this element's bounding box, in
  3572. * pixels.
  3573. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3574. * element's size as a {@code {width:number, height:number}} object.
  3575. */
  3576. getSize(): webdriver.promise.Promise<ISize>;
  3577. /**
  3578. * Schedules a command to compute the location of this element in page space.
  3579. * @return {!webdriver.promise.Promise} A promise that will be resolved to the
  3580. * element's location as a {@code {x:number, y:number}} object.
  3581. */
  3582. getLocation(): webdriver.promise.Promise<ILocation>;
  3583. /**
  3584. * Schedules a command to query whether the DOM element represented by this
  3585. * instance is enabled, as dicted by the {@code disabled} attribute.
  3586. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  3587. * whether this element is currently enabled.
  3588. */
  3589. isEnabled(): webdriver.promise.Promise<boolean>;
  3590. /**
  3591. * Schedules a command to query whether this element is selected.
  3592. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  3593. * whether this element is currently selected.
  3594. */
  3595. isSelected(): webdriver.promise.Promise<boolean>;
  3596. /**
  3597. * Schedules a command to submit the form containing this element (or this
  3598. * element if it is a FORM element). This command is a no-op if the element is
  3599. * not contained in a form.
  3600. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  3601. * the form has been submitted.
  3602. */
  3603. submit(): webdriver.promise.Promise<void>;
  3604. /**
  3605. * Schedules a command to clear the {@code value} of this element. This command
  3606. * has no effect if the underlying DOM element is neither a text INPUT element
  3607. * nor a TEXTAREA element.
  3608. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  3609. * the element has been cleared.
  3610. */
  3611. clear(): webdriver.promise.Promise<void>;
  3612. /**
  3613. * Schedules a command to test whether this element is currently displayed.
  3614. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  3615. * whether this element is currently visible on the page.
  3616. */
  3617. isDisplayed(): webdriver.promise.Promise<boolean>;
  3618. /**
  3619. * Schedules a command to retrieve the outer HTML of this element.
  3620. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  3621. * the element's outer HTML.
  3622. */
  3623. getOuterHtml(): webdriver.promise.Promise<string>;
  3624. /**
  3625. * @return {!webdriver.promise.Promise.<webdriver.WebElement.Id>} A promise
  3626. * that resolves to this element's JSON representation as defined by the
  3627. * WebDriver wire protocol.
  3628. * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol
  3629. */
  3630. getId(): webdriver.promise.Promise<IWebElementId>
  3631. /**
  3632. * Schedules a command to retrieve the inner HTML of this element.
  3633. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3634. * element's inner HTML.
  3635. */
  3636. getInnerHtml(): webdriver.promise.Promise<string>;
  3637. //endregion
  3638. }
  3639. interface IWebElementFinders {
  3640. /**
  3641. * Schedule a command to find a descendant of this element. If the element
  3642. * cannot be found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will
  3643. * be returned by the driver. Unlike other commands, this error cannot be
  3644. * suppressed. In other words, scheduling a command to find an element doubles
  3645. * as an assert that the element is present on the page. To test whether an
  3646. * element is present on the page, use {@code #isElementPresent} instead.
  3647. *
  3648. * <p>The search criteria for an element may be defined using one of the
  3649. * factories in the {@link webdriver.By} namespace, or as a short-hand
  3650. * {@link webdriver.By.Hash} object. For example, the following two statements
  3651. * are equivalent:
  3652. * <code><pre>
  3653. * var e1 = element.findElement(By.id('foo'));
  3654. * var e2 = element.findElement({id:'foo'});
  3655. * </pre></code>
  3656. *
  3657. * <p>You may also provide a custom locator function, which takes as input
  3658. * this WebDriver instance and returns a {@link webdriver.WebElement}, or a
  3659. * promise that will resolve to a WebElement. For example, to find the first
  3660. * visible link on a page, you could write:
  3661. * <code><pre>
  3662. * var link = element.findElement(firstVisibleLink);
  3663. *
  3664. * function firstVisibleLink(element) {
  3665. * var links = element.findElements(By.tagName('a'));
  3666. * return webdriver.promise.filter(links, function(link) {
  3667. * return links.isDisplayed();
  3668. * }).then(function(visibleLinks) {
  3669. * return visibleLinks[0];
  3670. * });
  3671. * }
  3672. * </pre></code>
  3673. *
  3674. * @param {!(webdriver.Locator|webdriver.By.Hash|Function)} locator The
  3675. * locator strategy to use when searching for the element.
  3676. * @return {!webdriver.WebElement} A WebElement that can be used to issue
  3677. * commands against the located element. If the element is not found, the
  3678. * element will be invalidated and all scheduled commands aborted.
  3679. */
  3680. findElement(locator: Locator): WebElementPromise;
  3681. findElement(locator: any): WebElementPromise;
  3682. /**
  3683. * Schedules a command to test if there is at least one descendant of this
  3684. * element that matches the given search criteria.
  3685. *
  3686. * @param {!(webdriver.Locator|webdriver.By.Hash|Function)} locator The
  3687. * locator strategy to use when searching for the element.
  3688. * @return {!webdriver.promise.Promise.<boolean>} A promise that will be
  3689. * resolved with whether an element could be located on the page.
  3690. */
  3691. isElementPresent(locator: Locator): webdriver.promise.Promise<boolean>;
  3692. isElementPresent(locator: any): webdriver.promise.Promise<boolean>;
  3693. /**
  3694. * Schedules a command to find all of the descendants of this element that
  3695. * match the given search criteria.
  3696. *
  3697. * @param {!(webdriver.Locator|webdriver.By.Hash|Function)} locator The
  3698. * locator strategy to use when searching for the elements.
  3699. * @return {!webdriver.promise.Promise.<!Array.<!webdriver.WebElement>>} A
  3700. * promise that will resolve to an array of WebElements.
  3701. */
  3702. findElements(locator: Locator): webdriver.promise.Promise<WebElement[]>;
  3703. findElements(locator: any): webdriver.promise.Promise<WebElement[]>;
  3704. }
  3705. class WebElement implements IWebElement, IWebElementFinders {
  3706. //region Constructors
  3707. /**
  3708. * @param {!webdriver.WebDriver} driver The parent WebDriver instance for this
  3709. * element.
  3710. * @param {!(webdriver.promise.Promise.<webdriver.WebElement.Id>|
  3711. * webdriver.WebElement.Id)} id The server-assigned opaque ID for the
  3712. * underlying DOM element.
  3713. * @constructor
  3714. */
  3715. constructor(driver: WebDriver, id: webdriver.promise.Promise<IWebElementId>);
  3716. constructor(driver: WebDriver, id: IWebElementId);
  3717. //endregion
  3718. //region Static Properties
  3719. /**
  3720. * The property key used in the wire protocol to indicate that a JSON object
  3721. * contains the ID of a WebElement.
  3722. * @type {string}
  3723. * @const
  3724. */
  3725. static ELEMENT_KEY: string;
  3726. //endregion
  3727. //region Methods
  3728. /**
  3729. * @return {!webdriver.WebDriver} The parent driver for this instance.
  3730. */
  3731. getDriver(): WebDriver;
  3732. /**
  3733. * Schedule a command to find a descendant of this element. If the element
  3734. * cannot be found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will
  3735. * be returned by the driver. Unlike other commands, this error cannot be
  3736. * suppressed. In other words, scheduling a command to find an element doubles
  3737. * as an assert that the element is present on the page. To test whether an
  3738. * element is present on the page, use {@code #isElementPresent} instead.
  3739. *
  3740. * <p>The search criteria for an element may be defined using one of the
  3741. * factories in the {@link webdriver.By} namespace, or as a short-hand
  3742. * {@link webdriver.By.Hash} object. For example, the following two statements
  3743. * are equivalent:
  3744. * <code><pre>
  3745. * var e1 = element.findElement(By.id('foo'));
  3746. * var e2 = element.findElement({id:'foo'});
  3747. * </pre></code>
  3748. *
  3749. * <p>You may also provide a custom locator function, which takes as input
  3750. * this WebDriver instance and returns a {@link webdriver.WebElement}, or a
  3751. * promise that will resolve to a WebElement. For example, to find the first
  3752. * visible link on a page, you could write:
  3753. * <code><pre>
  3754. * var link = element.findElement(firstVisibleLink);
  3755. *
  3756. * function firstVisibleLink(element) {
  3757. * var links = element.findElements(By.tagName('a'));
  3758. * return webdriver.promise.filter(links, function(link) {
  3759. * return links.isDisplayed();
  3760. * }).then(function(visibleLinks) {
  3761. * return visibleLinks[0];
  3762. * });
  3763. * }
  3764. * </pre></code>
  3765. *
  3766. * @param {!(webdriver.Locator|webdriver.By.Hash|Function)} locator The
  3767. * locator strategy to use when searching for the element.
  3768. * @return {!webdriver.WebElement} A WebElement that can be used to issue
  3769. * commands against the located element. If the element is not found, the
  3770. * element will be invalidated and all scheduled commands aborted.
  3771. */
  3772. findElement(locator: Locator): WebElementPromise;
  3773. findElement(locator: any): WebElementPromise;
  3774. /**
  3775. * Schedules a command to test if there is at least one descendant of this
  3776. * element that matches the given search criteria.
  3777. *
  3778. * @param {!(webdriver.Locator|webdriver.By.Hash|Function)} locator The
  3779. * locator strategy to use when searching for the element.
  3780. * @return {!webdriver.promise.Promise.<boolean>} A promise that will be
  3781. * resolved with whether an element could be located on the page.
  3782. */
  3783. isElementPresent(locator: Locator): webdriver.promise.Promise<boolean>;
  3784. isElementPresent(locator: any): webdriver.promise.Promise<boolean>;
  3785. /**
  3786. * Schedules a command to find all of the descendants of this element that
  3787. * match the given search criteria.
  3788. *
  3789. * @param {!(webdriver.Locator|webdriver.By.Hash|Function)} locator The
  3790. * locator strategy to use when searching for the elements.
  3791. * @return {!webdriver.promise.Promise.<!Array.<!webdriver.WebElement>>} A
  3792. * promise that will resolve to an array of WebElements.
  3793. */
  3794. findElements(locator: Locator): webdriver.promise.Promise<WebElement[]>;
  3795. findElements(locator: any): webdriver.promise.Promise<WebElement[]>;
  3796. /**
  3797. * Schedules a command to click on this element.
  3798. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  3799. * the click command has completed.
  3800. */
  3801. click(): webdriver.promise.Promise<void>;
  3802. /**
  3803. * Schedules a command to type a sequence on the DOM element represented by this
  3804. * instance.
  3805. * <p/>
  3806. * Modifier keys (SHIFT, CONTROL, ALT, META) are stateful; once a modifier is
  3807. * processed in the keysequence, that key state is toggled until one of the
  3808. * following occurs:
  3809. * <ul>
  3810. * <li>The modifier key is encountered again in the sequence. At this point the
  3811. * state of the key is toggled (along with the appropriate keyup/down events).
  3812. * </li>
  3813. * <li>The {@code webdriver.Key.NULL} key is encountered in the sequence. When
  3814. * this key is encountered, all modifier keys current in the down state are
  3815. * released (with accompanying keyup events). The NULL key can be used to
  3816. * simulate common keyboard shortcuts:
  3817. * <code>
  3818. * element.sendKeys("text was",
  3819. * webdriver.Key.CONTROL, "a", webdriver.Key.NULL,
  3820. * "now text is");
  3821. * // Alternatively:
  3822. * element.sendKeys("text was",
  3823. * webdriver.Key.chord(webdriver.Key.CONTROL, "a"),
  3824. * "now text is");
  3825. * </code></li>
  3826. * <li>The end of the keysequence is encountered. When there are no more keys
  3827. * to type, all depressed modifier keys are released (with accompanying keyup
  3828. * events).
  3829. * </li>
  3830. * </ul>
  3831. * <strong>Note:</strong> On browsers where native keyboard events are not yet
  3832. * supported (e.g. Firefox on OS X), key events will be synthesized. Special
  3833. * punctionation keys will be synthesized according to a standard QWERTY en-us
  3834. * keyboard layout.
  3835. *
  3836. * @param {...string} var_args The sequence of keys to
  3837. * type. All arguments will be joined into a single sequence (var_args is
  3838. * permitted for convenience).
  3839. * @return {!webdriver.promise.Promise} A promise that will be resolved when all
  3840. * keys have been typed.
  3841. */
  3842. sendKeys(...var_args: string[]): webdriver.promise.Promise<void>;
  3843. /**
  3844. * Schedules a command to query for the tag/node name of this element.
  3845. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3846. * element's tag name.
  3847. */
  3848. getTagName(): webdriver.promise.Promise<string>;
  3849. /**
  3850. * Schedules a command to query for the computed style of the element
  3851. * represented by this instance. If the element inherits the named style from
  3852. * its parent, the parent will be queried for its value. Where possible, color
  3853. * values will be converted to their hex representation (e.g. #00ff00 instead of
  3854. * rgb(0, 255, 0)).
  3855. * <p/>
  3856. * <em>Warning:</em> the value returned will be as the browser interprets it, so
  3857. * it may be tricky to form a proper assertion.
  3858. *
  3859. * @param {string} cssStyleProperty The name of the CSS style property to look
  3860. * up.
  3861. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3862. * requested CSS value.
  3863. */
  3864. getCssValue(cssStyleProperty: string): webdriver.promise.Promise<string>;
  3865. /**
  3866. * Schedules a command to query for the value of the given attribute of the
  3867. * element. Will return the current value even if it has been modified after the
  3868. * page has been loaded. More exactly, this method will return the value of the
  3869. * given attribute, unless that attribute is not present, in which case the
  3870. * value of the property with the same name is returned. If neither value is
  3871. * set, null is returned. The "style" attribute is converted as best can be to a
  3872. * text representation with a trailing semi-colon. The following are deemed to
  3873. * be "boolean" attributes and will be returned as thus:
  3874. *
  3875. * <p>async, autofocus, autoplay, checked, compact, complete, controls, declare,
  3876. * defaultchecked, defaultselected, defer, disabled, draggable, ended,
  3877. * formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope,
  3878. * loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open,
  3879. * paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
  3880. * selected, spellcheck, truespeed, willvalidate
  3881. *
  3882. * <p>Finally, the following commonly mis-capitalized attribute/property names
  3883. * are evaluated as expected:
  3884. * <ul>
  3885. * <li>"class"
  3886. * <li>"readonly"
  3887. * </ul>
  3888. * @param {string} attributeName The name of the attribute to query.
  3889. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3890. * attribute's value.
  3891. */
  3892. getAttribute(attributeName: string): webdriver.promise.Promise<string>;
  3893. /**
  3894. * Get the visible (i.e. not hidden by CSS) innerText of this element, including
  3895. * sub-elements, without any leading or trailing whitespace.
  3896. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3897. * element's visible text.
  3898. */
  3899. getText(): webdriver.promise.Promise<string>;
  3900. /**
  3901. * Schedules a command to compute the size of this element's bounding box, in
  3902. * pixels.
  3903. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3904. * element's size as a {@code {width:number, height:number}} object.
  3905. */
  3906. getSize(): webdriver.promise.Promise<ISize>;
  3907. /**
  3908. * Schedules a command to compute the location of this element in page space.
  3909. * @return {!webdriver.promise.Promise} A promise that will be resolved to the
  3910. * element's location as a {@code {x:number, y:number}} object.
  3911. */
  3912. getLocation(): webdriver.promise.Promise<ILocation>;
  3913. /**
  3914. * Schedules a command to query whether the DOM element represented by this
  3915. * instance is enabled, as dicted by the {@code disabled} attribute.
  3916. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  3917. * whether this element is currently enabled.
  3918. */
  3919. isEnabled(): webdriver.promise.Promise<boolean>;
  3920. /**
  3921. * Schedules a command to query whether this element is selected.
  3922. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  3923. * whether this element is currently selected.
  3924. */
  3925. isSelected(): webdriver.promise.Promise<boolean>;
  3926. /**
  3927. * Schedules a command to submit the form containing this element (or this
  3928. * element if it is a FORM element). This command is a no-op if the element is
  3929. * not contained in a form.
  3930. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  3931. * the form has been submitted.
  3932. */
  3933. submit(): webdriver.promise.Promise<void>;
  3934. /**
  3935. * Schedules a command to clear the {@code value} of this element. This command
  3936. * has no effect if the underlying DOM element is neither a text INPUT element
  3937. * nor a TEXTAREA element.
  3938. * @return {!webdriver.promise.Promise} A promise that will be resolved when
  3939. * the element has been cleared.
  3940. */
  3941. clear(): webdriver.promise.Promise<void>;
  3942. /**
  3943. * Schedules a command to test whether this element is currently displayed.
  3944. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  3945. * whether this element is currently visible on the page.
  3946. */
  3947. isDisplayed(): webdriver.promise.Promise<boolean>;
  3948. /**
  3949. * Schedules a command to retrieve the outer HTML of this element.
  3950. * @return {!webdriver.promise.Promise} A promise that will be resolved with
  3951. * the element's outer HTML.
  3952. */
  3953. getOuterHtml(): webdriver.promise.Promise<string>;
  3954. /**
  3955. * @return {!webdriver.promise.Promise.<webdriver.WebElement.Id>} A promise
  3956. * that resolves to this element's JSON representation as defined by the
  3957. * WebDriver wire protocol.
  3958. * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol
  3959. */
  3960. getId(): webdriver.promise.Promise<IWebElementId>;
  3961. /**
  3962. * Schedules a command to retrieve the inner HTML of this element.
  3963. * @return {!webdriver.promise.Promise} A promise that will be resolved with the
  3964. * element's inner HTML.
  3965. */
  3966. getInnerHtml(): webdriver.promise.Promise<string>;
  3967. //endregion
  3968. //region Static Methods
  3969. /**
  3970. * Compares to WebElements for equality.
  3971. * @param {!webdriver.WebElement} a A WebElement.
  3972. * @param {!webdriver.WebElement} b A WebElement.
  3973. * @return {!webdriver.promise.Promise} A promise that will be resolved to
  3974. * whether the two WebElements are equal.
  3975. */
  3976. static equals(a: WebElement, b: WebElement): webdriver.promise.Promise<boolean>;
  3977. //endregion
  3978. }
  3979. /**
  3980. * WebElementPromise is a promise that will be fulfilled with a WebElement.
  3981. * This serves as a forward proxy on WebElement, allowing calls to be
  3982. * scheduled without directly on this instance before the underlying
  3983. * WebElement has been fulfilled. In other words, the following two statements
  3984. * are equivalent:
  3985. * <pre><code>
  3986. * driver.findElement({id: 'my-button'}).click();
  3987. * driver.findElement({id: 'my-button'}).then(function(el) {
  3988. * return el.click();
  3989. * });
  3990. * </code></pre>
  3991. *
  3992. * @param {!webdriver.WebDriver} driver The parent WebDriver instance for this
  3993. * element.
  3994. * @param {!webdriver.promise.Promise.<!webdriver.WebElement>} el A promise
  3995. * that will resolve to the promised element.
  3996. * @constructor
  3997. * @extends {webdriver.WebElement}
  3998. * @implements {webdriver.promise.Thenable.<!webdriver.WebElement>}
  3999. * @final
  4000. */
  4001. class WebElementPromise extends WebElement implements webdriver.promise.IThenable<WebElement> {
  4002. /**
  4003. * Cancels the computation of this promise's value, rejecting the promise in the
  4004. * process. This method is a no-op if the promise has alreayd been resolved.
  4005. *
  4006. * @param {string=} opt_reason The reason this promise is being cancelled.
  4007. */
  4008. cancel(opt_reason?: string): void;
  4009. /** @return {boolean} Whether this promise's value is still being computed. */
  4010. isPending(): boolean;
  4011. /**
  4012. * Registers listeners for when this instance is resolved.
  4013. *
  4014. * @param opt_callback The
  4015. * function to call if this promise is successfully resolved. The function
  4016. * should expect a single argument: the promise's resolved value.
  4017. * @param opt_errback The
  4018. * function to call if this promise is rejected. The function should expect
  4019. * a single argument: the rejection reason.
  4020. * @return A new promise which will be
  4021. * resolved with the result of the invoked callback.
  4022. */
  4023. then<R>(opt_callback?: (value: WebElement) => webdriver.promise.Promise<R>, opt_errback?: (error: any) => any): webdriver.promise.Promise<R>;
  4024. /**
  4025. * Registers listeners for when this instance is resolved.
  4026. *
  4027. * @param opt_callback The
  4028. * function to call if this promise is successfully resolved. The function
  4029. * should expect a single argument: the promise's resolved value.
  4030. * @param opt_errback The
  4031. * function to call if this promise is rejected. The function should expect
  4032. * a single argument: the rejection reason.
  4033. * @return A new promise which will be
  4034. * resolved with the result of the invoked callback.
  4035. */
  4036. then<R>(opt_callback?: (value: WebElement) => R, opt_errback?: (error: any) => any): webdriver.promise.Promise<R>;
  4037. /**
  4038. * Registers a listener for when this promise is rejected. This is synonymous
  4039. * with the {@code catch} clause in a synchronous API:
  4040. * <pre><code>
  4041. * // Synchronous API:
  4042. * try {
  4043. * doSynchronousWork();
  4044. * } catch (ex) {
  4045. * console.error(ex);
  4046. * }
  4047. *
  4048. * // Asynchronous promise API:
  4049. * doAsynchronousWork().thenCatch(function(ex) {
  4050. * console.error(ex);
  4051. * });
  4052. * </code></pre>
  4053. *
  4054. * @param {function(*): (R|webdriver.promise.Promise.<R>)} errback The function
  4055. * to call if this promise is rejected. The function should expect a single
  4056. * argument: the rejection reason.
  4057. * @return {!webdriver.promise.Promise.<R>} A new promise which will be
  4058. * resolved with the result of the invoked callback.
  4059. * @template R
  4060. */
  4061. thenCatch<R>(errback: (error: any) => any): webdriver.promise.Promise<R>;
  4062. /**
  4063. * Registers a listener to invoke when this promise is resolved, regardless
  4064. * of whether the promise's value was successfully computed. This function
  4065. * is synonymous with the {@code finally} clause in a synchronous API:
  4066. * <pre><code>
  4067. * // Synchronous API:
  4068. * try {
  4069. * doSynchronousWork();
  4070. * } finally {
  4071. * cleanUp();
  4072. * }
  4073. *
  4074. * // Asynchronous promise API:
  4075. * doAsynchronousWork().thenFinally(cleanUp);
  4076. * </code></pre>
  4077. *
  4078. * <b>Note:</b> similar to the {@code finally} clause, if the registered
  4079. * callback returns a rejected promise or throws an error, it will silently
  4080. * replace the rejection error (if any) from this promise:
  4081. * <pre><code>
  4082. * try {
  4083. * throw Error('one');
  4084. * } finally {
  4085. * throw Error('two'); // Hides Error: one
  4086. * }
  4087. *
  4088. * webdriver.promise.rejected(Error('one'))
  4089. * .thenFinally(function() {
  4090. * throw Error('two'); // Hides Error: one
  4091. * });
  4092. * </code></pre>
  4093. *
  4094. *
  4095. * @param {function(): (R|webdriver.promise.Promise.<R>)} callback The function
  4096. * to call when this promise is resolved.
  4097. * @return {!webdriver.promise.Promise.<R>} A promise that will be fulfilled
  4098. * with the callback result.
  4099. * @template R
  4100. */
  4101. thenFinally<R>(callback: () => any): webdriver.promise.Promise<R>;
  4102. }
  4103. interface ILocatorStrategy {
  4104. className(value: string): Locator;
  4105. css(value: string): Locator;
  4106. id(value: string): Locator;
  4107. js(script: any, ...var_args: any[]): (WebDriver: webdriver.WebDriver) => webdriver.promise.Promise<any>;
  4108. linkText(value: string): Locator;
  4109. name(value: string): Locator;
  4110. partialLinkText(value: string): Locator;
  4111. tagName(value: string): Locator;
  4112. xpath(value: string): Locator;
  4113. }
  4114. var By: ILocatorStrategy;
  4115. /**
  4116. * An element locator.
  4117. */
  4118. interface Locator {
  4119. //region Properties
  4120. /**
  4121. * The search strategy to use when searching for an element.
  4122. * @type {string}
  4123. */
  4124. using: string;
  4125. /**
  4126. * The search target for this locator.
  4127. * @type {string}
  4128. */
  4129. value: string;
  4130. //endregion
  4131. //region Methods
  4132. /** @return {string} String representation of this locator. */
  4133. toString(): string;
  4134. //endregion
  4135. }
  4136. /**
  4137. * Contains information about a WebDriver session.
  4138. */
  4139. class Session {
  4140. //region Constructors
  4141. /**
  4142. * @param {string} id The session ID.
  4143. * @param {!(Object|webdriver.Capabilities)} capabilities The session
  4144. * capabilities.
  4145. * @constructor
  4146. */
  4147. constructor(id: string, capabilities: Capabilities);
  4148. constructor(id: string, capabilities: any);
  4149. //endregion
  4150. //region Methods
  4151. /**
  4152. * @return {string} This session's ID.
  4153. */
  4154. getId(): string;
  4155. /**
  4156. * @return {!webdriver.Capabilities} This session's capabilities.
  4157. */
  4158. getCapabilities(): Capabilities;
  4159. /**
  4160. * Retrieves the value of a specific capability.
  4161. * @param {string} key The capability to retrieve.
  4162. * @return {*} The capability value.
  4163. */
  4164. getCapability(key: string): any;
  4165. /**
  4166. * Returns the JSON representation of this object, which is just the string
  4167. * session ID.
  4168. * @return {string} The JSON representation of this Session.
  4169. */
  4170. toJSON(): string;
  4171. //endregion
  4172. }
  4173. }
  4174. declare module testing {
  4175. /**
  4176. * Registers a new test suite.
  4177. * @param name The suite name.
  4178. * @param fn The suite function, or {@code undefined} to define a pending test suite.
  4179. */
  4180. function describe(name: string, fn: Function): void;
  4181. /**
  4182. * Defines a suppressed test suite.
  4183. * @param name The suite name.
  4184. * @param fn The suite function, or {@code undefined} to define a pending test suite.
  4185. */
  4186. function xdescribe(name: string, fn: Function): void;
  4187. /**
  4188. * Register a function to call after the current suite finishes.
  4189. * @param fn
  4190. */
  4191. function after(fn: Function): void;
  4192. /**
  4193. * Register a function to call after each test in a suite.
  4194. * @param fn
  4195. */
  4196. function afterEach(fn: Function): void;
  4197. /**
  4198. * Register a function to call before the current suite starts.
  4199. * @param fn
  4200. */
  4201. function before(fn: Function): void;
  4202. /**
  4203. * Register a function to call before each test in a suite.
  4204. * @param fn
  4205. */
  4206. function beforeEach(fn: Function): void;
  4207. /**
  4208. * Add a test to the current suite.
  4209. * @param name The test name.
  4210. * @param fn The test function, or {@code undefined} to define a pending test case.
  4211. */
  4212. function it(name: string, fn: Function): void;
  4213. /**
  4214. * An alias for {@link #it()} that flags the test as the only one that should
  4215. * be run within the current suite.
  4216. * @param name The test name.
  4217. * @param fn The test function, or {@code undefined} to define a pending test case.
  4218. */
  4219. function iit(name: string, fn: Function): void;
  4220. /**
  4221. * Adds a test to the current suite while suppressing it so it is not run.
  4222. * @param name The test name.
  4223. * @param fn The test function, or {@code undefined} to define a pending test case.
  4224. */
  4225. function xit(name: string, fn: Function): void;
  4226. }
  4227. declare module 'selenium-webdriver/chrome' {
  4228. export = chrome;
  4229. }
  4230. declare module 'selenium-webdriver/firefox' {
  4231. export = firefox;
  4232. }
  4233. declare module 'selenium-webdriver/executors' {
  4234. export = executors;
  4235. }
  4236. declare module 'selenium-webdriver' {
  4237. export = webdriver;
  4238. }
  4239. declare module 'selenium-webdriver/testing' {
  4240. export = testing;
  4241. }