Skip to content

Commit

Permalink
test: add send keys plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Jan 21, 2021
1 parent 30b9187 commit f188c68
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"prelerna-publish": "yarn get-ready && yarn custom-element-json",
"lerna-publish": "lerna publish --message 'chore: release new versions'",
"test": "yarn build && yarn test:ci",
"test:build": "tsc --build test/tsconfig-test.json",
"test:build": "tsc --build test/tsconfig-test.json && tsc --build test/tsconfig-plugins.json",
"test:ci": "yarn test:build && yarn test:start",
"test:start": "web-test-runner",
"test:watch": "run-p watch 'test:build -w' 'test:start --watch'",
Expand Down Expand Up @@ -112,6 +112,7 @@
"@vaadin/router": "^1.2.0",
"@web/dev-server": "^0.1.3",
"@web/test-runner": "^0.11.7",
"@web/test-runner-commands": "^0.4.0",
"@web/test-runner-playwright": "^0.7.2",
"@webcomponents/webcomponentsjs": "^2.4.4",
"alex": "^9.0.1",
Expand Down
50 changes: 50 additions & 0 deletions test/send-keys-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2020 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
import type { Page } from 'playwright';

export function sendKeysPlugin() {
return {
name: 'send-keys-command',
async executeCommand({
command,
payload = {},
session,
}: {
payload: { type?: string; press?: string };
command: string;
session: {
id: string;
browser: { type: string; getPage: (id: string) => Page };
};
}) {
if (command === 'send-keys') {
// handle specific behavior for playwright
if (session.browser.type === 'playwright') {
if (payload.type) {
const page = session.browser.getPage(session.id);
await page.keyboard.type(payload.type);
return true;
} else if (payload.press) {
const page = session.browser.getPage(session.id);
await page.keyboard.press(payload.press);
return true;
}
}
// you might not be able to support all browser launchers
throw new Error(
`Sending keys is not supported for browser type ${session.browser.type}.`
);
}
return false;
},
};
}
11 changes: 11 additions & 0 deletions test/tsconfig-plugins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2017",
"rootDir": ".",
"sourceMap": false,
"strict": true
},
"include": ["./send-keys-plugin.ts"],
"exclude": []
}
2 changes: 2 additions & 0 deletions web-test-runner.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/
const { playwrightLauncher } = require('@web/test-runner-playwright');
const { sendKeysPlugin } = require('./test/send-keys-plugin.js');

module.exports = {
plugins: [sendKeysPlugin()],
files: ['packages/*/test/*.test.js'],
nodeResolve: true,
concurrency: 4,
Expand Down
62 changes: 61 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,13 @@
resolved "https://registry.yarnpkg.com/@web/browser-logs/-/browser-logs-0.1.6.tgz#275c9e2e0aa5767d8a5649ba487378b9f6a61efb"
integrity sha512-AQ3y3W5CLC3b68PYWMnimTApjDsgk6qJt82bPTJTxzCp3HZaUxuZJeMxrtt7FrtmaPt6E56pJobu1pcaqn1jcA==

"@web/browser-logs@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@web/browser-logs/-/browser-logs-0.2.0.tgz#3f39d59154bf668f0bce467026354ff2b9f3e06b"
integrity sha512-BExeD4Rlak10X+R38dDfc3waYu2dHEvMNqIottCwFXXoMvLeQs0+fYB2fqpcQwMoAIhhKRo9NENtuQQLaR1y0A==
dependencies:
errorstacks "^2.2.0"

"@web/config-loader@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@web/config-loader/-/config-loader-0.1.3.tgz#8325ea54f75ef2ee7166783e64e66936db25bff7"
Expand Down Expand Up @@ -4172,6 +4179,39 @@
dependencies:
"@web/test-runner-core" "^0.9.0"

"@web/test-runner-commands@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@web/test-runner-commands/-/test-runner-commands-0.4.0.tgz#14d5ec6de2f08d2cf84625210c261014572b6f2d"
integrity sha512-FsmF4Ya2mK8nlrodSjLMK1iKsSz61l4LeHSNRBjZtlzfjfwoGb38Pq+WehtboKgan+if/daHBjW85QFO1j3O+Q==
dependencies:
"@web/test-runner-core" "^0.10.0"

"@web/test-runner-core@^0.10.0":
version "0.10.3"
resolved "https://registry.yarnpkg.com/@web/test-runner-core/-/test-runner-core-0.10.3.tgz#6187975c01afa05c1d1efcf75db091337bdb2cc1"
integrity sha512-f0SLYg29PhyiN1iKCt0oRx6NwyoWsVRcu2OhCWDelh1MK0ehtKxPUPcmUvu4WfBiNMhVvQZGqqPAnlOlqSf7iw==
dependencies:
"@babel/code-frame" "^7.12.11"
"@web/browser-logs" "^0.2.0"
"@web/dev-server-core" "^0.3.3"
chalk "^4.1.0"
chokidar "^3.4.3"
cli-cursor "^3.1.0"
co-body "^6.1.0"
convert-source-map "^1.7.0"
debounce "^1.2.0"
dependency-graph "^0.10.0"
globby "^11.0.1"
ip "^1.1.5"
istanbul-lib-coverage "^3.0.0"
istanbul-lib-report "^3.0.0"
istanbul-reports "^3.0.2"
log-update "^4.0.0"
open "^7.3.0"
picomatch "^2.2.2"
source-map "^0.7.3"
uuid "^8.3.2"

"@web/test-runner-core@^0.9.0", "@web/test-runner-core@^0.9.3":
version "0.9.3"
resolved "https://registry.yarnpkg.com/@web/test-runner-core/-/test-runner-core-0.9.3.tgz#f4fa664ac392e08d7ceeeacba392a8398ff4fc8d"
Expand Down Expand Up @@ -8362,6 +8402,11 @@ depd@~1.1.2:
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9"
integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=

dependency-graph@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/dependency-graph/-/dependency-graph-0.10.0.tgz#dfebe384f1f36faf7782be203a7a71102a6335a6"
integrity sha512-c9amUgpgxSi1bE5/sbLwcs5diLD0ygCQYmhfM5H1s5VH1mCsYkcmAL3CcNdv4kdSw6JuMoHeDGzLgj/gAXdWVg==

dependency-graph@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/dependency-graph/-/dependency-graph-0.9.0.tgz#11aed7e203bc8b00f48356d92db27b265c445318"
Expand Down Expand Up @@ -8953,6 +8998,11 @@ error-stack-parser@^2.0.2, error-stack-parser@^2.0.3:
dependencies:
stackframe "^1.1.1"

errorstacks@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/errorstacks/-/errorstacks-2.2.0.tgz#21bdcfc16ded3660c542fc0b286bdf034a126c1a"
integrity sha512-d/HXKLrpdLYReAnNq5k/KgZKlfc5J+3DKKvci8WKzuM9MAXFrCoCfVyViHk0aFMLyazU/jYhW2d8zTa99pelIA==

es-abstract@^1.17.0-next.1, es-abstract@^1.17.2:
version "1.17.7"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.17.7.tgz#a4de61b2f66989fc7421676c1cb9787573ace54c"
Expand Down Expand Up @@ -22947,7 +22997,17 @@ ws@^6.2.1:
dependencies:
async-limiter "~1.0.0"

ws@^7.2.3, ws@^7.3.1, ws@^7.4.2:
ws@^7.2.3:
version "7.2.3"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.2.3.tgz#a5411e1fb04d5ed0efee76d26d5c46d830c39b46"
integrity sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==

ws@^7.3.1:
version "7.3.1"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.3.1.tgz#d0547bf67f7ce4f12a72dfe31262c68d7dc551c8"
integrity sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==

ws@^7.4.2:
version "7.4.2"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.2.tgz#782100048e54eb36fe9843363ab1c68672b261dd"
integrity sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA==
Expand Down

0 comments on commit f188c68

Please sign in to comment.