PageRenderTime 77ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/test/sahi/htdocs/spr/concat3.js

https://bitbucket.org/josselin_beaumont/music-spaces
JavaScript | 3116 lines | 2871 code | 61 blank | 184 comment | 756 complexity | 291afc3ebf7783a3b7b9900c44d2c2de MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0, JSON, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. /**
  2. * Sahi - Web Automation and Test Tool
  3. *
  4. * Copyright 2006 V Narayan Raman
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. String.isBlankOrNull = function (s) {
  19. return (s == "" || s == null);
  20. };
  21. var Sahi = function(){
  22. this.cmds = new Array();
  23. this.cmdDebugInfo = new Array();
  24. this.cmdsLocal = new Array();
  25. this.cmdDebugInfoLocal = new Array();
  26. this.waitInterval = -1;
  27. this.promptReturnValue = new Array();
  28. this.waitCondition = null;
  29. this.locals = [];
  30. this.INTERVAL = 100;
  31. this.ONERROR_INTERVAL = 1000;
  32. this.MAX_RETRIES = 5;
  33. this.SAHI_MAX_WAIT_FOR_LOAD = 30;
  34. this.waitForLoad = this.SAHI_MAX_WAIT_FOR_LOAD;
  35. this.interval = this.INTERVAL;
  36. this.localIx = 0;
  37. this.buffer = "";
  38. this.controller = null;
  39. this.lastAccessedInfo = null;
  40. this.execSteps = null; // from SahiScript through script.js
  41. this.sahiBuffer = "";
  42. this.real_alert = window.alert;
  43. this.real_confirm = window.confirm;
  44. this.real_prompt = window.prompt;
  45. this.real_print = window.print;
  46. this.wrapped = new Array();
  47. this.mockDialogs();
  48. this.XHRs = [];
  49. this.escapeMap = {
  50. '\b': '\\b',
  51. '\t': '\\t',
  52. '\n': '\\n',
  53. '\f': '\\f',
  54. '\r': '\\r',
  55. '"' : '\\"',
  56. '\\': '\\\\'
  57. };
  58. this.lastStepId = 0;
  59. this.diagnostics = new Object();
  60. this.storeDiagnostics();
  61. this.strictVisibilityCheck = false;
  62. this.ADs = [];
  63. this.lastBrowserMessageId = null;
  64. this._isRecording = false;
  65. this.NORMAL_LISTEN_INTERVAL = 1500;
  66. this.unreachableCount = 0;
  67. this.IDLE_LISTEN_INTERVAL = 4000;
  68. this.listenInterval = this.NORMAL_LISTEN_INTERVAL;
  69. this.activeCount = 0;
  70. };
  71. Sahi.prototype.relisten = function(){
  72. this.activeCount = 0;
  73. if (this.listenTimeoutId) window.clearTimeout(this.listenTimeoutId);
  74. this.listen();
  75. };
  76. Sahi.prototype.listen = function(){
  77. try{
  78. var msg = this.getMessageForBrowser();
  79. }catch(e){
  80. this.unreachableCount++;
  81. this.listenInterval = this.listenInterval*2;
  82. if (this.unreachableCount > 5) return;
  83. return window.setTimeout("_sahi.listen()", this.listenInterval);
  84. }
  85. this.listenInterval = this.NORMAL_LISTEN_INTERVAL;
  86. if (msg != null && msg != "null" && msg.id != this.lastBrowserMessageId){
  87. this.lastBrowserMessageId = msg.id;
  88. var res = null;
  89. try{
  90. var cmd = msg.command;
  91. if (cmd != null && cmd != ""){
  92. eval(cmd);
  93. }
  94. }catch (e){
  95. }
  96. }else{
  97. if (this.activeCount > 20){
  98. this.listenInterval = this.IDLE_LISTEN_INTERVAL;
  99. }else this.activeCount++;
  100. }
  101. this.listenTimeoutId = window.setTimeout("_sahi.listen()", this.listenInterval);
  102. };
  103. Sahi.prototype.getMessageForBrowser = function(){
  104. var url = "/_s_/dyn/Messages_getMessageForBrowser?windowName="+this.getPopupName();
  105. return eval("("+this.sendToServer(url, false, true)+")");
  106. };
  107. Sahi.prototype.processMessage = function(s){
  108. s = this.addSahi(s);
  109. this.setServerVar("sahiEvaluateExpr", true);
  110. try{
  111. this.top().eval(s);
  112. }catch(e){}
  113. this.setServerVar("sahiEvaluateExpr", false);
  114. };
  115. Sahi.prototype.sendToController = function(message, mode){
  116. this.setServerVarAsync("CONTROLLER_MessageForController", {mode:mode, message:message});
  117. };
  118. Sahi.prototype.sendIdsToController = function(elInfo, mode){
  119. var identifiers = elInfo.apis;
  120. var windowName = this.getPopupName();
  121. var s = "";
  122. if (identifiers == null || identifiers.length == 0) {
  123. s = {accessor: null, alternatives: [], windowName: windowName, value: null, script: null, mode: mode};
  124. } else {
  125. var id0 = identifiers[0];
  126. var value = this.escapeValue(id0.value);
  127. var accessors = [];
  128. for ( var i = 0; i < identifiers.length; i++) {
  129. accessors[i] = this.escapeDollar(this.getAccessor1(identifiers[i]));
  130. }
  131. var script = this.getScript(id0);
  132. s = {accessor: accessors[0], alternatives: accessors, windowName: windowName, value: value, script: script, mode: mode, assertions: elInfo.assertions};
  133. }
  134. // this.getController()._c.processMessage(s);
  135. this.setServerVarAsync("CONTROLLER_MessageForController", s);
  136. };
  137. Sahi.prototype.getAssertions = function(accs, info){
  138. var a = ["_assertExists(<accessor>)"];
  139. for (var k=0; k<accs.length; k++){
  140. var acc = accs[k];
  141. if (acc.assertions)
  142. a = a.concat(acc.assertions(info.value));
  143. }
  144. if (info.valueType == "sahiText"){
  145. a[a.length] = "_assertEqual(<value>, _getText(<accessor>))";
  146. a[a.length] = "_assertContainsText(<value>, <accessor>)";
  147. } else if (info.valueType == "value"){
  148. a[a.length] = "_assertEqual(<value>, <accessor>.value)";
  149. }
  150. return a;
  151. };
  152. Sahi.prototype.sendResultToController = function(result){
  153. this.setServerVar("CONTROLLER_MessageForController", {result: result});
  154. };
  155. Sahi.prototype.storeDiagnostics = function(){
  156. var d = this.diagnostics;
  157. d["UserAgent"] = navigator.userAgent;
  158. d["Native XMLHttpRequest"] = typeof XMLHttpRequest != "undefined";
  159. };
  160. Sahi.prototype.printDiagnostics = function(){
  161. var s = this.getDiagnostics();
  162. this._debug(s);
  163. return s;
  164. };
  165. Sahi.prototype.getDiagnostics = function(){
  166. var s = "";
  167. for (var key in this.diagnostics){
  168. s += key +": "+ this.diagnostics[key]+"\n";
  169. }
  170. return s;
  171. };
  172. Sahi.prototype.wrap = function (fn) {
  173. var el = this;
  174. if (this.wrapped[fn] == null) {
  175. this.wrapped[fn] = function(){fn.apply(el, arguments);};
  176. }
  177. return this.wrapped[fn];
  178. };
  179. Sahi.prototype.alertMock = function (s) {
  180. if (this.isPlaying()) {
  181. this.setServerVar("lastAlertText", s);
  182. return null;
  183. } else {
  184. return this._alert(s);
  185. }
  186. };
  187. Sahi.prototype.confirmMock = function (s) {
  188. if (this.isPlaying()) {
  189. var retVal = eval(this.getServerVar("confirm: "+s));
  190. if (retVal == null) retVal = true;
  191. this.setServerVar("lastConfirmText", s);
  192. this.setServerVar("confirm: "+s, null);
  193. return retVal;
  194. } else {
  195. var retVal = this.callFunction(this.real_confirm, window, s);
  196. if (this.isRecording()){
  197. this.recordStep("_expectConfirm(\"" + s + "\", " + retVal + ")");
  198. // this.sendToServer('/_s_/dyn/Recorder_record?cmd=' + encodeURIComponent("_expectConfirm(\"" + s + "\", " + retVal + ")"));
  199. }
  200. return retVal;
  201. }
  202. };
  203. Sahi.prototype.promptMock = function (s) {
  204. if (this.isPlaying()) {
  205. var retVal = this.getServerVar("prompt: "+s);//this.promptReturnValue[s];
  206. if (retVal == null) retVal = "";
  207. this.setServerVar("lastPromptText", s);
  208. this.setServerVar("prompt: "+s, null);
  209. return retVal;
  210. } else {
  211. var retVal = this.callFunction(this.real_prompt, window, s);
  212. this.recordStep("_expectPrompt(\"" + s + "\", \"" + retVal + "\")");
  213. // this.sendToServer('/_s_/dyn/Recorder_record?cmd=' + encodeURIComponent("_expectPrompt(\"" + s + "\", \"" + retVal + "\")"));
  214. return retVal;
  215. }
  216. };
  217. Sahi.prototype.printMock = function () {
  218. if (this.isPlaying()) {
  219. this.setServerVar("printCalled", true);
  220. return null;
  221. } else {
  222. return this.callFunction(this.real_print, window);
  223. }
  224. };
  225. Sahi.prototype.mockDialogs = function (e) {
  226. window.alert = this.wrap(this.alertMock);
  227. window.confirm = this.wrap(this.confirmMock);
  228. window.prompt = this.wrap(this.promptMock);
  229. window.print = this.wrap(this.printMock);
  230. };
  231. //_sahi.mockDialogs();
  232. var _sahi = new Sahi();
  233. var tried = false;
  234. var _sahi_top = window.top;
  235. Sahi.prototype.top = function () {
  236. //Hack for frames named "top"
  237. try{
  238. var x = _sahi_top.location.href; // test
  239. return _sahi_top;
  240. }catch(e){
  241. var p = window;
  242. while (p != p.parent){
  243. try{
  244. var y = p.parent.location.href; // test
  245. p = p.parent;
  246. }catch(e){
  247. return p;
  248. }
  249. }
  250. return p;
  251. }
  252. };
  253. Sahi.prototype.getKnownTags = function (src) {
  254. return src;
  255. var el = src;
  256. while (true) {
  257. if (!el) return src;
  258. if (!el.tagName || el.tagName.toLowerCase() == "html" || el.tagName.toLowerCase() == "body") return null;
  259. var tag = el.tagName.toLowerCase();
  260. if (tag == "a" || tag == "select" || tag == "img" || tag == "form"
  261. || tag == "input" || tag == "button" || tag == "textarea"
  262. || tag == "textarea" || tag == "td" || tag == "table"
  263. || ((tag == "div" || tag == "span")) || tag == "label" || tag == "li" ) return el;
  264. el = el.parentNode;
  265. }
  266. };
  267. var linkClick = function (e) {
  268. if (!e) e = window.event;
  269. var performDefault = true;
  270. if (this.prevClick) {
  271. performDefault = this.prevClick.apply(this, arguments);
  272. }
  273. //_sahi.real_alert(e);
  274. _sahi.lastLinkEvent = e;
  275. _sahi.lastLink = this;
  276. if (performDefault != false) {
  277. window.setTimeout(function(){_sahi.navigateLink()}, 10);
  278. } else {
  279. return false;
  280. }
  281. };
  282. Sahi.prototype._dragDrop = function (draggable, droppable) {
  283. this.checkNull(draggable, "_dragDrop", 1, "draggable");
  284. this.checkNull(droppable, "_dragDrop", 2, "droppable");
  285. var pos = this.findPos(droppable);
  286. var x = pos[0];
  287. var y = pos[1];
  288. this._dragDropXY(draggable, x, y);
  289. };
  290. Sahi.prototype.addBorder = function(el){
  291. el.style.border = "1px solid red";
  292. };
  293. Sahi.prototype._dragDropXY = function (draggable, x, y, isRelative) {
  294. this.checkNull(draggable, "_dragDropXY", 1, "draggable");
  295. this.simulateMouseEvent(draggable, "mousemove");
  296. this.simulateMouseEvent(draggable, "mousedown");
  297. this.simulateMouseEvent(draggable, "mousemove");
  298. var addX = 0, addY = 0;
  299. if (isRelative){
  300. var pos = this.findPos(draggable);
  301. addX = pos[0];
  302. addY = pos[1];
  303. if (!x) x = 0;
  304. if (!y) y = 0;
  305. x += addX;
  306. y += addY;
  307. }else{
  308. if (!x) x = this.findPos(draggable)[0];
  309. if (!y) y = this.findPos(draggable)[1];
  310. }
  311. this.simulateMouseEventXY(draggable, "mousemove", x, y);
  312. this.simulateMouseEventXY(draggable, "mouseup", x, y);
  313. this.simulateMouseEventXY(draggable, "click", x, y);
  314. this.simulateMouseEventXY(draggable, "mousemove", x, y);
  315. };
  316. Sahi.prototype.checkNull = function (el, fnName, paramPos, paramName) {
  317. if (el == null) {
  318. throw new Error("The " +
  319. (paramPos==1?"first ":paramPos==2?"second ":paramPos==3?"third ":"") +
  320. "parameter passed to " + fnName + " was not found on the browser");
  321. }
  322. };
  323. Sahi.prototype.checkVisible = function (el) {
  324. if (this.strictVisibilityCheck && !this._isVisible(el)) {
  325. throw "" + el + " is not visible";
  326. }
  327. };
  328. Sahi.prototype._isVisible = function (el) {
  329. try{
  330. if (el == null) return false;
  331. var elOrig = el;
  332. var display = true;
  333. while (true){
  334. display = display && this.isStyleDisplay(el);
  335. if (!display || el.parentNode == el || el.tagName == "BODY") break;
  336. el = el.parentNode;
  337. }
  338. el = elOrig;
  339. var visible = true;
  340. while (true){
  341. visible = visible && this.isStyleVisible(el);
  342. if (!visible || el.parentNode == el || el.tagName == "BODY") break;
  343. el = el.parentNode;
  344. }
  345. return display && visible;
  346. } catch(e){return true;}
  347. };
  348. Sahi.prototype.isStyleDisplay = function(el){
  349. var d = this._style(el, "display");
  350. return d==null || d != "none";
  351. };
  352. Sahi.prototype.isStyleVisible = function(el){
  353. var v = this._style(el, "visibility");
  354. return v==null || v != "hidden";
  355. };
  356. Sahi.prototype._click = function (el) {
  357. this.checkNull(el, "_click");
  358. this.checkVisible(el);
  359. this.simulateClick(el, false, false);
  360. };
  361. Sahi.prototype._doubleClick = function (el) {
  362. this.checkNull(el, "_doubleClick");
  363. this.checkVisible(el);
  364. this.simulateClick(el, false, true);
  365. };
  366. Sahi.prototype._rightClick = function (el) {
  367. this.checkNull(el, "_rightClick");
  368. this.checkVisible(el);
  369. this.simulateClick(el, true, false);
  370. };
  371. Sahi.prototype._mouseOver = function (el) {
  372. this.checkNull(el, "_mouseOver");
  373. this.checkVisible(el);
  374. this.simulateMouseEvent(el, "mousemove");
  375. this.simulateMouseEvent(el, "mouseover");
  376. };
  377. Sahi.prototype._keyPress = function (el, charCode, combo) {
  378. this.checkNull(el, "_keyPress", 1);
  379. this.checkVisible(el);
  380. if (typeof charCode == "string"){
  381. charCode = charCode.charCodeAt(0);
  382. }
  383. var c = String.fromCharCode(charCode);
  384. var prev = el.value;
  385. this.simulateMouseEvent(el, "focus");
  386. this.simulateKeyEvent(charCode, el, "keydown", combo);
  387. this.simulateKeyEvent(charCode, el, "keypress", combo);
  388. if (prev + c != el.value) {
  389. // if (!el.maxLength || el.value.length < el.maxLength)
  390. el.value = el.value + c;
  391. }
  392. this.simulateKeyEvent(charCode, el, "keyup", combo);
  393. };
  394. Sahi.prototype._focus = function (el) {
  395. this.simulateMouseEvent(el, "focus");
  396. };
  397. Sahi.prototype._keyDown = function (el, charCode, combo) {
  398. this.checkNull(el, "_keyDown", 1);
  399. this.checkVisible(el);
  400. this.simulateKeyEvent(charCode, el, "keydown", combo);
  401. };
  402. Sahi.prototype._keyUp = function (el, charCode, combo) {
  403. this.checkNull(el, "_keyUp", 1);
  404. this.checkVisible(el);
  405. this.simulateKeyEvent(charCode, el, "keyup", combo);
  406. };
  407. Sahi.prototype._readFile = function (fileName) {
  408. var qs = "fileName=" + fileName;
  409. return this._callServer("net.sf.sahi.plugin.FileReader_contents", qs);
  410. };
  411. Sahi.prototype._getDB = function (driver, jdbcurl, username, password) {
  412. return new Sahi.dB(driver, jdbcurl, username, password, this);
  413. };
  414. Sahi.dB = function (driver, jdbcurl, username, password, sahi) {
  415. this.driver = driver;
  416. this.jdbcurl = jdbcurl;
  417. this.username = username;
  418. this.password = password;
  419. this.select = function (sql) {
  420. var qs = "driver=" + this.driver + "&jdbcurl=" + this.jdbcurl + "&username=" + this.username + "&password=" + this.password + "&sql=" + sql;
  421. return eval(sahi._callServer("net.sf.sahi.plugin.DBClient_select", qs));
  422. };
  423. this.update = function (sql) {
  424. var qs = "driver=" + this.driver + "&jdbcurl=" + this.jdbcurl + "&username=" + this.username + "&password=" + this.password + "&sql=" + sql;
  425. return eval(sahi._callServer("net.sf.sahi.plugin.DBClient_execute", qs));
  426. };
  427. };
  428. Sahi.prototype.simulateClick = function (el, isRight, isDouble) {
  429. var n = el;
  430. if (this.isIE() && !isRight) {
  431. if (el && (el.tagName == "LABEL" || (el.type && (el.type == "submit" || el.type == "button"
  432. || el.type == "reset" || el.type == "image"
  433. || el.type == "checkbox" || el.type == "radio")))) {
  434. el.click();
  435. if (el.type && (el.type == "checkbox")){
  436. this.simulateChange(el);
  437. }
  438. return;
  439. }
  440. }
  441. var lastN = null;
  442. while (n != null && n != lastN) {
  443. if (n.tagName && n.tagName == "A") {
  444. n.prevClick = n.onclick;
  445. n.onclick = this.getWindow(el).linkClick;
  446. }
  447. lastN = n;
  448. n = n.parentNode;
  449. }
  450. this.simulateMouseEvent(el, "mousemove");
  451. this.simulateMouseEvent(el, "focus");
  452. this.simulateMouseEvent(el, "mouseover");
  453. this.simulateMouseEvent(el, "mousedown", isRight);
  454. this.simulateMouseEvent(el, "mouseup", isRight);
  455. if (isRight) {
  456. this.simulateMouseEvent(el, "contextmenu", isRight, isDouble);
  457. } else {
  458. try {
  459. this.simulateMouseEvent(el, "click", isRight, isDouble);
  460. if (this.isSafariLike()) {
  461. /*
  462. try {
  463. if (el.onclick) el.onclick();
  464. if (el.parentNode.tagName == "A") {
  465. el.parentNode.onclick();
  466. }
  467. } catch(ex) {
  468. this._debug(ex.message);
  469. }
  470. */
  471. if (el.tagName == "INPUT") {
  472. if (typeof el.checked == "boolean") {
  473. el.checked = (el.type == "radio") ? true : !el.checked;
  474. } /* else if (el.type == "submit") {
  475. var goOn = el.form.onsubmit();
  476. if (goOn != false) {
  477. el.form.submit();
  478. this.onBeforeUnLoad();
  479. }
  480. } */
  481. }
  482. }
  483. } catch(e) {
  484. }
  485. }
  486. this.simulateMouseEvent(el, "blur");
  487. n = el;
  488. lastN = null;
  489. while (n != null && n != lastN) {
  490. if (n.tagName && n.tagName == "A") {
  491. n.onclick = n.prevClick;
  492. }
  493. n = n.parentNode;
  494. }
  495. };
  496. Sahi.prototype.isSafariLike = function () {
  497. return /Konqueror|Safari|KHTML/.test(navigator.userAgent);
  498. };
  499. Sahi.prototype.simulateMouseEvent = function (el, type, isRight, isDouble) {
  500. var xy = this.findPos(el);
  501. var x = xy[0];
  502. var y = xy[1];
  503. this.simulateMouseEventXY(el, type, xy[0], xy[1], isRight, isDouble);
  504. };
  505. Sahi.prototype.simulateMouseEventXY = function (el, type, x, y, isRight, isDouble) {
  506. if (window.document.createEvent) {
  507. if (this.isSafariLike()) {
  508. var evt = el.ownerDocument.createEvent('HTMLEvents');
  509. evt.initEvent(type, true, true);
  510. el.dispatchEvent(evt);
  511. }
  512. else {
  513. // FF
  514. var evt = el.ownerDocument.createEvent("MouseEvents");
  515. evt.initMouseEvent(
  516. (isDouble ? "dbl" : "") + type,
  517. true, //can bubble
  518. true,
  519. el.ownerDocument.defaultView,
  520. (isDouble ? 2 : 1),
  521. x, //screen x
  522. y, //screen y
  523. x, //client x
  524. y, //client y
  525. false,
  526. false,
  527. false,
  528. false,
  529. isRight ? 2 : 0,
  530. null);
  531. el.dispatchEvent(evt);
  532. }
  533. } else {
  534. // IE
  535. var evt = el.ownerDocument.createEventObject();
  536. evt.clientX = x;
  537. evt.clientY = y;
  538. evt.button = isRight ? 2 : 1;
  539. el.fireEvent("on" + (isDouble ? "dbl" : "") + type, evt);
  540. evt.cancelBubble = true;
  541. }
  542. };
  543. Sahi.pointTimer = 0;
  544. Sahi.prototype._highlight = function (el) {
  545. var win = this.getWin(el);
  546. win.scrollTo(this.findPosX(el), this.findPosY(el) - 20);
  547. var oldBorder = el.style.border;
  548. el.style.border = "1px solid red";
  549. window.setTimeout(function(){el.style.border = oldBorder;}, 2000);
  550. };
  551. Sahi.prototype._position = function (el){
  552. return this.findPos(el);
  553. };
  554. Sahi.prototype.findPosX = function (obj){
  555. return this.findPos(obj)[0];
  556. };
  557. Sahi.prototype.findPosY = function (obj){
  558. return this.findPos(obj)[1];
  559. };
  560. Sahi.prototype.findPos = function (obj){
  561. var x = 0, y = 0;
  562. if (obj.offsetParent)
  563. {
  564. while (obj.offsetParent)
  565. {
  566. var wasStatic = null;
  567. /*
  568. if (this._style(obj, "position") == "static"){
  569. wasStatic = obj.style.position;
  570. obj.style.position = "relative";
  571. }
  572. */
  573. x += obj.offsetLeft;
  574. y += obj.offsetTop;
  575. if (wasStatic != null) obj.style.position = wasStatic;
  576. obj = obj.offsetParent;
  577. }
  578. }
  579. else if (obj.x){
  580. x = obj.x;
  581. y = obj.y;
  582. }
  583. return [x, y];
  584. };
  585. Sahi.prototype.getWindow = function(el){
  586. var win;
  587. if (this.isSafariLike()) {
  588. win = this.getWin(el);
  589. } else {
  590. win = el.ownerDocument.defaultView; //FF
  591. if (!win) win = el.ownerDocument.parentWindow; //IE
  592. }
  593. return win;
  594. };
  595. Sahi.prototype.navigateLink = function () {
  596. var ln = this.lastLink;
  597. if (!ln) return;
  598. if (this.lastLinkEvent.getPreventDefault) {
  599. if (this.lastLinkEvent.getPreventDefault()) return;
  600. }
  601. if ((this.isIE() || this.isSafariLike()) && this.lastLinkEvent.returnValue == false) return;
  602. var win = this.getWindow(ln);
  603. if (ln.href.indexOf("javascript:") == 0) {
  604. var s = ln.href.substring(11);
  605. win.setTimeout(unescape(s), 0);
  606. } else {
  607. var target = ln.target;
  608. if (ln.target == null || ln.target == "") target = "_self";
  609. if (this.isSafariLike()) {
  610. var targetWin = win.open("", target);
  611. try {
  612. targetWin._sahi.onBeforeUnLoad();
  613. } catch(e) {
  614. this._debug(e.message);
  615. }
  616. targetWin.location.href = ln.href;
  617. }
  618. else win.open(ln.href, target);
  619. }
  620. };
  621. Sahi.prototype.getClickEv = function (el) {
  622. var e = new Object();
  623. if (this.isIE()) el.srcElement = e;
  624. else e.target = el;
  625. e.stopPropagation = this.noop;
  626. return e;
  627. };
  628. Sahi.prototype.noop = function () {
  629. };
  630. // api for link click end
  631. Sahi.prototype._type = function (el, val) {
  632. for (var i = 0; i < val.length; i++) {
  633. var ccode = val.charAt(i).charCodeAt(0);
  634. this.simulateKeyEvent(ccode, el, "keydown");
  635. this.simulateKeyEvent(ccode, el, "keypress");
  636. this.simulateKeyEvent(ccode, el, "keyup");
  637. }
  638. };
  639. Sahi.prototype._setValue = function (el, val) {
  640. this.setValue(el, val);
  641. };
  642. // api for set value start
  643. Sahi.prototype.setValue = function (el, val) {
  644. this.checkNull(el, "_setValue", 1);
  645. this.checkVisible(el);
  646. val = "" + val;
  647. var prevVal = el.value;
  648. if (!window.document.createEvent) el.value = val;
  649. if (el.type && el.type.indexOf("select") != -1) {
  650. } else {
  651. var append = false;
  652. el.value = "";
  653. if (typeof val == "string") {
  654. for (var i = 0; i < val.length; i++) {
  655. var c = val.charAt(i);
  656. var ccode = c.charCodeAt(0);
  657. this.simulateKeyEvent(ccode, el, "keydown");
  658. this.simulateKeyEvent(ccode, el, "keypress");
  659. if (i == 0 && el.value != c) {
  660. append = true;
  661. }
  662. if (append) {
  663. //if (!el.maxLength || el.value.length < el.maxLength)
  664. el.value += c;
  665. }
  666. this.simulateKeyEvent(ccode, el, "keyup");
  667. }
  668. }
  669. }
  670. if (!this.isIE()) this.simulateEvent(el, "blur");
  671. if (prevVal != val) {
  672. if (!this.isFF3()) this.simulateEvent(el, "change");
  673. }
  674. if (this.isIE()) this.simulateEvent(el, "blur");
  675. if (el && el.form){
  676. try{
  677. this.simulateEvent(el.form, "change");
  678. }catch(e){}
  679. }
  680. };
  681. Sahi.prototype._setFile = function (el, v, url) {
  682. if (!url) url = (String.isBlankOrNull(el.form.action) || (typeof el.form.action != "string")) ? this.getWindow(el).location.href : el.form.action;
  683. if (url && (q = url.indexOf("?")) != -1) url = url.substring(0, q);
  684. if (url.indexOf("http") != 0) {
  685. var loc = window.location;
  686. if (url.indexOf("/") == 0){
  687. url = loc.protocol+ "//" + loc.hostname + (loc.port ? (':'+loc.port) : '') + url;
  688. }else{
  689. var winUrl = loc.href;
  690. url = winUrl.substring(0, winUrl.lastIndexOf ('/') + 1) + url;
  691. }
  692. }
  693. this._callServer("FileUpload_setFile", "n=" + el.name + "&v=" + encodeURIComponent(v) + "&action=" + encodeURIComponent(url));
  694. };
  695. Sahi.prototype.simulateEvent = function (target, evType) {
  696. if (window.document.createEvent) {
  697. var evt = new Object();
  698. evt.type = evType;
  699. evt.bubbles = true;
  700. evt.cancelable = true;
  701. if (!target) return;
  702. var event = target.ownerDocument.createEvent("HTMLEvents");
  703. event.initEvent(evt.type, evt.bubbles, evt.cancelable);
  704. target.dispatchEvent(event);
  705. } else {
  706. var evt = target.ownerDocument.createEventObject();
  707. evt.type = evType;
  708. evt.bubbles = true;
  709. evt.cancelable = true;
  710. evt.cancelBubble = true;
  711. target.fireEvent("on" + evType, evt);
  712. }
  713. };
  714. Sahi.prototype.simulateKeyEvent = function (charCode, target, evType, combo) {
  715. var c = String.fromCharCode(charCode);
  716. var isShift = combo == "SHIFT" || (charCode >= 65 && charCode <= 122 && c.toUpperCase() == c);
  717. if (window.document.createEvent) { // FF
  718. if (this.isSafariLike()) {
  719. var event = target.ownerDocument.createEvent('HTMLEvents');
  720. var evt = event;
  721. evt.bubbles = true;
  722. evt.cancelable = true;
  723. evt.ctrlKey = combo == "CTRL";
  724. evt.altKey = combo == "ALT";
  725. evt.metaKey = combo == "META";
  726. evt.charCode = charCode;
  727. evt.keyCode = charCode;
  728. evt.shiftKey = isShift;
  729. event.initEvent(evType, false, false);
  730. target.dispatchEvent(event);
  731. } else {
  732. var evt = new Object();
  733. evt.type = evType;
  734. evt.bubbles = true;
  735. evt.cancelable = true;
  736. evt.ctrlKey = combo == "CTRL";
  737. evt.altKey = combo == "ALT";
  738. evt.metaKey = combo == "META";
  739. if (charCode >= 31 && charCode <= 256){
  740. evt.charCode = charCode;
  741. evt.keyCode = 0;
  742. }else{
  743. evt.charCode = 0;
  744. evt.keyCode = charCode;
  745. }
  746. evt.shiftKey = isShift;
  747. if (!target) return;
  748. var event = target.ownerDocument.createEvent("KeyEvents");
  749. event.initKeyEvent(evt.type, evt.bubbles, evt.cancelable, target.ownerDocument.defaultView,
  750. evt.ctrlKey, evt.altKey, evt.shiftKey, evt.metaKey, evt.keyCode, evt.charCode);
  751. target.dispatchEvent(event);
  752. }
  753. } else {
  754. var evt = target.ownerDocument.createEventObject();
  755. evt.type = evType;
  756. evt.bubbles = true;
  757. evt.cancelable = true;
  758. var xy = this.findPos(target);
  759. evt.clientX = xy[0];
  760. evt.clientY = xy[1];
  761. evt.ctrlKey = combo == "CTRL";
  762. evt.altKey = combo == "ALT";
  763. evt.metaKey = combo == "META";
  764. evt.keyCode = charCode;
  765. evt.shiftKey = isShift; //c.toUpperCase().charCodeAt(0) == evt.charCode;
  766. evt.shiftLeft = isShift;
  767. evt.cancelBubble = true;
  768. target.fireEvent("on" + evType, evt);
  769. }
  770. };
  771. Sahi.prototype._setSelected = function (el, val, isMultiple) {
  772. var l = el.options.length;
  773. var optionEl = null;
  774. if (typeof val == "string" || val instanceof RegExp){
  775. for (var i = 0; i < l; i++) {
  776. if (this.areEqual(el.options[i], "text", val) ||
  777. this.areEqual(el.options[i], "id", val)) {
  778. optionEl = el.options[i];
  779. }
  780. }
  781. } else if (typeof val == "number" && el.options.length > val){
  782. optionEl = el.options[val];
  783. }
  784. if (!optionEl) throw new Error("Option not found: " + val);
  785. for (var i = 0; i < l; i++) {
  786. if (!isMultiple) el.options[i].selected = false;
  787. }
  788. optionEl.selected = true;
  789. this.simulateEvent(el, "change");
  790. };
  791. // api for set value end
  792. Sahi.prototype._check = function (el, val) {
  793. el.checked = val;
  794. if (el.onclick) el.onclick();
  795. };
  796. //Sahi.prototype._reset = function (n, inEl) {
  797. // var el = this.findElement(n, "reset", "input", inEl);
  798. // if (el == null) el = this.findElement(n, "reset", "button", inEl);
  799. // return el;
  800. //};
  801. //Sahi.prototype._submit = function (n, inEl) {
  802. // var el = this.findElement(n, "submit", "input", inEl);
  803. // if (el == null) el = this.findElement(n, "submit", "button", inEl);
  804. // return el;
  805. //};
  806. Sahi.prototype._wait = function (i, condn) {
  807. this.setServerVar("waitConditionTime", new Date().valueOf()+i);
  808. if (condn) {
  809. this.waitCondition = condn;
  810. this.setServerVar("waitCondition", condn);
  811. window.setTimeout("_sahi.cancelWaitCondition()", i);
  812. }
  813. else {
  814. window.setTimeout("_sahi.cancelWaitCondition()", i);
  815. this.waitInterval = i;
  816. }
  817. };
  818. Sahi.prototype.cancelWaitCondition = function (){
  819. this.waitCondition=null;
  820. this.waitInterval=this.INTERVAL;
  821. this.setServerVar("waitCondition", null);
  822. this.setServerVar("waitConditionTime", -1);
  823. };
  824. //Sahi.prototype._file = function (n, inEl) {
  825. // return this.findElement(n, "file", "input", inEl);
  826. //};
  827. //Sahi.prototype._password = function (n, inEl) {
  828. // return this.findElement(n, "password", "input", inEl);
  829. //};
  830. //Sahi.prototype._checkbox = function (n, inEl) {
  831. // return this.findElement(n, "checkbox", "input", inEl);
  832. //};
  833. //Sahi.prototype._textarea = function (n, inEl) {
  834. // return this.findElement(n, "textarea", "textarea", inEl);
  835. //};
  836. Sahi.prototype._hidden = function (n, inEl) {
  837. return this.findElement(n, "hidden", "input", inEl);
  838. };
  839. Sahi.prototype._accessor = function (n) {
  840. return eval(n);
  841. };
  842. Sahi.prototype._byId = function (id) {
  843. return this.findElementById(this.top(), id);
  844. };
  845. Sahi.prototype._byText = function (text, tag) {
  846. var res = this.getBlankResult();
  847. return this.tagByText(this.top(), text, tag, res).element;
  848. };
  849. Sahi.prototype._byClassName = function (className, tagName) {
  850. var res = this.getBlankResult();
  851. var el = this.findTagHelper(className, this.top(), tagName, res, "className").element;
  852. return el;
  853. };
  854. //Sahi.prototype._radio = function (n, inEl) {
  855. // return this.findElement(n, "radio", "input", inEl);
  856. //};
  857. //Sahi.prototype._div = function (id, inEl) {
  858. // return this.spandivcommon(id, inEl, "div");
  859. //};
  860. //Sahi.prototype._span = function (id, inEl) {
  861. // return this.spandivcommon(id, inEl, "span");
  862. //};
  863. //Sahi.prototype.spandivcommon = function (id, inEl, tagName) {
  864. // if (!inEl) inEl = this.top();
  865. // var res = this.getBlankResult();
  866. // var el = this.findTagHelper(id, inEl, tagName, res, "id").element;
  867. // if (el == null) el = this.tagByText(inEl, id, tagName, res).element;
  868. // return el;
  869. //};
  870. Sahi.prototype._spandiv = function (id, inEl) {
  871. if (!inEl) inEl = this.top();
  872. var el = this._span(id, inEl);
  873. if (el == null) el = this._div(id, inEl);
  874. return el;
  875. };
  876. //Sahi.prototype._listItem = function (id) {
  877. // var res = this.getBlankResult();
  878. // var el = this.findTagHelper(id, this.top(), "li", res, "id").element;
  879. // if (el == null) el = this.tagByText(this.top(), id, "li", res).element;
  880. // return el;
  881. //};
  882. //Sahi.prototype._label = function (id) {
  883. // var res = this.getBlankResult();
  884. // var el = this.findTagHelper(id, this.top(), "label", res, "id").element;
  885. // if (el == null) el = this.tagByText(this.top(), id, "label", res).element;
  886. // return el;
  887. //};
  888. Sahi.prototype.tagByText = function (win, id, tagName, res) {
  889. var o = this.getArrayNameAndIndex(id);
  890. var ix = o.index;
  891. var fetch = o.name;
  892. var els = this.getDoc(win).getElementsByTagName(tagName);
  893. for (var i = 0; i < els.length; i++) {
  894. var el = els[i];
  895. var text = this._getText(el);
  896. if (this.isTextMatch(text, fetch)) {
  897. res.cnt++;
  898. if (res.cnt == ix || ix == -1) {
  899. res.element = this.innerMost(el, id, tagName.toUpperCase());
  900. res.found = true;
  901. return res;
  902. }
  903. }
  904. }
  905. var frs = win.frames;
  906. if (frs) {
  907. for (var j = 0; j < frs.length; j++) {
  908. try{
  909. res = this.tagByText(frs[j], id, tagName, res);
  910. }catch(e){}
  911. if (res && res.found) return res;
  912. }
  913. }
  914. return res;
  915. };
  916. Sahi.prototype.isTextMatch = function(sample, pattern){
  917. if (pattern instanceof RegExp)
  918. return sample.match(pattern);
  919. return (sample == pattern);
  920. };
  921. Sahi.prototype.innerMost = function(el, re, tagName){
  922. for (var i=0; i < el.childNodes.length; i++){
  923. var child = el.childNodes[i];
  924. var text = this._getText(child);
  925. if (text && text.match(re)){
  926. var inner = this.innerMost(child, re, tagName);
  927. if (inner.nodeName == tagName) return inner;
  928. }
  929. }
  930. return el;
  931. };
  932. //Sahi.prototype._image = function (n, inEl) {
  933. // return this.findImage(n, inEl);
  934. //};
  935. //Sahi.prototype._imageSubmitButton = function (n, inEl) {
  936. // return this.findElement(n, "image", "input", inEl);
  937. //};
  938. Sahi.prototype._simulateEvent = function (el, ev) {
  939. if (this.isIE()) {
  940. var newFn = (eval("el.on" + ev.type)).toString();
  941. newFn = newFn.replace("anonymous()", "s_anon(s_ev)", "g").replace("event", "s_ev", "g");
  942. eval(newFn);
  943. s_anon(ev);
  944. } else {
  945. eval("el.on" + ev.type + "(ev);");
  946. }
  947. };
  948. Sahi.prototype._setGlobal = function (name, value) {
  949. //this._debug("SET name="+name+" value="+value);
  950. this.setServerVar(name, value, true);
  951. };
  952. Sahi.prototype._getGlobal = function (name) {
  953. var value = this.getServerVar(name, true);
  954. //this._debug("GET name="+name+" value="+value);
  955. return value;
  956. };
  957. Sahi.prototype._set = function (name, value) {
  958. this.locals[name] = value;
  959. };
  960. Sahi.prototype._get = function (name) {
  961. var value = this.locals[name];
  962. return value;
  963. };
  964. Sahi.prototype._assertNotNull = function (n, s) {
  965. if (n == null) throw new SahiAssertionException(1, s);
  966. return true;
  967. };
  968. Sahi.prototype._assertExists = Sahi.prototype._assertNotNull;
  969. Sahi.prototype._assertNull = function (n, s) {
  970. if (n != null) throw new SahiAssertionException(2, s);
  971. return true;
  972. };
  973. Sahi.prototype._assertNotExists = Sahi.prototype._assertNull;
  974. Sahi.prototype._assertTrue = function (n, s) {
  975. if (n != true) throw new SahiAssertionException(5, s);
  976. return true;
  977. };
  978. Sahi.prototype._assert = Sahi.prototype._assertTrue;
  979. Sahi.prototype._assertNotTrue = function (n, s) {
  980. if (n) throw new SahiAssertionException(6, s);
  981. return true;
  982. };
  983. Sahi.prototype._assertFalse = Sahi.prototype._assertNotTrue;
  984. Sahi.prototype._assertEqual = function (expected, actual, s) {
  985. if (this.trim(expected) != this.trim(actual)) throw new SahiAssertionException(3, (s ? s : "") + "\nExpected:[" + expected + "]\nActual:[" + actual + "]");
  986. return true;
  987. };
  988. Sahi.prototype._assertNotEqual = function (expected, actual, s) {
  989. if (this.trim(expected) == this.trim(actual)) throw new SahiAssertionException(4, s);
  990. return true;
  991. };
  992. Sahi.prototype._assertContainsText = function (expected, el, s) {
  993. var text = this._getText(el);
  994. var present = false;
  995. if (expected instanceof RegExp)
  996. present = expected != null && text.match(expected) != null;
  997. else present = text.indexOf(expected) != -1;
  998. if (!present) throw new SahiAssertionException(3, (s ? s : "") + "\nExpected:[" + expected + "] to be part of [" + text + "]");
  999. return true;
  1000. };
  1001. Sahi.prototype._getSelectedText = function (el) {
  1002. var opts = el.options;
  1003. for (var i = 0; i < opts.length; i++) {
  1004. if (el.value == opts[i].value) return opts[i].text;
  1005. }
  1006. return null;
  1007. };
  1008. Sahi.prototype._option = function (el, text) {
  1009. var opts = el.options;
  1010. for (var i = 0; i < opts.length; i++) {
  1011. if (text == opts[i].text) return opts[i];
  1012. }
  1013. return null;
  1014. };
  1015. Sahi.prototype._getText = function (el) {
  1016. this.checkNull(el, "_getText");
  1017. return this.trim(this.isIE() || this.isSafariLike() ? el.innerText : el.textContent);
  1018. };
  1019. Sahi.prototype._getCellText = Sahi.prototype._getText;
  1020. Sahi.prototype.getRowIndexWith = function (txt, tableEl) {
  1021. var r = this.getRowWith(txt, tableEl);
  1022. return (r == null) ? -1 : r.rowIndex;
  1023. };
  1024. Sahi.prototype.getRowWith = function (txt, tableEl) {
  1025. for (var i = 0; i < tableEl.rows.length; i++) {
  1026. var r = tableEl.rows[i];
  1027. for (var j = 0; j < r.cells.length; j++) {
  1028. if (this._getText(r.cells[j]).indexOf(txt) != -1) {
  1029. return r;
  1030. }
  1031. }
  1032. }
  1033. return null;
  1034. };
  1035. Sahi.prototype.getColIndexWith = function (txt, tableEl) {
  1036. for (var i = 0; i < tableEl.rows.length; i++) {
  1037. var r = tableEl.rows[i];
  1038. for (var j = 0; j < r.cells.length; j++) {
  1039. if (this._getText(r.cells[j]).indexOf(txt) != -1) {
  1040. return j;
  1041. }
  1042. }
  1043. }
  1044. return -1;
  1045. };
  1046. Sahi.prototype._alert = function (s) {
  1047. return this.callFunction(this.real_alert, window, s);
  1048. };
  1049. Sahi.prototype._lastAlert = function () {
  1050. var v = this.getServerVar("lastAlertText");
  1051. return v;
  1052. };
  1053. Sahi.prototype._eval = function (s) {
  1054. return eval(s);
  1055. };
  1056. Sahi.prototype._call = function (s) {
  1057. return s;
  1058. };
  1059. Sahi.prototype._random = function (n) {
  1060. return Math.floor(Math.random() * (n + 1));
  1061. };
  1062. Sahi.prototype._savedRandom = function (id, min, max) {
  1063. if (min == null) min = 0;
  1064. if (max == null) max = 10000;
  1065. var r = this.getServerVar("srandom" + id);
  1066. if (r == null || r == "") {
  1067. r = min + this._random(max - min);
  1068. this.setServerVar("srandom" + id, r);
  1069. }
  1070. return r;
  1071. };
  1072. Sahi.prototype._resetSavedRandom = function (id) {
  1073. this.setServerVar("srandom" + id, "");
  1074. };
  1075. Sahi.prototype._expectConfirm = function (text, value) {
  1076. this.setServerVar("confirm: "+text, value);
  1077. };
  1078. Sahi.prototype._saveDownloadedAs = function(filePath){
  1079. this._callServer("SaveAs_saveLastDownloadedAs", "destination="+encodeURIComponent(filePath));
  1080. };
  1081. Sahi.prototype._lastDownloadedFileName = function(){
  1082. var fileName = this._callServer("SaveAs_getLastDownloadedFileName");
  1083. if (fileName == "-1") return null;
  1084. return fileName;
  1085. };
  1086. Sahi.prototype._clearLastDownloadedFileName = function(){
  1087. this._callServer("SaveAs_clearLastDownloadedFileName");
  1088. };
  1089. Sahi.prototype._saveFileAs = function(filePath){
  1090. this._callServer("SaveAs_saveTo", filePath);
  1091. };
  1092. Sahi.prototype.recordStep = function(s){
  1093. this.sendToServer("/_s_/dyn/Recorder2_addRecordedStep?step="+ encodeURIComponent(s));
  1094. };
  1095. Sahi.prototype.callFunction = function(fn, obj, args){
  1096. if (fn.apply){
  1097. return fn.apply(window, [args]);
  1098. }else{
  1099. return fn(args);
  1100. }
  1101. };
  1102. Sahi.prototype._lastConfirm = function () {
  1103. var v = this.getServerVar("lastConfirmText");
  1104. return v;
  1105. };
  1106. Sahi.prototype._lastPrompt = function () {
  1107. var v = this.getServerVar("lastPromptText");
  1108. return v;
  1109. };
  1110. Sahi.prototype._expectPrompt = function (text, value) {
  1111. this.setServerVar("prompt: "+text, value);
  1112. };
  1113. Sahi.prototype._prompt = function (s) {
  1114. return this.callFunction(this.real_prompt, window, s);
  1115. };
  1116. Sahi.prototype._print = function (s){
  1117. return this.callFunction(this.real_print, window, s);
  1118. };
  1119. Sahi.prototype._printCalled = function (){
  1120. return this.getServerVar("printCalled");
  1121. };
  1122. Sahi.prototype._clearPrintCalled = function (){
  1123. this.setServerVar("printCalled", null);
  1124. };
  1125. Sahi.prototype._cell = function (id, row, col) {
  1126. if (id == null) return null;
  1127. if (row == null && col == null) {
  1128. return this.findCell(id);
  1129. }
  1130. if (row != null && (row.type == "_in" || row.type == "_near")){
  1131. return this.findCell(id, row);
  1132. }
  1133. var rowIx = row;
  1134. var colIx = col;
  1135. if (typeof row == "string") {
  1136. rowIx = this.getRowIndexWith(row, id);
  1137. if (rowIx == -1) return null;
  1138. }
  1139. if (typeof col == "string") {
  1140. colIx = this.getColIndexWith(col, id);
  1141. if (colIx == -1) return null;
  1142. }
  1143. if (id.rows[rowIx] == null) return null;
  1144. return id.rows[rowIx].cells[colIx];
  1145. };
  1146. //Sahi.prototype._table = function (n, inEl) {
  1147. // return this.findTable(n, inEl);
  1148. //};
  1149. Sahi.prototype._row = function (tableEl, rowIx) {
  1150. if (typeof rowIx == "string") {
  1151. return this.getRowWith(rowIx, tableEl);
  1152. }
  1153. if (typeof rowIx == "number") {
  1154. return tableEl.rows[rowIx];
  1155. }
  1156. return null;
  1157. };
  1158. Sahi.prototype._containsHTML = function (el, htm) {
  1159. return el && el.innerHTML && el.innerHTML.indexOf(htm) != -1;
  1160. };
  1161. Sahi.prototype._containsText = function (el, txt) {
  1162. return el && this._getText(el).indexOf(txt) != -1;
  1163. };
  1164. Sahi.prototype._contains = function (parent, child) {
  1165. var c = child;
  1166. while (true){
  1167. if (c == parent) return true;
  1168. if (c == null || c == c.parentNode) return false;
  1169. c = c.parentNode;
  1170. }
  1171. };
  1172. Sahi.prototype._popup = function (n) {
  1173. if (this.top().name == n || this.top().document.title == n) {
  1174. return this.top();
  1175. }
  1176. throw new SahiNotMyWindowException(n);
  1177. };
  1178. Sahi.prototype._log = function (s, type) {
  1179. if (!type) type = "info";
  1180. this.logPlayBack(s, type);
  1181. };
  1182. Sahi.prototype._navigateTo = function (url, force) {
  1183. if (force || this.top().location.href != url)
  1184. this.top().location.href = url;
  1185. // this.top().setTimeout("location.href = '"+url+"'", 1);
  1186. };
  1187. Sahi.prototype._callServer = function (cmd, qs) {
  1188. return this.sendToServer("/_s_/dyn/" + cmd + (qs == null ? "" : ("?" + qs)));
  1189. };
  1190. Sahi.prototype._removeMock = function (pattern) {
  1191. return this._callServer("MockResponder_remove", "pattern=" + pattern);
  1192. };
  1193. Sahi.prototype._addMock = function (pattern, clazz) {
  1194. if (clazz == null) clazz = "MockResponder_simple";
  1195. return this._callServer("MockResponder_add", "pattern=" + pattern + "&class=" + clazz);
  1196. };
  1197. Sahi.prototype._mockImage = function (pattern, clazz) {
  1198. if (clazz == null) clazz = "MockResponder_mockImage";
  1199. return this._callServer("MockResponder_add", "pattern=" + pattern + "&class=" + clazz);
  1200. };
  1201. Sahi.prototype._debug = function (s) {
  1202. return this._callServer("Debug_toOut", "msg=Debug: " + encodeURIComponent(s));
  1203. };
  1204. Sahi.prototype._debugToErr = function (s) {
  1205. return this._callServer("Debug_toErr", "msg=" + encodeURIComponent(s));
  1206. };
  1207. Sahi.prototype._debugToFile = function (s, file) {
  1208. if (file == null) return null;
  1209. return this._callServer("Debug_toFile", "msg=" + encodeURIComponent(s) + "&file=" + encodeURIComponent(file));
  1210. };
  1211. Sahi.prototype._enableKeepAlive = function () {
  1212. this.sendToServer('/_s_/dyn/Configuration_enableKeepAlive');
  1213. };
  1214. Sahi.prototype._disableKeepAlive = function () {
  1215. this.sendToServer('/_s_/dyn/Configuration_disableKeepAlive');
  1216. };
  1217. Sahi.prototype.getWin = function (el) {
  1218. if (el == null) return self;
  1219. if (el.nodeName.indexOf("document") != -1) return this.getFrame1(this.top(), el);
  1220. return this.getWin(el.parentNode);
  1221. };
  1222. // finds window to which a document belongs
  1223. Sahi.prototype.getFrame1 = function (win, doc) {
  1224. if (win.document == doc) return win;
  1225. var frs = win.frames;
  1226. for (var j = 0; j < frs.length; j++) {
  1227. var sub = this.getFrame1(frs[j], doc);
  1228. if (sub != null) {
  1229. return sub;
  1230. }
  1231. }
  1232. return null;
  1233. };
  1234. Sahi.prototype.simulateChange = function (el) {
  1235. if (window.document.all) {
  1236. if (el.onchange) el.onchange();
  1237. if (el.onblur) el.onblur();
  1238. } else {
  1239. if (el.onblur) el.onblur();
  1240. if (el.onchange) el.onchange();
  1241. }
  1242. };
  1243. Sahi.prototype.areEqual2 = function (el, param, value) {
  1244. if (param == "sahiText") {
  1245. var str = this._getText(el);
  1246. if (value instanceof RegExp)
  1247. return str != null && str.match(value) != null;
  1248. return (this.trim(str) == this.trim(value));
  1249. }
  1250. else {
  1251. if (value instanceof RegExp)
  1252. return el[param] != null && el[param].match(value) != null;
  1253. return (el[param] == value);
  1254. }
  1255. };
  1256. Sahi.prototype.areEqual = function (el, param, value) {
  1257. if (typeof param == "function"){
  1258. return this.callFunction(param, this, el) == value;
  1259. }
  1260. if (param == null || param.indexOf("|") == -1)
  1261. return this.areEqual2(el, param, value);
  1262. var params = param.split("|");
  1263. for (var i=0; i<params.length; i++){
  1264. if (this.areEqual2(el, params[i], value)) return true;
  1265. }
  1266. return false;
  1267. };
  1268. Sahi.prototype.findElementById = function (win, id) {
  1269. var res = null;
  1270. if (win.document.getElementById(id) != null) {
  1271. return win.document.getElementById(id);
  1272. }
  1273. var frs = win.frames;
  1274. if (frs) {
  1275. for (var j = 0; j < frs.length; j++) {
  1276. try{
  1277. res = this.findElementById(frs[j], id);
  1278. }catch(diffDomain){}
  1279. if (res) return res;
  1280. }
  1281. }
  1282. return res;
  1283. };
  1284. Sahi.prototype.findFormElementByIndex = function (ix, win, type, res, tagName) {
  1285. var els = this.getDoc(win).getElementsByTagName(tagName);
  1286. for (var j = 0; j < els.length; j++) {
  1287. var el = els[j];
  1288. if (el != null && this.areEqualTypes(el.type, type)) {
  1289. res.cnt++;
  1290. if (res.cnt == ix) {
  1291. res.element = el;
  1292. res.found = true;
  1293. return res;
  1294. }
  1295. }
  1296. }
  1297. var frs = win.frames;
  1298. if (frs) {
  1299. for (var k = 0; k < frs.length; k++) {
  1300. try{
  1301. res = this.findFormElementByIndex(ix, frs[k], type, res, tagName);
  1302. }catch(e){}
  1303. if (res && res.found) return res;
  1304. }
  1305. }
  1306. return res;
  1307. };
  1308. Sahi.prototype.findElementHelper = function (id, win, type, res, param, tagName) {
  1309. if ((typeof id) == "number") {
  1310. res = this.findFormElementByIndex(id, win, type, res, tagName);
  1311. if (res.found) return res;
  1312. } else {
  1313. var doc = this.getDoc(win);
  1314. var els = doc.getElementsByTagName(tagName);
  1315. for (var j = 0; j < els.length; j++) {
  1316. if (this.areEqualTypes(els[j].type, type) && this.areEqual(els[j], param, id)) {
  1317. res.element = els[j];
  1318. res.found = true;
  1319. return res;
  1320. }
  1321. }
  1322. var o = this.getArrayNameAndIndex(id);
  1323. var ix = o.index;
  1324. var fetch = o.name;
  1325. els = this.getDoc(win).getElementsByTagName(tagName);
  1326. for (var k = 0; k < els.length; k++) {
  1327. if (this.areEqualTypes(els[k].type, type) && this.areEqual(els[k], param, fetch)) {
  1328. res.cnt++;
  1329. if (res.cnt == ix || ix == -1) {
  1330. res.element = els[k];
  1331. res.found = true;
  1332. return res;
  1333. }
  1334. }
  1335. }
  1336. }
  1337. var frs = win.frames;
  1338. if (frs) {
  1339. for (var ii = 0; ii < frs.length; ii++) {
  1340. try{
  1341. res = this.findElementHelper(id, frs[ii], type, res, param, tagName);
  1342. }catch(e){}
  1343. if (res && res.found) return res;
  1344. }
  1345. }
  1346. return res;
  1347. };
  1348. Sahi.prototype.findElementIxHelper = function (id, type, toMatch, win, res, param, tagName) {
  1349. if (res && res.found) return res;
  1350. var els = win.document.getElementsByTagName(tagName);
  1351. for (var j = 0; j < els.length; j++) {
  1352. if (this.areEqualTypes(els[j].type, type) && this.areEqual(els[j], param, id)) {
  1353. res.cnt++;
  1354. if (els[j] == toMatch) {
  1355. res.found = true;
  1356. return res;
  1357. }
  1358. }
  1359. }
  1360. var frs = win.frames;
  1361. if (frs) {
  1362. for (var k = 0; k < frs.length; k++) {
  1363. try{
  1364. res = this.findElementIxHelper(id, type, toMatch, frs[k], res, param, tagName);
  1365. }catch(e){};
  1366. if (res && res.found) return res;
  1367. }
  1368. }
  1369. return res;
  1370. };
  1371. Sahi.prototype.areEqualTypes = function (type1, type2) {
  1372. if (type1 == type2) return true;
  1373. return (type1.indexOf("select") != -1 && type2.indexOf("select") != -1);
  1374. };
  1375. Sahi.prototype.findCell = function (id, inEl) {
  1376. if (!inEl) inEl = this.top();
  1377. var res = this.getBlankResult();
  1378. res = this.findTagHelper(id, inEl, "td", res, "id").element;
  1379. if (res != null) return res;
  1380. res = this.getBlankResult();
  1381. return this.findTagHelper(id, inEl, "td", res, "sahiText").element;
  1382. };
  1383. Sahi.prototype.findCellIx = function (id, toMatch, attr) {
  1384. var res = this.getBlankResult();
  1385. var retVal = this.findTagIxHelper(id, toMatch, this.top(), "td", res, attr).cnt;
  1386. if (retVal != -1) return retVal;
  1387. };
  1388. Sahi.prototype.getBlankResult = function () {
  1389. var res = new Object();
  1390. res.cnt = -1;
  1391. res.found = false;
  1392. res.element = null;
  1393. return res;
  1394. };
  1395. Sahi.prototype.getArrayNameAndIndex = function (id) {
  1396. var o = new Object();
  1397. if (!(id instanceof RegExp) && id.match(/(.*)\[([0-9]*)\]$/)) {
  1398. o.name = RegExp.$1;
  1399. o.index = parseInt(RegExp.$2);
  1400. } else {
  1401. o.name = id;
  1402. o.index = -1;
  1403. }
  1404. return o;
  1405. };
  1406. Sahi.prototype.findTableIx = function (id, toMatch) {
  1407. var res = this.getBlankResult();
  1408. var retVal = this.findTagIxHelper(id, toMatch, this.top(), "table", res, (id ? "id" : null)).cnt;
  1409. if (retVal != -1) return retVal;
  1410. };
  1411. Sahi.prototype.findTable = function (id, inEl) {
  1412. if (!inEl) inEl = this.top();
  1413. var res = this.getBlankResult();
  1414. return this.findTagHelper(id, inEl, "table", res, "id").element;
  1415. };
  1416. Sahi.prototype._iframe = function (id, inEl) {
  1417. if (!inEl) inEl = this.top();
  1418. var res = this.getBlankResult();
  1419. var el = this.findTagHelper(id, inEl, "iframe", res, "id").element;
  1420. if (el != null) return el;
  1421. res = this.getBlankResult();
  1422. el = this.findTagHelper(id, inEl, "iframe", res, "name").element;
  1423. if (el != null) return el;
  1424. };
  1425. Sahi.prototype._rte = Sahi.prototype._iframe;
  1426. Sahi.prototype.findResByIndexInList = function (ix, win, type, res) {
  1427. var tags = this.getDoc(win).getElementsByTagName(type);
  1428. if (tags[ix - res.cnt]) {
  1429. res.element = tags[ix - res.cnt];
  1430. res.found = true;
  1431. return res;
  1432. }
  1433. res.cnt += tags.length;
  1434. var frs = win.frames;
  1435. if (frs) {
  1436. for (var j = 0; j < frs.length; j++) {
  1437. try{
  1438. res = this.findResByIndexInList(ix, frs[j], type, res);
  1439. }catch(e){}
  1440. if (res && res.found) return res;
  1441. }
  1442. }
  1443. return res;
  1444. };
  1445. Sahi.prototype.findTagHelper = function (id, win, type, res, param) {
  1446. if ((typeof id) == "number") {
  1447. res.cnt = 0;
  1448. res = this.findResByIndexInList(id, win, type, res);
  1449. return res;
  1450. } else {
  1451. var o = this.getArrayNameAndIndex(id);
  1452. var ix = o.index;
  1453. var fetch = o.name;
  1454. var tags = this.getDoc(win).getElementsByTagName(type);
  1455. if (tags) {
  1456. for (var i = 0; i < tags.length; i++) {
  1457. if (this.areEqual(tags[i], param, fetch)) {
  1458. res.cnt++;
  1459. if (res.cnt == ix || ix == -1) {
  1460. res.element = tags[i];
  1461. res.found = true;
  1462. return res;
  1463. }
  1464. }
  1465. }
  1466. }
  1467. }
  1468. var frs = win.frames;
  1469. if (frs) {
  1470. for (var j = 0; j < frs.length; j++) {
  1471. try{
  1472. res = this.findTagHelper(id, frs[j], type, res, param);
  1473. }catch(diffDomain){}
  1474. if (res && res.found) return res;
  1475. }
  1476. }
  1477. return res;
  1478. };
  1479. Sahi.prototype.findTagIxHelper = function (id, toMatch, win, type, res, param) {
  1480. if (res && res.found) return res;
  1481. var tags = win.document.getElementsByTagName(type);
  1482. if (tags) {
  1483. for (var i = 0; i < tags.length; i++) {
  1484. if (param == null || this.areEqual(tags[i], param, id)) {
  1485. res.cnt++;
  1486. if (tags[i] == toMatch) {
  1487. res.found = true;
  1488. return res;
  1489. }
  1490. }
  1491. }
  1492. }
  1493. var frs = win.frames;
  1494. if (frs) {
  1495. for (var j = 0; j < frs.length; j++) {
  1496. try{
  1497. res = this.findTagIxHelper(id, toMatch, frs[j], type, res, param);
  1498. }catch(e){}
  1499. if (res && res.found) return res;
  1500. }
  1501. }
  1502. return res;
  1503. };
  1504. Sahi.prototype.canSimulateClick = function (el) {
  1505. return (el.click || el.dispatchEvent);
  1506. };
  1507. Sahi.prototype.isRecording = function () {
  1508. if (this._isRecording == null)
  1509. this._isRecording = this.getServerVar("sahi_record") == 1;
  1510. return this._isRecording;
  1511. };
  1512. Sahi.prototype.createCookie = function (name, value, days){
  1513. // this._alert(document.domain+" "+name+" "+value);
  1514. var expires = "";
  1515. if (days) {
  1516. var date = new Date();
  1517. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  1518. expires = "; expires=" + date.toGMTString();
  1519. }
  1520. window.document.cookie = name + "=" + value + expires + "; path=/";
  1521. };
  1522. Sahi.prototype._createCookie = Sahi.prototype.createCookie;
  1523. Sahi.prototype.readCookie = function (name){
  1524. var nameEQ = name + "=";
  1525. var ca = window.document.cookie.split(';');
  1526. for (var i = 0; i < ca.length; i++)
  1527. {
  1528. var c = ca[i];
  1529. while (c.charAt(0) == ' ') c = c.substring(1, c.length);
  1530. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  1531. }
  1532. return null;
  1533. };
  1534. Sahi.prototype._cookie = Sahi.prototype.readCookie;
  1535. Sahi.prototype.eraseCookie = function (name){
  1536. this.createCookie(name, "", -1);
  1537. };
  1538. Sahi.prototype._deleteCookie = Sahi.prototype.eraseCookie;
  1539. Sahi.prototype._event = function (type, keyCode) {
  1540. this.type = type;
  1541. this.keyCode = keyCode;
  1542. };
  1543. var SahiAssertionException = function (msgNum, msgText) {
  1544. this.messageNumber = msgNum;
  1545. this.messageText = msgText;
  1546. this.exceptionType = "SahiAssertionException";
  1547. };
  1548. var SahiNotMyWindowException = function (n) {
  1549. this.name = "SahiNotMyWindowException";
  1550. if (n){
  1551. this.message = "Window with name ["+n+"] not found";
  1552. }else{
  1553. this.message = "Base window not found";
  1554. }
  1555. };
  1556. var lastQs = "";
  1557. var lastTime = 0;
  1558. Sahi.prototype.onEv = function (e) {
  1559. if (e.handled == true) return; //FF
  1560. if (this.getServerVar("sahiEvaluateExpr") == true) return;
  1561. var targ = this.getKnownTags(this.getTarget(e));
  1562. if (e.type == _s_triggerType) {
  1563. if (targ.type) {
  1564. var type = targ.type;
  1565. if (type == "text" || type == "textarea" || type == "password"
  1566. || type == "select-one" || type == "select-multiple") return;
  1567. }
  1568. }
  1569. e.handled = true;
  1570. //FF
  1571. if (this.isRecording()){
  1572. var elInfo = this.identify(targ);
  1573. var ids = elInfo.apis;
  1574. if (ids.length > 0) {
  1575. var script = this.getScript(ids[0]);
  1576. if (script!=null) this.recordStep(script);
  1577. this.sendIdsToController(elInfo, "RECORD");
  1578. }
  1579. }
  1580. };
  1581. Sahi.prototype.showInController = function (info) {
  1582. try {
  1583. var c = this.getController();
  1584. if (c) {
  1585. var d = c.top.main.document.currentForm.debug;
  1586. c.top.main.document.currentForm.history.value += "\n" + d.value;
  1587. d.value = this.getScript(info);
  1588. }
  1589. } catch(ex2) {
  1590. // throw ex2;
  1591. }
  1592. };
  1593. Sahi.prototype.hasEventBeenRecorded = function (qs) {
  1594. var now = (new Date()).getTime();
  1595. if (qs == lastQs && (now - lastTime) < 500) return true;
  1596. lastQs = qs;
  1597. lastTime = now;
  1598. return false;
  1599. };
  1600. Sahi.prototype.getPopupName = function () {
  1601. var n = null;
  1602. if (this.isPopup()) {
  1603. n = this.top().name;
  1604. if (!n || n == "") {
  1605. try{
  1606. n = this.top().document.title;
  1607. }catch(e){}
  1608. }
  1609. }
  1610. return n ? n : "";
  1611. };
  1612. Sahi.prototype.isPopup = function () {
  1613. if (this.top().opener == null) return false;
  1614. if (_sahi.top().opener.closed) return true;
  1615. try{
  1616. var x = _sahi.top().opener._sahi;
  1617. }catch(openerFromDiffDomain){
  1618. return true;
  1619. }
  1620. if (_sahi.top().opener._sahi != null && _sahi.top().opener._sahi.top() != window._sahi.top()){
  1621. return true;
  1622. }
  1623. return false;
  1624. };
  1625. Sahi.prototype.addWait = function (time) {
  1626. var val = parseInt(time);
  1627. if (("" + val) == "NaN" || val < 200) throw new Error();
  1628. this.showInController(new AccessorInfo("", "", "", "wait", time));
  1629. // this.sendToServer('/_s_/dyn/Recorder_record?event=wait&value='+val);
  1630. };
  1631. Sahi.prototype.mark = function (s) {
  1632. this.showInController(new AccessorInfo("", "", "", "mark", s));
  1633. };
  1634. Sahi.prototype.doAssert = function (e) {
  1635. try {
  1636. var lastAccessedInfo = this.top()._sahi.lastAccessedInfo;
  1637. if (!lastAccessedInfo) return;
  1638. lastAccessedInfo.event = "assert";
  1639. this.showInController(lastAccessedInfo);
  1640. } catch(ex) {
  1641. this.handleException(ex);
  1642. }
  1643. };
  1644. Sahi.prototype.getTarget = function (e) {
  1645. var targ;
  1646. if (!e) e = window.event;
  1647. var evType = e.type;
  1648. if (e.target) targ = e.target;
  1649. else if (e.srcElement) targ = e.srcElement;
  1650. if (targ.nodeType == 3) // defeat Safari bug
  1651. targ = targ.parentNode;
  1652. return targ;
  1653. };
  1654. var AccessorInfo = function (accessor, shortHand, type, event, value, valueType) {
  1655. this.accessor = accessor;
  1656. this.shortHand = shortHand;
  1657. this.type = type;
  1658. this.event = event;
  1659. this.value = value;
  1660. this.valueType = valueType;
  1661. };
  1662. Sahi.prototype.getOptionText = function (sel, val) {
  1663. var l = sel.options.length;
  1664. for (var i = 0; i < l; i++) {
  1665. if (sel.options[i].value == val) return sel.options[i].text;
  1666. }
  1667. return null;
  1668. };
  1669. Sahi.prototype.getOptionId = function (sel, val) {
  1670. var l = sel.options.length;
  1671. for (var i = 0; i < l; i++) {
  1672. if (sel.options[i].value == val) return sel.options[i].id;
  1673. }
  1674. return null;
  1675. };
  1676. Sahi.prototype.addHandlersToAllFrames = function (win) {
  1677. var fs = win.frames;
  1678. if (!fs || fs.length == 0) {
  1679. this.addHandlers(self);
  1680. } else {
  1681. for (var i = 0; i < fs.length; i++) {
  1682. try{
  1683. this.addHandlersToAllFrames(fs[i]);
  1684. }catch(e){}
  1685. }
  1686. }
  1687. };
  1688. Sahi.prototype.docEventHandler = function (e) {
  1689. if (!e) e = window.event;
  1690. //var t = _sahi.getTarget(e);
  1691. var t = this.getKnownTags(this.getTarget(e));
  1692. if (t && !t.hasAttached && t.tagName) {
  1693. var tag = t.tagName.toLowerCase();
  1694. if (tag == "a" || t.form || tag == "img" || tag == "div" || tag == "span" || tag == "li" || tag == "td" || tag == "table"
  1695. || tag == "input" || tag == "textarea" || tag == "button") {
  1696. this.attachEvents(t);
  1697. }
  1698. t.hasAttached = true;
  1699. }
  1700. };
  1701. Sahi.prototype.addHandlers = function (win) {
  1702. if (!win) win = self;
  1703. var doc = win.document;
  1704. this.addWrappedEvent(doc, "keyup", this.docEventHandler);
  1705. this.addWrappedEvent(doc, "mousemove", this.docEventHandler);
  1706. };
  1707. Sahi.prototype.attachEvents = function (el) {
  1708. var tagName = el.tagName.toLowerCase();
  1709. if (tagName == "a") {
  1710. this.attachLinkEvents(el);
  1711. // } else if (el.form && el.type) {
  1712. } else if (el.type) {
  1713. this.attachFormElementEvents(el);
  1714. } else if (tagName == "img" || tagName == "div" || tagName == "span" || tagName == "td" || tagName == "table" || tagName == "li") {
  1715. this.attachImageEvents(el);
  1716. }
  1717. };
  1718. var _s_triggerType = "click";
  1719. Sahi.prototype.attachFormElementEvents = function (el) {
  1720. var type = el.type;
  1721. var wrapped = this.wrap(this.onEv);
  1722. if (el.onchange == wrapped || el.onblur == wrapped || el.onclick == wrapped) return;
  1723. if (type == "text" || type == "file" || type == "textarea" || type == "password") {
  1724. this.addEvent(el, "change", wrapped);
  1725. } else if (type == "select-one" || type == "select-multiple") {
  1726. this.addEvent(el, "change", wrapped);
  1727. } else if (type == "button" || type == "submit" || type == "reset" || type == "checkbox" || type == "radio" || type == "image") {
  1728. this.addEvent(el, _s_triggerType, wrapped);
  1729. }
  1730. };
  1731. Sahi.prototype.attachLinkEvents = function (el) {
  1732. this.addWrappedEvent(el, _s_triggerType, this.onEv);
  1733. };
  1734. Sahi.prototype.attachImageEvents = function (el) {
  1735. this.addWrappedEvent(el, _s_triggerType, this.onEv);
  1736. };
  1737. Sahi.prototype.addWrappedEvent = function (el, ev, fn) {
  1738. this.addEvent(el, ev, this.wrap(fn));
  1739. };
  1740. Sahi.prototype.addEvent = function (el, ev, fn) {
  1741. if (!el) return;
  1742. if (el.attachEvent) {
  1743. el.attachEvent("on" + ev, fn);
  1744. } else if (el.addEventListener) {
  1745. el.addEventListener(ev, fn, false);
  1746. }
  1747. };
  1748. Sahi.prototype.removeEvent = function (el, ev, fn) {
  1749. if (!el) return;
  1750. if (el.attachEvent) {
  1751. el.detachEvent("on" + ev, fn);
  1752. } else if (el.removeEventListener) {
  1753. el.removeEventListener(ev, fn, false);
  1754. }
  1755. };
  1756. Sahi.prototype.setRetries = function (i) {
  1757. this.sendToServer("/_s_/dyn/Player_setRetries?retries="+i);
  1758. //this.setServerVar("sahi_retries", i);
  1759. };
  1760. Sahi.prototype.getRetries = function () {
  1761. var i = parseInt(this.sendToServer("/_s_/dyn/Player_getRetries"));
  1762. return ("" + i != "NaN") ? i : 0;
  1763. };
  1764. Sahi.prototype.getExceptionString = function (e)
  1765. {
  1766. var stack = e.stack ? e.stack : "No trace available";
  1767. return e.name + ": " + e.message + "<br>" + stack.replace(/\n/g, "<br>");
  1768. };
  1769. Sahi.onError = function (msg, url, lno) {
  1770. try {
  1771. var debugInfo = "Javascript error on page";
  1772. if (!url) url = "";
  1773. if (!lno) lno = "";
  1774. if (msg && msg.indexOf("Access to XPConnect service denied") != -1) { //FF hack
  1775. _sahi.setJSError(msg, lno);
  1776. }
  1777. else {
  1778. _sahi.setJSError(msg, lno);
  1779. }
  1780. if (Sahi.prevOnError && Sahi.prevOnError != Sahi.onError)
  1781. Sahi.prevOnError(msg, url, lno);
  1782. } catch(swallow) {
  1783. }
  1784. };
  1785. Sahi.prototype.setJSError = function (msg, lno) {
  1786. this.__jsError = {'message':msg, 'lineNumber':lno};
  1787. };
  1788. Sahi.prototype.openWin = function (e) {
  1789. var winName = "_sahiControl3";
  1790. try {
  1791. if (!e) e = window.event;
  1792. this.controller = window.open("", winName, this.getWinParams(e));
  1793. // var diffDom = false;
  1794. // try {
  1795. // var checkDiffDomain = this.controller.document.domain;
  1796. // } catch(domainInaccessible) {
  1797. // diffDom = true;
  1798. // }
  1799. // if (diffDom || !this.controller.isWinOpen) {
  1800. // if (this.controller.closed) {
  1801. this.controller = window.open("http://sahi.example.com/_s_/dyn/ControllerUI?sahisid="+this.sid, winName, this.getWinParams(e));
  1802. // }
  1803. // if (this.controller) this.controller.opener = window;
  1804. if (e) this.controller.focus();
  1805. } catch(ex) {
  1806. this.handleException(ex);
  1807. }
  1808. };
  1809. Sahi.prototype.getWinParams = function (e) {
  1810. var x = e ? e.screenX - 40 : 500;
  1811. var y = e ? e.screenY - 60 : 100;
  1812. var positionParams = "";
  1813. if (e) {
  1814. if (this.isIE()) positionParams = ",screenX=" + x + ",screenY=" + y;
  1815. else positionParams = ",screenX=" + x + ",screenY=" + y;
  1816. }
  1817. return "height=550px,width=430px,resizable=yes,toolbar=no,status=no" + positionParams;
  1818. };
  1819. Sahi.prototype.getController = function () {
  1820. var controller = this.top()._sahi.controller;
  1821. return (controller && !controller.closed) ? controller : null;
  1822. };
  1823. Sahi.openControllerWindow = function (e) {
  1824. if (!e) e = window.event;
  1825. if (!_sahi.isHotKeyPressed(e)) return true;
  1826. _sahi.top()._sahi.openWin(e);
  1827. // _sahi.openWin(e);
  1828. return true;
  1829. };
  1830. Sahi.prototype.isHotKeyPressed = function (e) {
  1831. return ((this.hotKey == "SHIFT" && e.shiftKey)
  1832. || (this.hotKey == "CTRL" && e.ctrlKey)
  1833. || (this.hotKey == "ALT" && e.altKey)
  1834. || (this.hotKey == "META" && e.metaKey));
  1835. };
  1836. Sahi.prototype.mouseOver = function (e) {
  1837. try {
  1838. if (this.getTarget(e) == null) return;
  1839. if (!e.ctrlKey) return;
  1840. var el = this.getTarget(e);
  1841. if (el == this.top()._sahi.lastElement){
  1842. return;
  1843. }
  1844. this.top()._sahi.lastElement = el;
  1845. var elInfo = this.identify(el); // _sahi.getAccessorInfo(_sahi.getKnownTags(el));
  1846. if (elInfo.apis.length > 0) acc = elInfo.apis[0];
  1847. else acc = null;
  1848. try {
  1849. if (acc){
  1850. this.sendIdsToController(elInfo, "HOVER");
  1851. // controlWin.main.displayInfo(acc, this.escapeDollar(this.getAccessor1(acc)),
  1852. // this.escapeValue(acc.value), this.getPopupName());
  1853. this.relisten;
  1854. }
  1855. } catch(ex2) {
  1856. throw ex2;
  1857. }
  1858. if (acc) this.top()._sahi.lastAccessedInfo = acc;
  1859. } catch(ex) {
  1860. throw ex;
  1861. }
  1862. };
  1863. /*Sahi.prototype.mouseOver = function (e) {
  1864. try {
  1865. if (this.getTarget(e) == null) return;
  1866. if (!e.ctrlKey) return;
  1867. var controlWin = this.getController();
  1868. if (controlWin) {
  1869. var el = this.getTarget(e);
  1870. if (el == this.top()._sahi.lastElement){
  1871. return;
  1872. }
  1873. this.top()._sahi.lastElement = el;
  1874. var accs = this.identify(el); // _sahi.getAccessorInfo(_sahi.getKnownTags(el));
  1875. if (accs.length > 0) acc = accs[0];
  1876. else acc = null;
  1877. try {
  1878. if (acc) controlWin.main.displayInfo(acc, this.escapeDollar(this.getAccessor1(acc)),
  1879. this.escapeValue(acc.value), this.getPopupName());
  1880. } catch(ex2) {
  1881. throw ex2;
  1882. }
  1883. if (acc) this.top()._sahi.lastAccessedInfo = acc;
  1884. }
  1885. } catch(ex) {
  1886. throw ex;
  1887. }
  1888. };*/
  1889. Sahi.prototype.escapeDollar = function (s) {
  1890. if (s == null) return null;
  1891. return s.replace(/[$]/g, "\\$");
  1892. };
  1893. Sahi.prototype.getAccessor1 = function (info) {
  1894. if (info == null) return null;
  1895. if ("" == (""+info.shortHand) || info.shortHand == null) return null;
  1896. return info.type + "(" + this.escapeForScript(info.shortHand) + ")";
  1897. };
  1898. Sahi.prototype.escapeForScript = function (s) {
  1899. return this.quoteIfString(s);
  1900. };
  1901. Sahi.prototype.schedule = function (cmd, debugInfo) {
  1902. if (!this.cmds) return;
  1903. var i = this.cmds.length;
  1904. this.cmds[i] = cmd;
  1905. this.cmdDebugInfo[i] = debugInfo;
  1906. };
  1907. Sahi.prototype.instant = function (cmd, debugInfo) {
  1908. if (!this.cmds) return;
  1909. var i = this.cmdsLocal.length;
  1910. this.cmdsLocal[i] = cmd;
  1911. this.cmdDebugInfoLocal[i] = debugInfo;
  1912. };
  1913. Sahi.prototype.play = function () {
  1914. var interval = this.waitInterval > 0 && !this.waitCondition ? this.waitInterval : this.INTERVAL;
  1915. this.execNextStep(false, interval);
  1916. };
  1917. Sahi.prototype.areXHRsDone = function (){
  1918. var xs = this.XHRs;
  1919. for (var i=0; i<xs.length; i++){
  1920. var xsi = xs[i];
  1921. //this.d("xsi.readyState="+xsi.readyState)
  1922. if (xsi){
  1923. if (xsi.readyState==2 || xsi.readyState==3){
  1924. // this._debug("xsi.readyState="+xsi.readyState);
  1925. }
  1926. if (xsi.readyState==2) return false;
  1927. if (xsi.readyState==3){
  1928. if (this.waitWhenReadyState3) return false;
  1929. try{
  1930. var m = xsi.responseText;
  1931. }catch(e){return false;}
  1932. }
  1933. }
  1934. }
  1935. return true;
  1936. };
  1937. Sahi.prototype.d = function(s){
  1938. this.updateControlWinDisplay(s);
  1939. };
  1940. Sahi.prototype.areWindowsLoaded = function (win) {
  1941. try {
  1942. if (win.location.href == "about:blank") return true;
  1943. } catch(e) {
  1944. return true;
  1945. // diff domain
  1946. }
  1947. try {
  1948. var fs = win.frames;
  1949. if (!fs || fs.length == 0) {
  1950. try {
  1951. return (win.document.readyState == "complete") || (this.loaded);
  1952. } catch(e) {
  1953. //this.d("**********");
  1954. return true;
  1955. //diff domain; don't bother
  1956. }
  1957. } else {
  1958. if (win.name == "listIframe") this.d("fs.length="+fs.length);
  1959. for (var i = 0; i < fs.length; i++) {
  1960. //this.d("" + i + ") " +fs[i].name);
  1961. try{
  1962. if (""+fs[i].location != "about:blank" && !fs[i]._sahi.areWindowsLoaded(fs[i])) return false;
  1963. }catch(e){
  1964. // skip if error. can happen for ""+fs[i].location if diff domain.
  1965. }
  1966. }
  1967. if (win.document && win.document.getElementsByTagName("frameset").length == 0)
  1968. return this.loaded;
  1969. else return true;
  1970. }
  1971. }
  1972. catch(ex) {
  1973. //this.d("2 to " + ex);
  1974. //this._debugToErr("3 pr " + ex.prototype);
  1975. return true;
  1976. //for diff domains.
  1977. }
  1978. };
  1979. var _isLocal = false;
  1980. Sahi._timer = null;
  1981. Sahi.prototype.execNextStep = function (isStep, interval) {
  1982. if (isStep || !this.isPlaying()) return;
  1983. if (Sahi._timer) window.clearTimeout(Sahi._timer);
  1984. Sahi._timer = window.setTimeout("try{_sahi.ex();}catch(ex){}", interval);
  1985. };
  1986. Sahi.prototype.hasErrors = function () {
  1987. var i = this.sendToServer("/_s_/dyn/Player_hasErrors");
  1988. return i == "true";
  1989. };
  1990. Sahi.prototype.getCurrentStep = function (isStep) {
  1991. var wasOpened = 1;
  1992. var windowName = "";
  1993. var windowTitle = "";
  1994. try{
  1995. wasOpened = (this.top().opener == null || (this.top().opener._sahi.top() == this.top())) ? 0 : 1;
  1996. }catch(e){
  1997. }
  1998. try{
  1999. windowName = this.top().name;
  2000. }catch(e){
  2001. }
  2002. try{
  2003. windowTitle = this.top().document.title;
  2004. }catch(e){
  2005. }
  2006. var v = this.sendToServer("/_s_/dyn/Player_getCurrentStep?derivedName="+this.getPopupName()+
  2007. "&wasOpened="+wasOpened+"&windowName="+encodeURIComponent(windowName)+
  2008. "&windowTitle="+encodeURIComponent(windowTitle) +"&isStep="+(isStep?1:0));
  2009. //this.d(v);
  2010. return eval("(" + v + ")");
  2011. };
  2012. Sahi.prototype.markStepDone = function(stepId, type, failureMsg){
  2013. var qs = "stepId=" + stepId + (failureMsg ? ("&failureMsg=" + encodeURIComponent(failureMsg)) : "") + "&type=" + type;
  2014. this.sendToServer("/_s_/dyn/Player_markStepDone?"+qs);
  2015. };
  2016. Sahi.prototype.markStepInProgress = function(stepId, type){
  2017. var qs = "stepId=" + stepId + "&type=" + type;
  2018. this.sendToServer("/_s_/dyn/Player_markStepInProgress?"+qs);
  2019. };
  2020. Sahi.prototype.skipTill = function(n){
  2021. var lastStepId = -1;
  2022. while(true){
  2023. var stepInfo = this.getCurrentStep(false);
  2024. var stepId = stepInfo['stepId'];
  2025. if (lastStepId == stepId){
  2026. continue;
  2027. }
  2028. lastStepId = stepId;
  2029. var type = stepInfo['type'];
  2030. if (type == "STOP") {
  2031. this.showStopPlayingMessage();
  2032. return;
  2033. }
  2034. var step = stepInfo['step'];
  2035. if (step == null || step == 'null') continue;
  2036. if (stepId < n){
  2037. this.markStepDone(stepId, "skipped");
  2038. }else{
  2039. break;
  2040. }
  2041. }
  2042. };
  2043. Sahi.prototype.ex = function (isStep) {
  2044. var stepId = -1;
  2045. try{
  2046. //if (this.isPaused() && !isStep) return;
  2047. if (this.waitCondition) {
  2048. var again = true;
  2049. try {
  2050. if (eval(this.waitCondition)) {
  2051. again = false;
  2052. _sahi.cancelWaitCondition();
  2053. }
  2054. } catch(e1) {
  2055. }
  2056. if (again) {
  2057. this.execNextStep(isStep, this.interval);
  2058. return;
  2059. }
  2060. }
  2061. if ((!this.areWindowsLoaded(this.top()) || !this.areXHRsDone()) && this.waitForLoad > 0){
  2062. this.waitForLoad = this.waitForLoad - 1;
  2063. if (!this.isIE() && this.waitForLoad % 20 == 0){
  2064. this.check204Response();
  2065. }
  2066. this.execNextStep(isStep, this.interval);
  2067. return;
  2068. }
  2069. this.waitForLoad = this.SAHI_MAX_WAIT_FOR_LOAD;
  2070. if (this.__jsError){
  2071. var msg = this.getJSErrorMessage(this.__jsError);
  2072. this._log(msg, "custom1");
  2073. this.d(this.__jsError.message);
  2074. this.__jsError = null;
  2075. }
  2076. var stepInfo = this.getCurrentStep(isStep);
  2077. // this._alert(stepInfo['step'] +": " +stepInfo['type']+ ": " +stepInfo['stepId']);
  2078. var type = stepInfo['type'];
  2079. if (type == "STOP") {
  2080. this.showStopPlayingMessage();
  2081. //this.stopPlaying();
  2082. return;
  2083. }
  2084. if (type == "PAUSED"){
  2085. return;
  2086. }
  2087. var step = stepInfo['step'];
  2088. if (step == null || step == 'null' || type == "WAIT"){
  2089. this.execNextStep(isStep, this.interval);
  2090. return;
  2091. }
  2092. stepId = stepInfo['stepId'];
  2093. if (this.lastStepId == stepId){
  2094. this.execNextStep(isStep, this.interval);
  2095. return;
  2096. }
  2097. var debugInfo = stepInfo['debugInfo'];
  2098. var origStep = stepInfo['origStep'];
  2099. if (type == 'JSERROR'){
  2100. this.updateControlWinDisplay("Error in script: "+origStep+"\nLogs may have details.");
  2101. return;
  2102. }
  2103. var status = (step.indexOf("_sahi._assert") != -1) ? "success" : "info";
  2104. this.markStepInProgress(stepId, status);
  2105. this.updateControlWinDisplay(origStep, stepId);
  2106. eval(step);
  2107. this.lastStepId = stepId;
  2108. this.markStepDone(stepId, status);
  2109. this.interval = this.waitInterval >= 0 ? this.waitInterval : this.INTERVAL;
  2110. this.waitInterval = -1;
  2111. this.execNextStep(isStep, this.interval);
  2112. }catch(e){
  2113. var retries = this.getRetries();
  2114. if (retries < this.MAX_RETRIES) {
  2115. retries = retries + 1;
  2116. this.setRetries(retries);
  2117. this.interval = this.ONERROR_INTERVAL; //100 * (2^retries);
  2118. this.execNextStep(isStep, this.interval);
  2119. return;
  2120. } else {
  2121. if (e instanceof SahiAssertionException){
  2122. var failureMsg = "Assertion Failed. " + (e.messageText ? e.messageText : "");
  2123. this.setRetries(0);
  2124. this.markStepDone(stepId, "failure", failureMsg);
  2125. this.execNextStep(isStep, this.interval);
  2126. } else {
  2127. if (this.isPlaying()) {
  2128. var msg = this.getJSErrorMessage(e);
  2129. this.markStepDone(stepId, "error", msg);
  2130. }
  2131. this.execNextStep(isStep, this.interval);
  2132. }
  2133. }
  2134. }
  2135. };
  2136. Sahi.prototype.getJSErrorMessage2 = function(msg, lineNumber){
  2137. var url = "/_s_/dyn/Log_getBrowserScript?href="+this.__scriptPath+"&n="+lineNumber;
  2138. msg += "\n<a href='"+url+"'><b>Click for browser script</b></a>";
  2139. return msg;
  2140. };
  2141. Sahi.prototype.getJSErrorMessage = function(e){
  2142. var msg = this.getExceptionString(e);
  2143. var lineNumber = (e.lineNumber) ? e.lineNumber : -1;
  2144. return this.getJSErrorMessage2(msg, lineNumber);
  2145. };
  2146. Sahi.prototype.check204Response = function(){
  2147. var last = this._lastDownloadedFileName()
  2148. if (last != null && last != this.lastDownloaded){
  2149. this.lastDownloaded = last;
  2150. this.loaded = true;
  2151. }
  2152. };
  2153. Sahi.prototype.xcanEvalInBase = function (cmd) {
  2154. return (this.top().opener == null && !this.isForPopup(cmd)) || (this.top().opener && this.top().opener._sahi.top() == this.top());
  2155. };
  2156. Sahi.prototype.xisForPopup = function (cmd) {
  2157. return cmd.indexOf("_sahi._popup") == 0;
  2158. };
  2159. Sahi.prototype.xcanEval = function (cmd) {
  2160. return (this.top().opener == null && !this.isForPopup(cmd)) // for base window
  2161. || (this.top().opener && this.top().opener._sahi.top() == this.top()) // for links in firefox
  2162. || (this.top().opener != null && this.isForPopup(cmd));
  2163. // for popups
  2164. };
  2165. /*
  2166. Sahi.prototype.pause = function () {
  2167. this._isPaused = true;
  2168. this.setServerVar("sahi_paused", 1);
  2169. };
  2170. Sahi.prototype.unpause = function () {
  2171. // TODO
  2172. this._isPaused = false;
  2173. this.setServerVar("sahi_paused", 0);
  2174. this._isPlaying = true;
  2175. };
  2176. */
  2177. Sahi.prototype.isPaused = function () {
  2178. return false;
  2179. if (this._isPaused == null)
  2180. this._isPaused = this.getServerVar("sahi_paused") == 1;
  2181. return this._isPaused;
  2182. };
  2183. Sahi.prototype.updateControlWinDisplay = function (s, i) {
  2184. this.setServerVarAsync("CONTROLLER_Playback_Log", this.toJSON({step: s.replace(/_sahi[.]/g, ""), id:i})+"\n", false, true);
  2185. this.sendToController("", "PLAYBACK_LOG_REFRESH");
  2186. // try {
  2187. // var controlWin = this.getController();
  2188. // if (controlWin && !controlWin.closed) {
  2189. // // controller2.js checks if this i has already been displayed.
  2190. // controlWin.main.displayLogs(s.replace(/_sahi[.]/g, ""), i);
  2191. // if (i != null) controlWin.main.displayStepNum(i);
  2192. // }
  2193. // } catch(ex) {
  2194. // }
  2195. };
  2196. Sahi.prototype.setCurrentIndex = function (i) {
  2197. this.startFromStep = i;
  2198. return;
  2199. if (_isLocal) {
  2200. this.setServerVar("this.localIx", i);
  2201. }
  2202. else this.setServerVar("this.ix", i);
  2203. };
  2204. Sahi.prototype.xgetCurrentIndex = function () {
  2205. if (this.cmdsLocal.length > 0) {
  2206. var i = parseInt(this.getServerVar("this.localIx"));
  2207. var localIx = ("" + i != "NaN") ? i : 0;
  2208. if (this.cmdsLocal.length == localIx) {
  2209. this.cmdsLocal = new Array();
  2210. this.setServerVar("this.localIx", 0);
  2211. _isLocal = false;
  2212. } else {
  2213. return localIx;
  2214. }
  2215. }
  2216. var i = parseInt(this.getServerVar("this.ix"));
  2217. return ("" + i != "NaN") ? i : 0;
  2218. };
  2219. Sahi.prototype.isPlaying = function () {
  2220. if (this._isPlaying == null){
  2221. this._isPlaying = this.sendToServer("/_s_/dyn/Player_isPlaying") == "1";
  2222. }
  2223. return this._isPlaying;
  2224. };
  2225. Sahi.prototype.playManual = function (ix) {
  2226. this.skipTill(ix);
  2227. //this.setCurrentIndex(ix);
  2228. //this.unpause();
  2229. this._isPlaying = true;
  2230. this.ex();
  2231. };
  2232. Sahi.prototype.startPlaying = function () {
  2233. this.sendToServer("/_s_/dyn/Player_start");
  2234. };
  2235. Sahi.prototype.stepWisePlay = function () {
  2236. this.sendToServer("/_s_/dyn/Player_stepWisePlay");
  2237. };
  2238. Sahi.prototype.showStopPlayingMessage = function () {
  2239. this.updateControlWinDisplay("--Stopped Playback: " + (this.hasErrors() ? "FAILURE" : "SUCCESS") + "--", "-");
  2240. };
  2241. Sahi.prototype.stopPlaying = function () {
  2242. this.sendToServer("/_s_/dyn/Player_stop");
  2243. this.showStopPlayingMessage();
  2244. this._isPlaying = false;
  2245. };
  2246. Sahi.prototype.startRecording = function () {
  2247. this._isRecording = true;
  2248. this.addHandlersToAllFrames(this.top());
  2249. this.setServerVar("sahi_record", 1);
  2250. };
  2251. Sahi.prototype.stopRecording = function () {
  2252. this.setServerVar("sahi_record", 0);
  2253. this._isRecording = false;
  2254. // this.sendToServer("/_s_/dyn/Recorder_stop");
  2255. };
  2256. Sahi.prototype.getLogQS = function (msg, type, debugInfo, failureMsg) {
  2257. var qs = "msg=" + encodeURIComponent(msg) + "&type=" + type
  2258. + (debugInfo ? "&debugInfo=" + encodeURIComponent(debugInfo) : "")
  2259. + (failureMsg ? "&failureMsg=" + encodeURIComponent(failureMsg) : "");
  2260. return qs;
  2261. };
  2262. Sahi.prototype.logPlayBack = function (msg, type, debugInfo, failureMsg) {
  2263. this.sendToServer("/_s_/dyn/TestReporter_logTestResult?"+this.getLogQS(msg, type, debugInfo, failureMsg));
  2264. };
  2265. Sahi.prototype.trim = function (s) {
  2266. if (s == null) return s;
  2267. if ((typeof s) != "string") return s;
  2268. s = s.replace(/&nbsp;/g, ' ');
  2269. s = s.replace(/\xA0/g, ' ');
  2270. s = s.replace(/^[ \t\n\r]*/g, '');
  2271. s = s.replace(/[ \t\n\r]*$/g, '');
  2272. s = s.replace(/[ \t\n\r]{1,}/g, ' ');
  2273. return s;
  2274. };
  2275. Sahi.prototype.list = function (el) {
  2276. var s = "";
  2277. var f = "";
  2278. var j = 0;
  2279. if (typeof el == "array"){
  2280. for (var i=0; i<el.length; i++) {
  2281. s += i + "=" + el[i];
  2282. }
  2283. }
  2284. if (typeof el == "object") {
  2285. for (var i in el) {
  2286. try {
  2287. if (el[i] && el[i] != el) {
  2288. if (("" + el[i]).indexOf("function") == 0) {
  2289. f += i + "\n";
  2290. } else {
  2291. if (typeof el[i] == "object" && el[i] != el.parentNode) {
  2292. s += i + "={{" + el[i] + "}};\n";
  2293. }
  2294. s += i + "=" + el[i] + ";\n";
  2295. j++;
  2296. }
  2297. }
  2298. } catch(e) {
  2299. s += "" + i + "\n";
  2300. }
  2301. }
  2302. } else {
  2303. s += el;
  2304. }
  2305. return s + "\n\n-----Functions------\n\n" + f;
  2306. };
  2307. Sahi.prototype.findInArray = function (ar, el) {
  2308. var len = ar.length;
  2309. for (var i = 0; i < len; i++) {
  2310. if (ar[i] == el) return i;
  2311. }
  2312. return -1;
  2313. };
  2314. Sahi.prototype.isIE = function () {return navigator.appName == "Microsoft Internet Explorer";};
  2315. Sahi.prototype.isFF3 = function () {return navigator.userAgent.match(/Firefox\/3/) != null;};
  2316. Sahi.prototype.isFF = function () {return navigator.userAgent.match(/Firefox/) != null;};
  2317. Sahi.prototype.isChrome = function () {return navigator.userAgent.match(/Chrome/) != null;};
  2318. Sahi.prototype.createRequestObject = function () {
  2319. var obj;
  2320. if (window.XMLHttpRequest){
  2321. // If IE7, Mozilla, Safari, etc: Use native object
  2322. obj = new XMLHttpRequest()
  2323. }else {
  2324. if (window.ActiveXObject){
  2325. // ...otherwise, use the ActiveX control for IE5.x and IE6
  2326. obj = new ActiveXObject("Microsoft.XMLHTTP");
  2327. }
  2328. }
  2329. return obj;
  2330. };
  2331. Sahi.prototype.getAndDeleteServerVar = function (name, isGlobal) {
  2332. return this.getServerVar(name, isGlobal, true);
  2333. };
  2334. Sahi.prototype.getServerVar = function (name, isGlobal, isDelete) {
  2335. var v = this.sendToServer("/_s_/dyn/SessionState_getVar?name=" + encodeURIComponent(name)
  2336. + "&isglobal="+(isGlobal?1:0)
  2337. + "&isdelete="+(isDelete?1:0));
  2338. return eval("(" + v + ")");
  2339. };
  2340. Sahi.prototype.setServerVarAsync = function (name, value, isGlobal, append) {
  2341. this.sendToServer(this.getSetServerVarURL(name, value, isGlobal, append), true);
  2342. };
  2343. Sahi.prototype.setServerVar = function (name, value, isGlobal, append) {
  2344. this.sendToServer(this.getSetServerVarURL(name, value, isGlobal, append));
  2345. };
  2346. Sahi.prototype.getSetServerVarURL = function (name, value, isGlobal, append) {
  2347. var url = "/_s_/dyn/SessionState_setVar?" +
  2348. "name=" + encodeURIComponent(name) +
  2349. "&value=" + encodeURIComponent(this.toJSON(value)) +
  2350. "&append=" + (append?1:0) +
  2351. "&isglobal="+(isGlobal?1:0);
  2352. // alert(url);
  2353. return url;
  2354. };
  2355. Sahi.prototype.logErr = function (msg) {
  2356. // return;
  2357. this.sendToServer("/_s_/dyn/Log?msg=" + encodeURIComponent(msg) + "&type=err");
  2358. };
  2359. Sahi.prototype.getParentNode = function (el, tagName, occurrence) {
  2360. if (!occurrence) occurrence = 1;
  2361. var cnt = 0;
  2362. var parent = el.parentNode;
  2363. var tagNameUC = tagName.toUpperCase();
  2364. while (parent && parent.tagName.toLowerCase() != "body" && parent.tagName.toLowerCase() != "html") {
  2365. if (tagNameUC == "ANY" || parent.tagName == tagNameUC) {
  2366. cnt++;
  2367. if (occurrence == cnt) return parent;
  2368. }
  2369. parent = parent.parentNode;
  2370. }
  2371. return null;
  2372. };
  2373. Sahi.prototype.sendToServer = function (url, async, throwEx) {
  2374. try {
  2375. var rand = (new Date()).getTime() + Math.floor(Math.random() * (10000));
  2376. var http = this.createRequestObject();
  2377. url = url + (url.indexOf("?") == -1 ? "?" : "&") + "t=" + rand;
  2378. var post = url.substring(url.indexOf("?") + 1);
  2379. url = url.substring(0, url.indexOf("?"));
  2380. http.open("POST", url, async ? true: false);
  2381. http.send(post);
  2382. return async ? null : http.responseText;
  2383. } catch(ex) {
  2384. if (throwEx) throw ex;
  2385. else this.handleException(ex);
  2386. }
  2387. };
  2388. var s_v = function (v) {
  2389. var type = typeof v;
  2390. if (type == "number") return v;
  2391. else if (type == "string") return "\"" + v.replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/"/g, '\\"') + "\"";
  2392. else return v;
  2393. };
  2394. Sahi.prototype.quoted = function (s) {
  2395. return '"' + s.replace(/"/g, '\\"') + '"';
  2396. };
  2397. Sahi.prototype.handleException = function (e) {
  2398. // alert(e);
  2399. // throw e;
  2400. };
  2401. Sahi.prototype.convertUnicode = function (source) {
  2402. if (source == null) return null;
  2403. var result = '';
  2404. for (var i = 0; i < source.length; i++) {
  2405. if (source.charCodeAt(i) > 127)
  2406. result += this.addSlashU(source.charCodeAt(i).toString(16));
  2407. else result += source.charAt(i);
  2408. }
  2409. return result;
  2410. };
  2411. Sahi.prototype.addSlashU = function (num) {
  2412. var buildU;
  2413. switch (num.length) {
  2414. case 1:
  2415. buildU = "\\u000" + num;
  2416. break;
  2417. case 2:
  2418. buildU = "\\u00" + num;
  2419. break;
  2420. case 3:
  2421. buildU = "\\u0" + num;
  2422. break;
  2423. case 4:
  2424. buildU = "\\u" + num;
  2425. break;
  2426. }
  2427. return buildU;
  2428. };
  2429. Sahi.prototype.onBeforeUnLoad = function () {
  2430. this.loaded = false;
  2431. };
  2432. Sahi.prototype.init = function (e) {
  2433. try {
  2434. this.loaded = true;
  2435. this.activateHotKey();
  2436. } catch(ex) {
  2437. this.handleException(ex);
  2438. }
  2439. this.prepareADs();
  2440. if (this.waitInterval > 0){
  2441. if (this.waitCondition){
  2442. this._wait(this.waitInterval, this.waitCondition);
  2443. }else {
  2444. this._wait(this.waitInterval);
  2445. }
  2446. }
  2447. try {
  2448. if (self == this.top()) {
  2449. this.play();
  2450. }
  2451. if (this.isRecording()) {
  2452. this.addHandlersToAllFrames(this.top());
  2453. }
  2454. } catch(ex) {
  2455. // throw ex;
  2456. this.handleException(ex);
  2457. }
  2458. // alert("Cookies: " + document.domain + " " + document.cookie);
  2459. this.listen();
  2460. };
  2461. Sahi.prototype.setSessionCookie = function(){
  2462. this.createCookie('sahisid', this.sid);
  2463. };
  2464. Sahi.prototype.activateHotKey = function () {
  2465. try {
  2466. this.addEvent(document, "dblclick", Sahi.openControllerWindow);
  2467. this.addWrappedEvent(document, "dblclick", this.relisten);
  2468. this.addEvent(document, "mousemove", function(e){_sahi.mouseOver(e)});
  2469. if (this.isSafariLike()) {
  2470. var prev = window.document.ondblclick;
  2471. window.document.ondblclick = function(e) {
  2472. if (prev != null) prev(e);
  2473. this.openControllerWindow(e)
  2474. };
  2475. }
  2476. } catch(ex) {
  2477. this.handleException(ex);
  2478. }
  2479. };
  2480. Sahi.prototype.isFirstExecutableFrame = function () {
  2481. var fs = this.top().frames;
  2482. for (var i = 0; i < fs.length; i++) {
  2483. if (self == this.top().frames[i]) return true;
  2484. if ("" + (typeof this.top().frames[i].location) != "undefined") { // = undefined when previous frames are not accessible due to some reason (may be from diff domain)
  2485. return false;
  2486. }
  2487. }
  2488. return false;
  2489. };
  2490. Sahi.prototype.getScript = function (info) {
  2491. var accessor = this.escapeDollar(this.getAccessor1(info));
  2492. if (accessor == null) return null;
  2493. var ev = info.event;
  2494. var value = info.value;
  2495. var type = info.type;
  2496. var popup = this.getPopupName();
  2497. var cmd = null;
  2498. if (value == null)
  2499. value = "";
  2500. if (ev == "load") {
  2501. cmd = "_wait(2000);";
  2502. } else if (ev == "_click") {
  2503. cmd = "_click(" + accessor + ");";
  2504. } else if (ev == "_setValue") {
  2505. cmd = "_setValue(" + accessor + ", " + this.quotedEscapeValue(value) + ");";
  2506. } else if (ev == "_setSelected") {
  2507. cmd = "_setSelected(" + accessor + ", " + this.quotedEscapeValue(value) + ");";
  2508. } else if (ev == "assert") {
  2509. cmd = "_assertExists(" + accessor + ");\r\n";
  2510. if (type == "_cell") {
  2511. this._debug(info.shortHand + " " + this.quotedEscapeValue(value));
  2512. if (info.shortHand != this.quotedEscapeValue(value)){
  2513. cmd += "_assertEqual(" + this.quotedEscapeValue(value) + ", _getText(" + accessor + "));\n";
  2514. cmd += "_assertContainsText(" + this.quotedEscapeValue(value) + ", " + accessor + ");";
  2515. }
  2516. } else if (type == "_select") {
  2517. cmd += "_assertEqual(" + this.quotedEscapeValue(value) + ", _getSelectedText(" + accessor + "));";
  2518. } else if (type == "_textbox" || type == "_textarea" || type == "_password") {
  2519. cmd += "_assertEqual(" + this.quotedEscapeValue(value) + ", " + accessor + ".value);";
  2520. } else if (type == "_checkbox" || type == "_radio") {
  2521. cmd += "_assert" + ("true" == ("" + value) ? "" : "NotTrue" ) + "(" + accessor + ".checked);";
  2522. } else if (type != "_link" && type != "_image") {
  2523. if (info.shortHand != this.quotedEscapeValue(value)){
  2524. cmd += "_assertContainsText(" + this.quotedEscapeValue(value) + ", " + accessor + ");";
  2525. }
  2526. }
  2527. } else if (ev == "wait") {
  2528. cmd = "_wait(" + value + ");";
  2529. } else if (ev == "mark") {
  2530. cmd = "//MARK: " + value;
  2531. } else if (ev == "_setFile") {
  2532. cmd = "_setFile(" + accessor + ", " + this.quotedEscapeValue(value) + ");";
  2533. }
  2534. if (cmd != null && popup != null && popup != "") {
  2535. cmd = "_popup(\"" + popup + "\")." + cmd;
  2536. cmd = cmd.replace(/[\n]_assert/g, "\n_popup(\"" + popup + "\")._assert")
  2537. }
  2538. return cmd;
  2539. };
  2540. Sahi.prototype.quotedEscapeValue = function (s) {
  2541. return this.quoted(this.escapeValue(s));
  2542. };
  2543. Sahi.prototype.escapeValue = function (s) {
  2544. if (s == null || typeof s != "string") return s;
  2545. return this.convertUnicode(s.replace(/\r/g, "").replace(/\\/g, "\\\\").replace(/\n/g, "\\n"));
  2546. };
  2547. Sahi.prototype.escape = function (s) {
  2548. if (s == null) return s;
  2549. return escape(s).replace(/[+]/g, "%2B");
  2550. };
  2551. Sahi.prototype.saveCondition = function (a) {
  2552. this.setServerVar("condn", a ? "true" : "false");
  2553. //this.resetCmds();
  2554. };
  2555. Sahi.prototype.resetCmds = function(){
  2556. this.cmds = new Array();
  2557. this.cmdDebugInfo = new Array();
  2558. this.scriptScope();
  2559. };
  2560. Sahi.prototype.handleSet = function(varName, value){
  2561. this.setServerVar(varName, value);
  2562. //this.resetCmds();
  2563. };
  2564. Sahi.prototype.quoteIfString = function (shortHand) {
  2565. // if (("" + shortHand).match(/^[0-9]+$/)) return shortHand;
  2566. if (typeof shortHand == "number") return shortHand;
  2567. return this.quotedEscapeValue(shortHand);
  2568. };
  2569. Sahi.prototype._execute = function (command, sync) {
  2570. var is_sync = sync ? "true" : "false";
  2571. var status = this._callServer("CommandInvoker_execute", "command=" + encodeURIComponent(command) + "&sync=" + is_sync);
  2572. if ("success" != status) {
  2573. throw new Error("Execute Command Failed!");
  2574. }
  2575. };
  2576. Sahi.prototype.activateHotKey();
  2577. Sahi.prototype._style = function (el, style) {
  2578. var value = el.style[this.toCamelCase(style)];
  2579. if (!value){
  2580. if (el.ownerDocument && el.ownerDocument.defaultView) // FF
  2581. value = el.ownerDocument.defaultView.getComputedStyle(el, "").getPropertyValue(style);
  2582. else if (el.currentStyle)
  2583. value = el.currentStyle[this.toCamelCase(style)];
  2584. }
  2585. return value;
  2586. };
  2587. Sahi.prototype.toCamelCase = function (s) {
  2588. var exp = /-([a-z])/
  2589. for (;exp.test(s); s = s.replace(exp, RegExp.$1.toUpperCase()));
  2590. return s;
  2591. };
  2592. Sahi.prototype.setWaitCondition = function(waitCondn) {
  2593. if (!String.isBlankOrNull(waitCondn) && waitCondn != "null") {
  2594. this.waitCondition = waitCondn;
  2595. }
  2596. };
  2597. Sahi.prototype.setWaitConditionTime = function(time) {
  2598. if (!String.isBlankOrNull(time) && time != "-1") {
  2599. var diff = eval(time) - new Date().valueOf();
  2600. this.waitInterval = (diff > 0) ? diff : -1;
  2601. }
  2602. };
  2603. // document.write start
  2604. Sahi.INSERT_TEXT = "<script src='/_s_/spr/concat.js'></scr"+"ipt>"+
  2605. "<script src='http://sahi.example.com/_s_/dyn/SessionState/state.js'></scr"+"ipt>"+
  2606. "<script src='http://sahi.example.com/_s_/dyn/Player_script/script.js'></scr"+"ipt>"+
  2607. "<script src='/_s_/spr/playback.js'></scr"+"ipt>" +
  2608. "";
  2609. Sahi.prototype.ieDocClose = function(){
  2610. this.oldDocWrite(this.sahiBuffer);
  2611. window.document.write(Sahi.INSERT_TEXT);
  2612. window.document.close();
  2613. this.loaded = true;
  2614. this.play();
  2615. };
  2616. Sahi.prototype.ieDocWrite = function(s){
  2617. this.sahiBuffer += s;
  2618. }
  2619. if (false && _sahi.isIE()){ // Do not move into method.
  2620. Sahi.prototype.oldDocWrite = window.document.write;
  2621. window.document.write = function (s) {_sahi.ieDocWrite(s);};
  2622. window.document.close = function () {_sahi.ieDocClose();};
  2623. };
  2624. //--
  2625. Sahi.prototype.ffDocClose = function(){
  2626. this.oldDocWrite.apply(document, [this.sahiBuffer + Sahi.INSERT_TEXT]);
  2627. this.oldDocClose.apply(document);
  2628. this.loaded = true;
  2629. this.play();
  2630. };
  2631. Sahi.prototype.ffDocWrite = function(s){
  2632. this.sahiBuffer += s;
  2633. };
  2634. if (!_sahi.isIE()) {
  2635. // Sahi.prototype.oldDocWrite = document.write;
  2636. // document.write = function (s) {_sahi.ffDocWrite(s);};
  2637. // Sahi.prototype.oldDocClose = document.close;
  2638. // document.close = function () {_sahi.ffDocClose();};
  2639. }
  2640. // document.write end
  2641. Sahi.init = function(e){
  2642. eval("_sahi.init()");
  2643. };
  2644. Sahi.onBeforeUnLoad = function(e){
  2645. _sahi.onBeforeUnLoad(e);
  2646. };
  2647. // ff xhr start
  2648. if (!_sahi.isIE()){
  2649. var d = new XMLHttpRequest();
  2650. d.constructor.prototype.openOld = XMLHttpRequest.prototype.open;
  2651. d.constructor.prototype.open = function(method, url, async, username, password){
  2652. url = ""+url;
  2653. var opened = this.openOld(method, url, async, username, password);
  2654. if (url.indexOf("/_s_/") == -1){
  2655. //_sahi.d("xhr url="+url);
  2656. try{
  2657. var xs = _sahi.top()._sahi.XHRs;
  2658. xs[xs.length] = this;
  2659. }catch(e){
  2660. _sahi._debug("concat.js: Diff domain: Could not add XHR to list for automatic monitoring "+e);
  2661. }
  2662. this.setRequestHeader("sahi-isxhr", "true");
  2663. }
  2664. return opened;
  2665. }
  2666. new_ActiveXObject = function(s){ // Some custom implementation of ActiveXObject
  2667. return new ActiveXObject(s);
  2668. }
  2669. }else{
  2670. new_ActiveXObject = function(s){
  2671. var lower = s.toLowerCase();
  2672. if (lower.indexOf("microsoft.xmlhttp")!=-1 || lower.indexOf("msxml2.xmlhttp")!=-1){
  2673. return new SahiXHRWrapper(s, true);
  2674. }else{
  2675. return new ActiveXObject(s);
  2676. }
  2677. }
  2678. }
  2679. // ff xhr end
  2680. SahiXHRWrapper = function (s, isActiveX){
  2681. //_sahi.real_alert("inside SahiXHRWrapper");
  2682. this.xhr = isActiveX ? new ActiveXObject(s) : new real_XMLHttpRequest();
  2683. var xs = _sahi.top()._sahi.XHRs;
  2684. xs[xs.length] = this;
  2685. this._async = false;
  2686. };
  2687. SahiXHRWrapper.prototype.open = function(method, url, async, username, password){
  2688. url = ""+url;
  2689. this._async = async;
  2690. var opened = this.xhr.open(method, url, async, username, password);
  2691. if (url.indexOf("/_s_/") == -1){
  2692. try{
  2693. var xs = _sahi.top()._sahi.XHRs;
  2694. xs[xs.length] = this;
  2695. }catch(e){}
  2696. this.xhr.setRequestHeader("sahi-isxhr", "true");
  2697. }
  2698. var fn = this.stateChange;
  2699. var obj = this;
  2700. this.xhr.onreadystatechange = function(){fn.apply(obj, arguments);};
  2701. return opened;
  2702. };
  2703. SahiXHRWrapper.prototype.getAllResponseHeaders = function(){
  2704. return this.xhr.getAllResponseHeaders();
  2705. };
  2706. SahiXHRWrapper.prototype.getResponseHeader = function(s){
  2707. return this.xhr.getResponseHeader(s);
  2708. };
  2709. SahiXHRWrapper.prototype.setRequestHeader = function(k, v){
  2710. return this.xhr.setRequestHeader(k, v);
  2711. };
  2712. SahiXHRWrapper.prototype.send = function(s){
  2713. var sent = this.xhr.send(s);
  2714. if (!this._async) this.populateProps();
  2715. return sent;
  2716. };
  2717. SahiXHRWrapper.prototype.stateChange = function(){
  2718. this.readyState = this.xhr.readyState;
  2719. if (this.readyState==4){
  2720. this.populateProps();
  2721. }
  2722. if (this.onreadystatechange) this.onreadystatechange();
  2723. };
  2724. SahiXHRWrapper.prototype.populateProps = function(){
  2725. this.responseText = this.xhr.responseText;
  2726. this.responseXML = this.xhr.responseXML;
  2727. this.status = this.xhr.status;
  2728. this.statusText = this.xhr.statusText;
  2729. };
  2730. if (_sahi.isIE() && typeof XMLHttpRequest != "undefined"){
  2731. window.real_XMLHttpRequest = XMLHttpRequest;
  2732. XMLHttpRequest = SahiXHRWrapper;
  2733. }
  2734. Sahi.prototype.toJSON = function(el){
  2735. if (el == null || el == undefined) return 'null';
  2736. if (el instanceof Date){
  2737. return String(el);
  2738. }else if (typeof el == 'string'){
  2739. if (/["\\\x00-\x1f]/.test(el)) {
  2740. return '"' + el.replace(/([\x00-\x1f\\"])/g, function (a, b) {
  2741. var c = _sahi.escapeMap[b];
  2742. if (c) {
  2743. return c;
  2744. }
  2745. c = b.charCodeAt();
  2746. return '\\u00' +
  2747. Math.floor(c / 16).toString(16) +
  2748. (c % 16).toString(16);
  2749. }) + '"';
  2750. }
  2751. return '"' + el + '"';
  2752. }else if (el instanceof Array){
  2753. var ar = [];
  2754. for (var i=0; i<el.length; i++){
  2755. ar[i] = this.toJSON(el[i]);
  2756. }
  2757. return '[' + ar.join(',') + ']';
  2758. }else if (typeof el == 'number'){
  2759. return new String(el);
  2760. }else if (typeof el == 'boolean'){
  2761. return String(el);
  2762. }else if (el instanceof Object){
  2763. var ar = [];
  2764. for (var k in el){
  2765. var v = el[k];
  2766. if (typeof v != 'function'){
  2767. ar[ar.length] = this.toJSON(k) + ':' + this.toJSON(v);
  2768. }
  2769. }
  2770. return '{' + ar.join(',') + '}';
  2771. }
  2772. };
  2773. Sahi.prototype.isIgnorableId = function(id){
  2774. // zkoss, extjs, xilinus, gmail
  2775. return id.match(/^z_/) || id.match(/^j_id/) || id.match(/^ext[-]gen/) || id.match(/^[:]/);
  2776. // || id.match(/_[0-9]{10,}_/);
  2777. };
  2778. Sahi.prototype.iframeFromStr = function(iframe){
  2779. if (typeof iframe == "string") return this._byId(iframe);
  2780. return iframe;
  2781. };
  2782. Sahi.prototype._rteWrite = function(iframe, s){
  2783. this.iframeFromStr(iframe).contentWindow.document.body.innerHTML = s;
  2784. };
  2785. Sahi.prototype._rteHTML = function(iframe){
  2786. return this.iframeFromStr(iframe).contentWindow.document.body.innerHTML;
  2787. };
  2788. Sahi.prototype._rteText = function(iframe){
  2789. return this._getText(this.iframeFromStr(iframe).contentWindow.document.body);
  2790. };
  2791. Sahi.prototype._re = function(s){
  2792. return eval("/"+s.replace(/\s+/g, '\\s+')+"/");
  2793. };
  2794. Sahi.prototype._scriptName = function(){
  2795. return this.__scriptName;
  2796. };
  2797. Sahi.prototype._scriptPath = function(){
  2798. return this.__scriptPath;
  2799. };
  2800. Sahi.prototype._parentNode = function (el, tagName, occurrence){
  2801. if (tagName == null && occurrence == null){
  2802. tagName = "ANY";
  2803. } else if (typeof(tagName) == "number") {
  2804. occurrence = tagName;
  2805. tagName = "ANY";
  2806. }
  2807. return this.getParentNode(el, tagName, occurrence);
  2808. };
  2809. Sahi.prototype._parentCell = function(el, occurrence){
  2810. return this._parentNode(el, "TD", occurrence);
  2811. };
  2812. Sahi.prototype._parentRow = function(el, occurrence){
  2813. return this._parentNode(el, "TR", occurrence);
  2814. };
  2815. Sahi.prototype._parentTable = function(el, occurrence){
  2816. return this._parentNode(el, "TABLE", occurrence);
  2817. };
  2818. Sahi.prototype.getDoc = function(win){
  2819. if (win.type){
  2820. if (win.type == "_in") return win.element;
  2821. if (win.type == "_near"){
  2822. var parents = [];
  2823. for (var i=1; i<7; i++){
  2824. parents[parents.length] = this.getParentNode(win.element, "ANY", i);
  2825. }
  2826. return new SahiDocProxy(parents);
  2827. }
  2828. }else{
  2829. return win.document;
  2830. }
  2831. };
  2832. SahiDocProxy = function(nodes){
  2833. this.nodes = nodes;
  2834. };
  2835. SahiDocProxy.prototype.getElementsByTagName = function(tag){
  2836. var tags = [];
  2837. for (var i=0; i<this.nodes.length; i++){
  2838. if (this.nodes[i] == null) continue;
  2839. var childNodes = this.nodes[i].getElementsByTagName(tag);
  2840. for (var j=0; j<childNodes.length; j++){
  2841. var childNode = childNodes[j];
  2842. var alreadyAdded = false;
  2843. for (var k=0; k<tags.length; k++){
  2844. if (tags[k] === childNode){
  2845. alreadyAdded = true;
  2846. break;
  2847. }
  2848. }
  2849. if (!alreadyAdded){
  2850. tags[tags.length] = childNode;
  2851. }
  2852. }
  2853. }
  2854. return tags;
  2855. };
  2856. Sahi.prototype._in = function(el){
  2857. return {"element":el, "type":"_in"};
  2858. };
  2859. Sahi.prototype._near = function(el){
  2860. return {"element":el, "type":"_near"};
  2861. };
  2862. Sahi.prototype.addSahi = function(s) {
  2863. return this.sendToServer("/_s_/dyn/ControllerUI_getSahiScript?code=" + encodeURIComponent(s));
  2864. };
  2865. Sahi.prevOnError = window.onerror;
  2866. window.onerror = Sahi.onError;
  2867. Sahi.prototype.addADAr = function(a){
  2868. this.ADs[this.ADs.length] = a;
  2869. };
  2870. Sahi.prototype.getAD = function(el){
  2871. var defs = [];
  2872. for (var i=0; i<this.ADs.length; i++){
  2873. var d = this.ADs[i];
  2874. if (d.tag == el.tagName){
  2875. if (!el.type) defs[defs.length] = d;
  2876. else if (!d.type || el.type == d.type) defs[defs.length] = d;
  2877. }
  2878. }
  2879. return defs;
  2880. };
  2881. Sahi.prototype.addAD = function(a){
  2882. this.addADAr(a);
  2883. var old = Sahi.prototype[a.name];
  2884. var newFn = function(identifier, inEl){
  2885. if (!inEl) inEl = this.top();
  2886. if (old) {
  2887. var el = old.apply(this, [identifier, inEl]);
  2888. if (el) return el;
  2889. }
  2890. for (var i=0; i<a.attributes.length; i++){
  2891. var res = this.getBlankResult();
  2892. if (a.type){
  2893. var el = this.findElementHelper(identifier, inEl, a.type, res, a.attributes[i], a.tag).element;
  2894. } else {
  2895. var el = this.findTagHelper(identifier, inEl, a.tag, res, a.attributes[i]).element;
  2896. }
  2897. if (el != null) return el;
  2898. }
  2899. };
  2900. if (!a.idOnly) Sahi.prototype[a.name] = newFn;
  2901. };
  2902. Sahi.prototype.identify = function(el){
  2903. if (el == null) return [];
  2904. var apis = [];
  2905. var tagLC = el.tagName.toLowerCase();
  2906. var accs = this.getAD(el);
  2907. for (var k=0; k<accs.length; k++){
  2908. var acc = accs[k];
  2909. if (acc && acc.attributes){
  2910. var r = acc.attributes;
  2911. for (var i=0; i<r.length; i++){
  2912. var attr = r[i];
  2913. if (attr == "index"){
  2914. var ix = this.getIdentifyIx(null, el, null);
  2915. if (ix != -1 && this[acc.name](ix) == el){
  2916. apis[apis.length] = this.buildAccessorInfo(el, acc, ix);
  2917. }
  2918. }else {
  2919. var val = this.getAttribute(el, attr);
  2920. if (val){
  2921. if (this[acc.name](val) == el){
  2922. apis[apis.length] = this.buildAccessorInfo(el, acc, val);
  2923. } else {
  2924. var ix = this.getIdentifyIx(val, el, attr);
  2925. val = val + "[" + ix + "]";
  2926. if (ix != -1 && this[acc.name](val) == el){
  2927. apis[apis.length] = this.buildAccessorInfo(el, acc, val);
  2928. }
  2929. }
  2930. }
  2931. }
  2932. }
  2933. }
  2934. }
  2935. var assertions = (apis.length > 0) ? this.getAssertions(accs, apis[0]) : [];
  2936. //if (apis.length != 0) this._alert(apis);
  2937. return {apis: apis, assertions: assertions};
  2938. };
  2939. Sahi.prototype.buildAccessorInfo = function(el, acc, identifier){
  2940. return new AccessorInfo("", identifier, acc.name, acc.action, (acc.value ? this.getAttribute(el, acc.value):null), acc.value);
  2941. };
  2942. Sahi.prototype.getIdentifyIx = function(val, el, attr){
  2943. var tagLC = el.tagName.toLowerCase();
  2944. var res = this.getBlankResult();
  2945. if (el.type){
  2946. return this.findElementIxHelper(val, el.type, el, this.top(), res, attr, tagLC).cnt;
  2947. } else {
  2948. return this.findTagIxHelper(val, el, this.top(), tagLC, res, attr).cnt;
  2949. }
  2950. };
  2951. Sahi.prototype.getAttribute = function (el, attr){
  2952. if (typeof attr == "function"){
  2953. return attr(el);
  2954. }
  2955. if (attr.indexOf("|") != -1){
  2956. var attrs = attr.split("|");
  2957. for (var i=0; i<attrs.length; i++){
  2958. var v = this.getAttribute(el, attrs[i]);
  2959. if (v != null && v != "") return v;
  2960. }
  2961. }else{
  2962. if (attr == "sahiText") return this._getText(el);
  2963. return el[attr];
  2964. }
  2965. };
  2966. Sahi.prototype.prepareADs = function(){
  2967. this.addAD({tag: "SPAN", type: null, event:"click", name: "_spanWithImage",
  2968. attributes: [function(el){ if (el.parentNode.tagName == "TD"){return _sahi._getText(el);}}], action: "_click", value: "sahiText"});
  2969. this.addAD({tag: "A", type: null, event:"click", name: "_link", attributes: ["sahiText", "id", "index"], action: "_click", value: "sahiText"});
  2970. this.addAD({tag: "IMG", type: null, event:"click", name: "_image", attributes: ["title|alt", "id",
  2971. function(el){var src = el.src; return src.substring(src.lastIndexOf("/")+1);}, "index"], action: "_click"});
  2972. this.addAD({tag: "LABEL", type: null, event:"click", name: "_label", attributes: ["sahiText", "id", "index"], action: "_click", value: "sahiText"});
  2973. this.addAD({tag: "LI", type: null, event:"click", name: "_listItem", attributes: ["sahiText", "id", "index"], action: "_click", value: "sahiText"});
  2974. this.addAD({tag: "DIV", type: null, event:"click", name: "_div", attributes: ["sahiText", "id", "index"], action: "_click", value: "sahiText"});
  2975. this.addAD({tag: "SPAN", type: null, event:"click", name: "_span", attributes: ["sahiText", "id", "index"], action: "_click", value: "sahiText"});
  2976. this.addAD({tag: "TABLE", type: null, event:"click", name: "_table", attributes: ["id", "index"], action: null, value: "sahiText"});
  2977. this.addAD({tag: "TD", type: null, event:"click", name: "_cell", attributes: ["sahiText", "id"], action: null, idOnly: true, value: "sahiText"});
  2978. this.addAD({tag: "INPUT", type: "button", event:"click", name: "_button", attributes: ["value", "name", "id", "index"], action: "_click", value: "value"});
  2979. this.addAD({tag: "BUTTON", type: "button", event:"click", name: "_button", attributes: ["sahiText", "name", "id", "index"], action: "_click", value: "sahiText"});
  2980. this.addAD({tag: "INPUT", type: "checkbox", event:"click", name: "_checkbox", attributes: ["name", "id", "index"], action: "_click", value: "checked"});
  2981. this.addAD({tag: "INPUT", type: "password", event:"change", name: "_password", attributes: ["name", "id", "index"], action: "_setValue", value: "value"});
  2982. this.addAD({tag: "INPUT", type: "radio", event:"click", name: "_radio", attributes: ["id", "name", "index"], action: "_click", value: "checked",
  2983. assertions: function(value){return ["_assert" + ("true" == "" + value ? "" : "NotTrue" ) + "(<accessor>.checked);"];}});
  2984. this.addAD({tag: "INPUT", type: "submit", event:"click", name: "_submit", attributes: ["value", "name", "id", "index"], action: "_click", value: "value"});
  2985. this.addAD({tag: "BUTTON", type: "submit", event:"click", name: "_submit", attributes: ["sahiText", "name", "id", "index"], action: "_click", value: "sahiText"});
  2986. this.addAD({tag: "INPUT", type: "text", event:"change", name: "_textbox", attributes: ["name", "id", "index"], action: "_setValue", value: "value"});
  2987. this.addAD({tag: "INPUT", type: "reset", event:"click", name: "_reset", attributes: ["value", "name", "id", "index"], action: "_click", value: "value"});
  2988. this.addAD({tag: "BUTTON", type: "reset", event:"click", name: "_reset", attributes: ["sahiText", "name", "id", "index"], action: "_click", value: "sahiText"});
  2989. this.addAD({tag: "INPUT", type: "file", event:"click", name: "_file", attributes: ["name", "id", "index"], action: "_click", value: "value"});
  2990. this.addAD({tag: "INPUT", type: "image", event:"click", name: "_imageSubmitButton", attributes: ["title|alt", "name", "id",
  2991. function(el){var src = el.src; return src.substring(src.lastIndexOf("/")+1);}, "index"], action: "_click"});
  2992. this.addAD({tag: "SELECT", type: null, event:"change", name: "_select", attributes: ["name", "id", "index"], action: "_setSelected", value: function(el){return _sahi.getOptionId(el, el.value) || _sahi.getOptionText(el, el.value) ;},
  2993. assertions: function(value){return ["_assertEqual(<value>, _getSelectedText(<accessor>))"];}});
  2994. this.addAD({tag: "TEXTAREA", type: null, event:"change", name: "_textarea", attributes: ["name", "id", "index"], action: "_setValue", value: "value"});
  2995. };
  2996. Sahi.prototype.c_reIdentify = function(s){
  2997. var el = null, elInfo = null;
  2998. try{
  2999. el = eval(s);
  3000. elInfo = this.identify(el);
  3001. }catch(e){}
  3002. this.sendIdsToController(elInfo, "RE_ID");
  3003. };
  3004. Sahi.prototype.c_evalEx = function(s){
  3005. var res = null;
  3006. try{
  3007. res = eval(s);
  3008. }catch(e){
  3009. res = e.message;
  3010. }
  3011. this.sendResultToController(""+res);
  3012. };