input.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // Licensed to the Software Freedom Conservancy (SFC) under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The SFC licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. 'use strict';
  18. /**
  19. * @fileoverview Defines types related to user input with the WebDriver API.
  20. */
  21. /**
  22. * Enumeration of the buttons used in the advanced interactions API.
  23. * @enum {number}
  24. */
  25. const Button = {
  26. LEFT: 0,
  27. MIDDLE: 1,
  28. RIGHT: 2
  29. };
  30. /**
  31. * Representations of pressable keys that aren't text. These are stored in
  32. * the Unicode PUA (Private Use Area) code points, 0xE000-0xF8FF. Refer to
  33. * http://www.google.com.au/search?&q=unicode+pua&btnG=Search
  34. *
  35. * @enum {string}
  36. */
  37. const Key = {
  38. NULL: '\uE000',
  39. CANCEL: '\uE001', // ^break
  40. HELP: '\uE002',
  41. BACK_SPACE: '\uE003',
  42. TAB: '\uE004',
  43. CLEAR: '\uE005',
  44. RETURN: '\uE006',
  45. ENTER: '\uE007',
  46. SHIFT: '\uE008',
  47. CONTROL: '\uE009',
  48. ALT: '\uE00A',
  49. PAUSE: '\uE00B',
  50. ESCAPE: '\uE00C',
  51. SPACE: '\uE00D',
  52. PAGE_UP: '\uE00E',
  53. PAGE_DOWN: '\uE00F',
  54. END: '\uE010',
  55. HOME: '\uE011',
  56. ARROW_LEFT: '\uE012',
  57. LEFT: '\uE012',
  58. ARROW_UP: '\uE013',
  59. UP: '\uE013',
  60. ARROW_RIGHT: '\uE014',
  61. RIGHT: '\uE014',
  62. ARROW_DOWN: '\uE015',
  63. DOWN: '\uE015',
  64. INSERT: '\uE016',
  65. DELETE: '\uE017',
  66. SEMICOLON: '\uE018',
  67. EQUALS: '\uE019',
  68. NUMPAD0: '\uE01A', // number pad keys
  69. NUMPAD1: '\uE01B',
  70. NUMPAD2: '\uE01C',
  71. NUMPAD3: '\uE01D',
  72. NUMPAD4: '\uE01E',
  73. NUMPAD5: '\uE01F',
  74. NUMPAD6: '\uE020',
  75. NUMPAD7: '\uE021',
  76. NUMPAD8: '\uE022',
  77. NUMPAD9: '\uE023',
  78. MULTIPLY: '\uE024',
  79. ADD: '\uE025',
  80. SEPARATOR: '\uE026',
  81. SUBTRACT: '\uE027',
  82. DECIMAL: '\uE028',
  83. DIVIDE: '\uE029',
  84. F1: '\uE031', // function keys
  85. F2: '\uE032',
  86. F3: '\uE033',
  87. F4: '\uE034',
  88. F5: '\uE035',
  89. F6: '\uE036',
  90. F7: '\uE037',
  91. F8: '\uE038',
  92. F9: '\uE039',
  93. F10: '\uE03A',
  94. F11: '\uE03B',
  95. F12: '\uE03C',
  96. COMMAND: '\uE03D', // Apple command key
  97. META: '\uE03D' // alias for Windows key
  98. };
  99. /**
  100. * Simulate pressing many keys at once in a "chord". Takes a sequence of
  101. * {@linkplain Key keys} or strings, appends each of the values to a string,
  102. * adds the chord termination key ({@link Key.NULL}) and returns the resulting
  103. * string.
  104. *
  105. * Note: when the low-level webdriver key handlers see Keys.NULL, active
  106. * modifier keys (CTRL/ALT/SHIFT/etc) release via a keyup event.
  107. *
  108. * @param {...string} var_args The key sequence to concatenate.
  109. * @return {string} The null-terminated key sequence.
  110. */
  111. Key.chord = function(var_args) {
  112. return Array.prototype.slice.call(arguments, 0).join('') + Key.NULL;
  113. };
  114. /**
  115. * Used with {@link ./webelement.WebElement#sendKeys WebElement#sendKeys} on
  116. * file input elements (`<input type="file">`) to detect when the entered key
  117. * sequence defines the path to a file.
  118. *
  119. * By default, {@linkplain ./webelement.WebElement WebElement's} will enter all
  120. * key sequences exactly as entered. You may set a
  121. * {@linkplain ./webdriver.WebDriver#setFileDetector file detector} on the
  122. * parent WebDriver instance to define custom behavior for handling file
  123. * elements. Of particular note is the
  124. * {@link selenium-webdriver/remote.FileDetector}, which should be used when
  125. * running against a remote
  126. * [Selenium Server](http://docs.seleniumhq.org/download/).
  127. */
  128. class FileDetector {
  129. /**
  130. * Handles the file specified by the given path, preparing it for use with
  131. * the current browser. If the path does not refer to a valid file, it will
  132. * be returned unchanged, otherwise a path suitable for use with the current
  133. * browser will be returned.
  134. *
  135. * This default implementation is a no-op. Subtypes may override this function
  136. * for custom tailored file handling.
  137. *
  138. * @param {!./webdriver.WebDriver} driver The driver for the current browser.
  139. * @param {string} path The path to process.
  140. * @return {!Promise<string>} A promise for the processed file path.
  141. * @package
  142. */
  143. handleFile(driver, path) {
  144. return Promise.resolve(path);
  145. }
  146. }
  147. // PUBLIC API
  148. module.exports = {
  149. Button: Button,
  150. Key: Key,
  151. FileDetector: FileDetector
  152. };