PageRenderTime 72ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/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

Large files files are truncated, but you can click here to view the full file

  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.pr

Large files files are truncated, but you can click here to view the full file