PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/tests/functional/assets/extensions/user-extensions.js

https://bitbucket.org/zurmo/zurmo/
JavaScript | 150 lines | 67 code | 17 blank | 66 comment | 10 complexity | dded414cb3f7284664311bdb95aa365a MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. /**
  2. * storeValue, storeText, storeAttribute and store actions now
  3. * have 'global' equivalents.
  4. * Use storeValueGlobal, storeTextGlobal, storeAttributeGlobal or storeGlobal
  5. * will store the variable globally, making it available it subsequent tests.
  6. *
  7. * See the Reference.html for storeValue, storeText, storeAttribute and store
  8. * for the arguments you should send to the new Global functions.
  9. *
  10. * example of use
  11. * in testA.html:
  12. * +------------------+----------------------+----------------------+
  13. * |storeGlobal | http://localhost/ | baseURL |
  14. * +------------------+----------------------+----------------------+
  15. *
  16. * in textB.html (executed after testA.html):
  17. * +------------------+-----------------------+--+
  18. * |open | ${baseURL}Main.jsp | |
  19. * +------------------+-----------------------+--+
  20. *
  21. * Note: Selenium.prototype.replaceVariables from selenium-api.js has been replaced
  22. * here to make it use global variables if no local variable is found.
  23. * This might cause issues if you upgraded Selenium in the future and this function
  24. * has been changed.
  25. *
  26. * @author Guillaume Boudreau
  27. */
  28. globalStoredVars = new Object();
  29. /*
  30. * Globally store the value of a form input in a variable
  31. */
  32. Selenium.prototype.doStoreValueGlobal = function(target, varName)
  33. {
  34. if (!varName) {
  35. // Backward compatibility mode: read the ENTIRE text of the page
  36. // and stores it in a variable with the name of the target
  37. value = this.page().bodyText();
  38. globalStoredVars[target] = value;
  39. return;
  40. }
  41. var element = this.page().findElement(target);
  42. globalStoredVars[varName] = getInputValue(element);
  43. };
  44. /*
  45. * Globally store the text of an element in a variable
  46. */
  47. Selenium.prototype.doStoreTextGlobal = function(target, varName)
  48. {
  49. var element = this.page().findElement(target);
  50. globalStoredVars[varName] = getText(element);
  51. };
  52. /*
  53. * Globally store the value of an element attribute in a variable
  54. */
  55. Selenium.prototype.doStoreAttributeGlobal = function(target, varName)
  56. {
  57. globalStoredVars[varName] = this.page().findAttribute(target);
  58. };
  59. /*
  60. * Globally store the result of a literal value
  61. */
  62. Selenium.prototype.doStoreGlobal = function(value, varName)
  63. {
  64. globalStoredVars[varName] = value;
  65. };
  66. /*
  67. * Search through str and replace all variable references ${varName} with their
  68. * value in storedVars (or globalStoredVars).
  69. */
  70. Selenium.prototype.replaceVariables = function(str)
  71. {
  72. var stringResult = str;
  73. // Find all of the matching variable references
  74. var match = stringResult.match(/\$\{\w+\}/g);
  75. if (!match)
  76. {
  77. return stringResult;
  78. }
  79. // For each match, lookup the variable value, and replace if found
  80. for (var i = 0; match && i < match.length; i++)
  81. {
  82. var variable = match[i]; // The replacement variable, with ${}
  83. var name = variable.substring(2, variable.length - 1); // The replacement variable without ${}
  84. var replacement = storedVars[name];
  85. if (replacement != undefined)
  86. {
  87. stringResult = stringResult.replace(variable, replacement);
  88. }
  89. var replacement = globalStoredVars[name];
  90. if (replacement != undefined)
  91. {
  92. stringResult = stringResult.replace(variable, replacement);
  93. }
  94. }
  95. return stringResult;
  96. };
  97. /*
  98. * The below prototype combines the focus, select and click commands of selinium
  99. * so as to support different browser.
  100. */
  101. Selenium.prototype.doFocusSelectAndClick = function(selectLocator, optionLocator)
  102. {
  103. //Focus on a Combox element.
  104. this.doFocus(selectLocator);
  105. //Select an option from a Combobox element.
  106. this.doSelect(selectLocator, optionLocator);
  107. //Click the Combobox element.
  108. this.doClick(selectLocator);
  109. };
  110. /*
  111. * The below prototype combines the type and typeKeys commands of selinium
  112. * so as to support different browser.
  113. */
  114. Selenium.prototype.doTypeAndTypeKeys = function(locator, value)
  115. {
  116. var typeValue = (navigator.appName == "Microsoft Internet Explorer" || navigator.userAgent.toLowerCase().indexOf('chrome') > -1) ? value : "";
  117. //Type a particulat value in the element.
  118. this.doType(locator, typeValue);
  119. //Type a particulat value in the element, so as to support the auto-complete functionality.
  120. this.doTypeKeys(locator, value);
  121. };
  122. /*
  123. * The below prototype compares the text of the element locator and the
  124. * corresponding text provided.
  125. */
  126. Selenium.prototype.doCompareText = function(locator, value)
  127. {
  128. //Fetch the locator value and also filter the content based on the regex Object.
  129. var regex = (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) ? new RegExp("\\n", 'gi') : "\\n/gi";
  130. var locatorValue = this.getText(locator).replace(regex,"");
  131. //Asset the the values match.
  132. Assert.matches(locatorValue, value);
  133. };