Skip to content

Commit e58bf3f

Browse files
authored
fix(runner): scroll 0 in the direction an act scroll leaves out (#1680)
1 parent c604e1e commit e58bf3f

8 files changed

Lines changed: 53 additions & 19 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@qawolf/cli": patch
3+
---
4+
5+
`qawolf runner act scroll` now scrolls 0 in the direction you leave out, so `--scroll-y 600` alone works, and `act --help` shows a scroll example.

‎skills/qawolf-cli/references/runner.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ Options:
592592
place of a separate screenshot. An action that did not take effect answers
593593
with one too. - writes it to stdout and moves the confirmation, JSON
594594
included, to stderr
595-
--scroll-x <delta> scroll: horizontal wheel delta
596-
--scroll-y <delta> scroll: vertical wheel delta
595+
--scroll-x <delta> scroll: horizontal wheel delta, 0 when only --scroll-y is given
596+
--scroll-y <delta> scroll: vertical wheel delta, 0 when only --scroll-x is given
597597
--selector <selector> tap or fill: the element to act on, as a screen object would find it. tap
598598
takes it in place of --x and --y
599599
--strategy <strategy> how --selector is resolved: xpath (default), ios-predicate or shadow
@@ -608,6 +608,7 @@ Examples:
608608
$ qawolf runner act click --button left --x 480 --y 260
609609
$ qawolf runner act type --text "hello@example.com"
610610
$ qawolf runner act keypress --keys Control a
611+
$ qawolf runner act scroll --x 640 --y 400 --scroll-y 600
611612
$ qawolf runner act navigate --url https://example.com
612613
$ qawolf runner act drag --path '[{"x":10,"y":20},{"x":80,"y":90}]'
613614
$ qawolf runner act click --button left --x 480 --y 260 --screenshot step-4.jpg

‎src/commands/__snapshots__/help.test.ts.snap‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,10 @@ Options:
941941
action that did not take effect answers with one too. -
942942
writes it to stdout and moves the confirmation, JSON
943943
included, to stderr
944-
--scroll-x <delta> scroll: horizontal wheel delta
945-
--scroll-y <delta> scroll: vertical wheel delta
944+
--scroll-x <delta> scroll: horizontal wheel delta, 0 when only --scroll-y
945+
is given
946+
--scroll-y <delta> scroll: vertical wheel delta, 0 when only --scroll-x is
947+
given
946948
--selector <selector> tap or fill: the element to act on, as a screen object
947949
would find it. tap takes it in place of --x and --y
948950
--strategy <strategy> how --selector is resolved: xpath (default),
@@ -959,6 +961,7 @@ Examples:
959961
$ qawolf runner act click --button left --x 480 --y 260
960962
$ qawolf runner act type --text "hello@example.com"
961963
$ qawolf runner act keypress --keys Control a
964+
$ qawolf runner act scroll --x 640 --y 400 --scroll-y 600
962965
$ qawolf runner act navigate --url https://example.com
963966
$ qawolf runner act drag --path '[{"x":10,"y":20},{"x":80,"y":90}]'
964967
$ qawolf runner act click --button left --x 480 --y 260 --screenshot step-4.jpg

‎src/commands/help/__snapshots__/reference.test.ts.snap‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ Options:
593593
place of a separate screenshot. An action that did not take effect answers
594594
with one too. - writes it to stdout and moves the confirmation, JSON
595595
included, to stderr
596-
--scroll-x <delta> scroll: horizontal wheel delta
597-
--scroll-y <delta> scroll: vertical wheel delta
596+
--scroll-x <delta> scroll: horizontal wheel delta, 0 when only --scroll-y is given
597+
--scroll-y <delta> scroll: vertical wheel delta, 0 when only --scroll-x is given
598598
--selector <selector> tap or fill: the element to act on, as a screen object would find it. tap
599599
takes it in place of --x and --y
600600
--strategy <strategy> how --selector is resolved: xpath (default), ios-predicate or shadow
@@ -609,6 +609,7 @@ Examples:
609609
$ qawolf runner act click --button left --x 480 --y 260
610610
$ qawolf runner act type --text "hello@example.com"
611611
$ qawolf runner act keypress --keys Control a
612+
$ qawolf runner act scroll --x 640 --y 400 --scroll-y 600
612613
$ qawolf runner act navigate --url https://example.com
613614
$ qawolf runner act drag --path '[{"x":10,"y":20},{"x":80,"y":90}]'
614615
$ qawolf runner act click --button left --x 480 --y 260 --screenshot step-4.jpg

‎src/commands/runner/actExamples.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Examples:
33
$ qawolf runner act click --button left --x 480 --y 260
44
$ qawolf runner act type --text "hello@example.com"
55
$ qawolf runner act keypress --keys Control a
6+
$ qawolf runner act scroll --x 640 --y 400 --scroll-y 600
67
$ qawolf runner act navigate --url https://example.com
78
$ qawolf runner act drag --path '[{"x":10,"y":20},{"x":80,"y":90}]'
89
$ qawolf runner act click --button left --x 480 --y 260 --screenshot step-4.jpg

‎src/commands/runner/interact.register.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ export function registerRunnerInteractCommands(
9191
"--screenshot <path>",
9292
"Also save a JPEG of the screen, taken after the action, to this file, in place of a separate screenshot. An action that did not take effect answers with one too. - writes it to stdout and moves the confirmation, JSON included, to stderr",
9393
)
94-
.option("--scroll-x <delta>", "scroll: horizontal wheel delta")
95-
.option("--scroll-y <delta>", "scroll: vertical wheel delta")
94+
.option(
95+
"--scroll-x <delta>",
96+
"scroll: horizontal wheel delta, 0 when only --scroll-y is given",
97+
)
98+
.option(
99+
"--scroll-y <delta>",
100+
"scroll: vertical wheel delta, 0 when only --scroll-x is given",
101+
)
96102
.option(
97103
"--selector <selector>",
98104
"tap or fill: the element to act on, as a screen object would find it. tap takes it in place of --x and --y",

‎src/core/interactiveRunner/browserAction.test.ts‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,29 @@ describe("buildRunnerAction", () => {
142142
expect(built.ok).toBe(false);
143143
});
144144

145-
// The schema is strict, so a scroll carries both deltas or neither. Nothing in
146-
// the help says so, which is exactly why the refusal has to.
147-
it("refuses a scroll missing one of its two deltas", () => {
148-
const built = build("scroll", { scrollY: "300", x: "1", y: "2" });
145+
it("scrolls 0 in the direction a scroll leaves out", () => {
146+
expect(build("scroll", { scrollY: "300", x: "1", y: "2" })).toEqual({
147+
action: { scroll_x: 0, scroll_y: 300, type: "scroll", x: 1, y: 2 },
148+
ok: true,
149+
});
150+
expect(build("scroll", { scrollX: "-40", x: "1", y: "2" })).toEqual({
151+
action: { scroll_x: -40, scroll_y: 0, type: "scroll", x: 1, y: 2 },
152+
ok: true,
153+
});
154+
});
155+
156+
it("refuses a scroll with no delta at all", () => {
157+
const built = build("scroll", { x: "1", y: "2" });
158+
159+
expect(built.ok).toBe(false);
160+
});
161+
162+
it("refuses a scroll with no point to scroll at", () => {
163+
const built = build("scroll", { scrollY: "300" });
149164

150165
expect(built.ok).toBe(false);
151166
if (built.ok) return;
152-
expect(built.error).toContain("scroll_x");
167+
expect(built.error).toContain("at x");
153168
});
154169
});
155170

‎src/core/interactiveRunner/browserAction.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ export function buildRunnerAction(
7676
if (to !== undefined && !to.ok) return to;
7777
// A click with no --button is a left click, the one nearly every click means.
7878
const button = flags.button ?? (type === "click" ? "left" : undefined);
79+
// A scroll given one direction does not move in the other.
80+
const scrollsOneWay =
81+
type === "scroll" &&
82+
(flags.scrollX === undefined) !== (flags.scrollY === undefined);
83+
const scrollX = flags.scrollX ?? (scrollsOneWay ? "0" : undefined);
84+
const scrollY = flags.scrollY ?? (scrollsOneWay ? "0" : undefined);
7985

8086
const candidate = {
8187
type,
@@ -86,12 +92,8 @@ export function buildRunnerAction(
8692
...(from === undefined ? {} : { from: from.value }),
8793
...(flags.keys === undefined ? {} : { keys: flags.keys }),
8894
...(parsedPath === undefined ? {} : { path: parsedPath.value }),
89-
...(flags.scrollX === undefined
90-
? {}
91-
: { scroll_x: toNumber(flags.scrollX) }),
92-
...(flags.scrollY === undefined
93-
? {}
94-
: { scroll_y: toNumber(flags.scrollY) }),
95+
...(scrollX === undefined ? {} : { scroll_x: toNumber(scrollX) }),
96+
...(scrollY === undefined ? {} : { scroll_y: toNumber(scrollY) }),
9597
...(flags.selector === undefined ? {} : { selector: flags.selector }),
9698
...(flags.strategy === undefined ? {} : { strategy: flags.strategy }),
9799
...(flags.text === undefined ? {} : { text: flags.text }),

0 commit comments

Comments
 (0)