Skip to content

Commit

Permalink
Use realistic typing delays for the scripting integration tests
Browse files Browse the repository at this point in the history
In the scripting integration tests we use a few different typing
delays, mostly 100 or 200 milliseconds. According to for example
https://www.typingpal.com/en/documentation/school-edition/pedagogical-resources/typing-speed,
a fast typing speed is around 300 characters per minute, which is 5
characters per second and therefore a delay of 200 milliseconds between
each keystroke. Note that this is already above average, so in practice
the delay will be even larger. Therefore the 100 milliseconds variant
is unrealistically fast and therefore not suitable for the integration
tests which aim to simulate the average user behavior.

On top of that, the quick typing speeds are problematic for the tests
that involve validation alert dialogs appearing during typing. In those
tests a handler is registered to close the dialog once it pops up, but
it takes time for Puppeteer to notice the dialog, trigger the handler
and close it. If the typing delay, which is the delay between the key
down and key up events according to the Puppeteer source code at
https://github.com/puppeteer/puppeteer/blob/master/packages/puppeteer-core/src/cdp/Input.ts#L209-L215,
is too short, the key up event will be fired before the dialog is
closed. In that time the text box we're typing in is not focused, so
when the dialog is closed the `page.type()` call on the text box will
never resolve because the key up event never reached the text box.

This commit aims to fix the issues by converting all 100 millisecond
delays to 200 milliseconds. For instance the "must check input for US
zip format" failed pretty consistently locally before and hasn't failed
anymore with a 200 millisecond delay.
  • Loading branch information
timvandermeij committed Sep 24, 2023
1 parent 9b46404 commit 6e584ad
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions test/integration/scripting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ describe("Interaction", () => {
const prev = await page.$eval(getSelector("171R"), el => el.value);

await page.type(getSelector(id), val.toString(), {
delay: 100,
delay: 200,
});
await page.keyboard.press("Tab");

Expand Down Expand Up @@ -1035,7 +1035,7 @@ describe("Interaction", () => {
await clearInput(page, getSelector("30R"));

await page.focus(getSelector("29R"));
await page.type(getSelector("29R"), "12A", { delay: 100 });
await page.type(getSelector("29R"), "12A", { delay: 200 });
await page.waitForFunction(
`${getQuerySelector("29R")}.value !== "12A"`
);
Expand All @@ -1044,7 +1044,7 @@ describe("Interaction", () => {
expect(text).withContext(`In ${browserName}`).toEqual("12");

await page.focus(getSelector("29R"));
await page.type(getSelector("29R"), "34", { delay: 100 });
await page.type(getSelector("29R"), "34", { delay: 200 });
await page.click("[data-annotation-id='30R']");

await page.waitForFunction(
Expand All @@ -1055,7 +1055,7 @@ describe("Interaction", () => {
expect(text).withContext(`In ${browserName}`).toEqual("");

await page.focus(getSelector("29R"));
await page.type(getSelector("29R"), "12345", { delay: 100 });
await page.type(getSelector("29R"), "12345", { delay: 200 });
await page.click("[data-annotation-id='30R']");

text = await page.$eval(getSelector(`29R`), el => el.value);
Expand Down Expand Up @@ -1092,7 +1092,7 @@ describe("Interaction", () => {
await clearInput(page, getSelector("30R"));

await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "(123) 456A", { delay: 100 });
await page.type(getSelector("30R"), "(123) 456A", { delay: 200 });
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "(123) 456A"`
);
Expand All @@ -1101,7 +1101,7 @@ describe("Interaction", () => {
expect(text).withContext(`In ${browserName}`).toEqual("(123) 456");

await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "-789", { delay: 100 });
await page.type(getSelector("30R"), "-789", { delay: 200 });
await page.click("[data-annotation-id='29R']");

await page.waitForFunction(
Expand All @@ -1112,7 +1112,7 @@ describe("Interaction", () => {
expect(text).withContext(`In ${browserName}`).toEqual("");

await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "(123) 456-7890", { delay: 100 });
await page.type(getSelector("30R"), "(123) 456-7890", { delay: 200 });
await page.click("[data-annotation-id='29R']");

text = await page.$eval(getSelector("30R"), el => el.value);
Expand Down Expand Up @@ -1149,7 +1149,7 @@ describe("Interaction", () => {
await clearInput(page, getSelector("30R"));

await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "123A", { delay: 100 });
await page.type(getSelector("30R"), "123A", { delay: 200 });
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "123A"`
);
Expand All @@ -1158,7 +1158,7 @@ describe("Interaction", () => {
expect(text).withContext(`In ${browserName}`).toEqual("123");

await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "-456", { delay: 100 });
await page.type(getSelector("30R"), "-456", { delay: 200 });
await page.click("[data-annotation-id='29R']");

await page.waitForFunction(
Expand All @@ -1169,7 +1169,7 @@ describe("Interaction", () => {
expect(text).withContext(`In ${browserName}`).toEqual("");

await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "123-4567", { delay: 100 });
await page.type(getSelector("30R"), "123-4567", { delay: 200 });
await page.click("[data-annotation-id='29R']");

text = await page.$eval(getSelector("30R"), el => el.value);
Expand Down Expand Up @@ -1201,15 +1201,15 @@ describe("Interaction", () => {
"window.PDFViewerApplication.scriptingReady === true"
);

await page.type(getSelector("27R"), "Hello", { delay: 100 });
await page.type(getSelector("27R"), "Hello", { delay: 200 });
await page.waitForFunction(
`${getQuerySelector("27R")}.value !== "Hello"`
);

let text = await page.$eval(getSelector("27R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("HELLO");

await page.type(getSelector("27R"), " world", { delay: 100 });
await page.type(getSelector("27R"), " world", { delay: 200 });
await page.waitForFunction(
`${getQuerySelector("27R")}.value !== "HELLO world"`
);
Expand All @@ -1227,7 +1227,7 @@ describe("Interaction", () => {
text = await page.$eval(getSelector("27R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("HELLO WOR");

await page.type(getSelector("27R"), "12.dL", { delay: 100 });
await page.type(getSelector("27R"), "12.dL", { delay: 200 });

await page.waitForFunction(
`${getQuerySelector("27R")}.value !== "HELLO WOR"`
Expand All @@ -1236,7 +1236,7 @@ describe("Interaction", () => {
text = await page.$eval(getSelector("27R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("HELLO WORDL");

await page.type(getSelector("27R"), " ", { delay: 100 });
await page.type(getSelector("27R"), " ", { delay: 200 });

await page.keyboard.down("Control");
await page.keyboard.press("Backspace");
Expand Down Expand Up @@ -1274,7 +1274,7 @@ describe("Interaction", () => {
el.setSelectionRange(0, 0)
);

await page.type(getSelector("28R"), "Hello", { delay: 100 });
await page.type(getSelector("28R"), "Hello", { delay: 200 });
await page.waitForFunction(
`${getQuerySelector("28R")}.value !== "123"`
);
Expand Down Expand Up @@ -1322,7 +1322,7 @@ describe("Interaction", () => {
"window.PDFViewerApplication.scriptingReady === true"
);

await page.type(getSelector("29R"), "Hello World", { delay: 100 });
await page.type(getSelector("29R"), "Hello World", { delay: 200 });
await page.click(getSelector("27R"));

await page.waitForFunction(
Expand Down Expand Up @@ -1763,7 +1763,7 @@ describe("Interaction", () => {
"window.PDFViewerApplication.scriptingReady === true"
);

await page.type(getSelector("30R"), "abc", { delay: 100 });
await page.type(getSelector("30R"), "abc", { delay: 200 });
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "abc"`
);
Expand Down

0 comments on commit 6e584ad

Please sign in to comment.