I have a Selenium LiveServerTestCase (django project) that tests an AJAXy page. After the main page loads, there's a delay before another item loads, and I need to test for that second item. I'm trying to include a smart way to wait without doing time.sleep(too_long), but the test always fails unless I insert a pdb breakpoint.
def some_test_thing(self):
#loads a page with some ajaxy stuff, so there's a
#delay that needs to be accounted for
url = "something..."
self.browser.get(url)
#import ipdb;ipdb.set_trace() #this test only passes with this statement, wtf^^?
self.assertWithWait(self.assert_, args=(some_args,))
and I use the convenience function assertWithWait, which tries the assertion in a loop, catching the AssertionError if the test fails, until a timeout.
def assertWithWait(self, assertion, timeout=10, args=(), kwargs={}):
total_time = 0
while total_time < timeout:
try:
assertion(*args, **kwargs)
except AssertionError:
pass
else: # assertion passed
return
time.sleep(0.2)
total_time += 0.2
assertion(*args, **kwargs) # final try, will cause test failure if unsuccessful
The problem is that the test always fails if I don't have that pdb breakpoint - the loop runs until the timeout at 10 seconds. However, if I include that pdb breakpoint, and even if I enter "c" and continue immediately (like within 1 second), the test will pass. So clearly it's not a timing issue, because the test completes successfully well within the 10 second timeout in the breakpoint case, but fails after waiting 10 seconds in the no-breakpoint case. So it seems like something related to multiprocessing or multithreading that Selenium is doing, that maybe gets released by the pdb breakpoint? I'm grabbing at straws a bit here.
Help!
Aucun commentaire:
Enregistrer un commentaire