def test_press_and_wait_stable_timeout(): transition = stbt.press_and_wait("ball", timeout_secs=0.2, stable_secs=0.1, _dut=FakeDeviceUnderTest()) print(transition) assert not transition assert transition.status == stbt.TransitionStatus.STABLE_TIMEOUT transition = stbt.press_and_wait("ball", stable_secs=0, _dut=FakeDeviceUnderTest()) print(transition) assert transition assert transition.status == stbt.TransitionStatus.COMPLETE
def press_and_wait(self, key, timeout_secs=10, stable_secs=1): import stbt_core as stbt return stbt.press_and_wait(key, mask=self.mask, timeout_secs=timeout_secs, stable_secs=stable_secs)
def test_press_and_wait(): _stbt = FakeDeviceUnderTest() transition = stbt.press_and_wait("white", stable_secs=0.1, _dut=_stbt) print(transition) assert transition assert transition.status == stbt.TransitionStatus.COMPLETE assert transition.press_time < transition.animation_start_time assert transition.animation_start_time == transition.end_time assert transition.duration < 0.01 # excludes stable period assert transition.frame.min() == 255 transition = stbt.press_and_wait("fade-to-black", stable_secs=0.1, _dut=_stbt) print(transition) assert transition assert transition.status == stbt.TransitionStatus.COMPLETE assert transition.animation_start_time < transition.end_time assert transition.frame.max() == 0
def test_press_and_wait_timestamps(): _stbt = FakeDeviceUnderTest( ["black"] * 10 + ["fade-to-white"] * 2 + ["white"] * 100) transition = stbt.press_and_wait("fade-to-white", _dut=_stbt) print(transition) assert transition assert isclose(transition.animation_start_time, transition.press_time + 0.40, rtol=0, atol=0.01) assert isclose(transition.duration, 0.48, rtol=0, atol=0.01) assert isclose(transition.end_time, transition.animation_start_time + 0.08) assert isclose(transition.animation_duration, 0.08)
def navigate_to(self, target, page, verify_every_keypress=False): """Move the selection to the specified character. Note that this won't press KEY_OK on the target, it only moves the selection there. :param str target: The key or button to navigate to, for example "A", " ", or "CLEAR". :param stbt.FrameObject page: See ``enter_text``. :param bool verify_every_keypress: See ``enter_text``. :returns: A new FrameObject instance of the same type as ``page``, reflecting the device-under-test's new state after the navigation completed. """ import stbt_core as stbt if target not in self.G: raise ValueError("'%s' isn't in the keyboard" % (target, )) assert page, "%s page isn't visible" % type(page).__name__ deadline = time.time() + self.navigate_timeout current = _selection_to_text(page.selection) while current != target: assert time.time() < deadline, ( "Keyboard.navigate_to: Didn't reach %r after %s seconds" % (target, self.navigate_timeout)) keys = list(_keys_to_press(self.G, current, target)) log.info("Keyboard: navigating from %s to %s by pressing %r", current, target, keys) if not verify_every_keypress: for k, _ in keys[:-1]: stbt.press(k) keys = keys[-1:] # only verify the last one for key, possible_targets in keys: assert stbt.press_and_wait(key, mask=self.mask, stable_secs=0.5) page = page.refresh() assert page, "%s page isn't visible" % type(page).__name__ current = _selection_to_text(page.selection) assert current in possible_targets, \ "Expected to see %s after pressing %s, but saw %r" % ( _join_with_commas( [repr(x) for x in sorted(possible_targets)], last_one=" or "), key, current) return page
def test_press_and_wait_start_timeout(): transition = stbt.press_and_wait("black", timeout_secs=0.2, stable_secs=0.1, _dut=FakeDeviceUnderTest()) print(transition) assert not transition assert transition.status == stbt.TransitionStatus.START_TIMEOUT
def test_press_and_wait_with_mask_or_region(mask, region, expected): transition = stbt.press_and_wait( "ball", mask=mask, region=region, timeout_secs=0.2, stable_secs=0.1, _dut=FakeDeviceUnderTest()) print(transition) assert transition.status == expected