input.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Touchscreen = exports.Mouse = exports.Keyboard = void 0;
  6. /**
  7. * Copyright 2017 Google Inc. All rights reserved.
  8. * Modifications copyright (c) Microsoft Corporation.
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. class Keyboard {
  23. constructor(page) {
  24. this._page = void 0;
  25. this._page = page;
  26. }
  27. async down(key) {
  28. await this._page._channel.keyboardDown({
  29. key
  30. });
  31. }
  32. async up(key) {
  33. await this._page._channel.keyboardUp({
  34. key
  35. });
  36. }
  37. async insertText(text) {
  38. await this._page._channel.keyboardInsertText({
  39. text
  40. });
  41. }
  42. async type(text, options = {}) {
  43. await this._page._channel.keyboardType({
  44. text,
  45. ...options
  46. });
  47. }
  48. async press(key, options = {}) {
  49. await this._page._channel.keyboardPress({
  50. key,
  51. ...options
  52. });
  53. }
  54. }
  55. exports.Keyboard = Keyboard;
  56. class Mouse {
  57. constructor(page) {
  58. this._page = void 0;
  59. this._page = page;
  60. }
  61. async move(x, y, options = {}) {
  62. await this._page._channel.mouseMove({
  63. x,
  64. y,
  65. ...options
  66. });
  67. }
  68. async down(options = {}) {
  69. await this._page._channel.mouseDown({
  70. ...options
  71. });
  72. }
  73. async up(options = {}) {
  74. await this._page._channel.mouseUp(options);
  75. }
  76. async click(x, y, options = {}) {
  77. await this._page._channel.mouseClick({
  78. x,
  79. y,
  80. ...options
  81. });
  82. }
  83. async dblclick(x, y, options = {}) {
  84. await this.click(x, y, {
  85. ...options,
  86. clickCount: 2
  87. });
  88. }
  89. async wheel(deltaX, deltaY) {
  90. await this._page._channel.mouseWheel({
  91. deltaX,
  92. deltaY
  93. });
  94. }
  95. }
  96. exports.Mouse = Mouse;
  97. class Touchscreen {
  98. constructor(page) {
  99. this._page = void 0;
  100. this._page = page;
  101. }
  102. async tap(x, y) {
  103. await this._page._channel.touchscreenTap({
  104. x,
  105. y
  106. });
  107. }
  108. }
  109. exports.Touchscreen = Touchscreen;