From 8bd025a75e295609647af0510544efb857678ec8 Mon Sep 17 00:00:00 2001 From: aszlig Date: Thu, 21 May 2015 19:49:08 +0200 Subject: [PATCH] nixos/test-driver: Add new waitForText function. As promised in the previous commit, this can be used similarly to $machine->waitForWindow, where you supply a regular expression and it's retrying OCR until the regexp matches. Signed-off-by: aszlig --- nixos/doc/manual/development/writing-nixos-tests.xml | 7 +++++++ nixos/lib/test-driver/Machine.pm | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/nixos/doc/manual/development/writing-nixos-tests.xml b/nixos/doc/manual/development/writing-nixos-tests.xml index 6224be0ca1a..322778d1c20 100644 --- a/nixos/doc/manual/development/writing-nixos-tests.xml +++ b/nixos/doc/manual/development/writing-nixos-tests.xml @@ -244,6 +244,13 @@ startAll; connections. + + waitForText + Wait until the supplied regular expressions matches + the textual contents of the screen by using optical character recognition + (see getScreenText). + + waitForWindow Wait until an X11 window has appeared whose name diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm index 0dddc1dc14b..d149634e9e6 100644 --- a/nixos/lib/test-driver/Machine.pm +++ b/nixos/lib/test-driver/Machine.pm @@ -518,6 +518,17 @@ sub getScreenText { } +# Wait until a specific regexp matches the textual contents of the screen. +sub waitForText { + my ($self, $regexp) = @_; + $self->nest("waiting for $regexp to appear on the screen", sub { + retry sub { + return 1 if $self->getScreenText =~ /$regexp/; + } + }); +} + + # Wait until it is possible to connect to the X server. Note that # testing the existence of /tmp/.X11-unix/X0 is insufficient. sub waitForX {