Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Allow history to exceed precision in expected element moving and give…
Browse files Browse the repository at this point in the history
… the element a chance to change state during initial state gathering
  • Loading branch information
davehunt committed Sep 15, 2015
1 parent 4174e6a commit e957c4d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import time


class element_moving(object):
"""An expectation for checking that an element is moving.
Expand All @@ -19,12 +21,18 @@ def __init__(self, element, precision=3):
self.history = []

def __call__(self, selenium):
self.collect() # collect initial element state
while len(self.history) < self.precision:
self.history.append((
str(self.element.location),
str(self.element.size)))
# ensure we have enough states in history to match the precision
time.sleep(0.1) # give the element a chance to change state
self.collect()
return len(set(self.history[-self.precision:])) == 1

def collect(self):
self.history.append((
str(self.element.location),
str(self.element.size)))


class element_not_moving(element_moving):
"""An expectation for checking that an element is not moving.
Expand Down

0 comments on commit e957c4d

Please sign in to comment.