summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-08-03 12:31:43 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-08-03 12:31:43 +0100
commit41ecb495d0d27e2911a08c52330d1e58483c345c (patch)
treecb14dd6559592919f2f86a0cfe08e5db308f7331
parent45097c7f396df40b9c0cf71f2dd3dbeb50fc10c8 (diff)
downloadnetsurf-41ecb495d0d27e2911a08c52330d1e58483c345c.tar.gz
netsurf-41ecb495d0d27e2911a08c52330d1e58483c345c.tar.bz2
monkeyfarmer, driver: Add support for clicking on things
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rwxr-xr-xtest/monkey_driver.py58
-rw-r--r--test/monkeyfarmer.py3
2 files changed, 58 insertions, 3 deletions
diff --git a/test/monkey_driver.py b/test/monkey_driver.py
index 7a1bd7972..7296c8a7a 100755
--- a/test/monkey_driver.py
+++ b/test/monkey_driver.py
@@ -380,6 +380,56 @@ def run_test_step_action_repeat(ctx, step):
ctx["depth"] -= 1
+def run_test_step_action_click(ctx, step):
+ print(get_indent(ctx) + "Action: " + step["action"])
+ assert_browser(ctx)
+ win = ctx['windows'][step['window']]
+ targets = step['target']
+ if type(targets) == dict:
+ targets = [targets]
+ button = step.get('button', 'left').upper()
+ kind = step.get('kind', 'single').upper()
+ all_text_list = []
+ bitmaps = []
+ for plot in win.redraw():
+ if plot[0] == 'TEXT':
+ all_text_list.append((int(plot[2]), int(plot[4]), " ".join(plot[6:])))
+ if plot[0] == 'BITMAP':
+ bitmaps.append((int(plot[2]), int(plot[4]), int(plot[6]), int(plot[8])))
+
+ x = None
+ y = None
+
+ for target in targets:
+ if 'bitmap' in target:
+ if x is not None:
+ assert False, "Found more than one thing to click on, oh well"
+ bmap = int(target['bitmap'])
+ assert bmap < 0 or bmap >= len(bitmaps)
+ x = bitmaps[bmap][0] + bitmaps[bmap][2] / 2
+ y = bitmaps[bmap][1] + bitmaps[bmap][3] / 2
+ elif 'text' in target:
+ if x is not None:
+ assert False, "Found more than one thing to click on, oh well"
+ text = target['text']
+ for textentry in all_text_list:
+ if text in textentry[2]:
+ if x is not None:
+ assert False, "Text {} found more than once".format(text)
+ x = textentry[0] + 2
+ y = textentry[1] + 2
+
+ # Now we want to click on the x/y coordinate given
+ print(get_indent(ctx) + " Clicking at {}, {} (button={} kind={})".format(x, y, button, kind))
+ win.click(x, y, button, kind)
+
+
+def run_test_step_action_wait_loading(ctx, step):
+ print(get_indent(ctx) + "Action: " + step["action"])
+ assert_browser(ctx)
+ win = ctx['windows'][step['window']]
+ win.wait_start_loading()
+
def run_test_step_action_plot_check(ctx, step):
print(get_indent(ctx) + "Action: " + step["action"])
assert_browser(ctx)
@@ -398,13 +448,13 @@ def run_test_step_action_plot_check(ctx, step):
all_text = " ".join(all_text_list)
for check in checks:
if 'text-contains' in check.keys():
- print("Check {} in {}".format(repr(check['text-contains']), repr(all_text)))
+ print(" Check {} in {}".format(repr(check['text-contains']), repr(all_text)))
assert check['text-contains'] in all_text
elif 'text-not-contains' in check.keys():
- print("Check {} NOT in {}".format(repr(check['text-not-contains']), repr(all_text)))
+ print(" Check {} NOT in {}".format(repr(check['text-not-contains']), repr(all_text)))
assert check['text-not-contains'] not in all_text
elif 'bitmap-count' in check.keys():
- print("Check bitmap count is {}".format(int(check['bitmap-count'])))
+ print(" Check bitmap count is {}".format(int(check['bitmap-count'])))
assert len(bitmaps) == int(check['bitmap-count'])
else:
raise AssertionError("Unknown check: {}".format(repr(check)))
@@ -559,6 +609,8 @@ STEP_HANDLERS = {
"timer-stop": run_test_step_action_timer_stop,
"timer-check": run_test_step_action_timer_check,
"plot-check": run_test_step_action_plot_check,
+ "click": run_test_step_action_click,
+ "wait-loading": run_test_step_action_wait_loading,
"add-auth": run_test_step_action_add_auth,
"remove-auth": run_test_step_action_remove_auth,
"add-cert": run_test_step_action_add_cert,
diff --git a/test/monkeyfarmer.py b/test/monkeyfarmer.py
index 21be110ec..a26e28dd4 100644
--- a/test/monkeyfarmer.py
+++ b/test/monkeyfarmer.py
@@ -434,6 +434,9 @@ class BrowserWindow:
self.browser.farmer.tell_monkey("WINDOW RELOAD %s%s" % (self.winid, all))
self.wait_start_loading()
+ def click(self, x, y, button="LEFT", kind="SINGLE"):
+ self.browser.farmer.tell_monkey("WINDOW CLICK WIN %s X %s Y %s BUTTON %s KIND %s" % (self.winid, x, y, button, kind))
+
def js_exec(self, src):
self.browser.farmer.tell_monkey("WINDOW EXEC WIN %s %s" % (self.winid, src))