Reputation: 33
I'm trying to run this:
import unittest
import wd.parallel
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException
import copy
class Selenium2OnSauce(unittest.TestCase):
def setUp(self):
desired_capabilities = []
browser = copy.copy(webdriver.DesiredCapabilities.FIREFOX)
browser['version'] = '10'
browser['platform'] = 'XP'
browser['name'] = 'Python at Sauce'
browser['tags'] = "Parallel"
desired_capabilities += [browser]
self.drivers = wd.parallel.Remote(
desired_capabilities=desired_capabilities,
command_executor="http://user-string:[email protected]:80/wd/hub"
)
def ajax_complete(driver):
try:
return 0 == driver.execute_script("return JQuery.active")
except WebDriverException:
pass
@wd.parallel.multiply
def test_sauce(self):
self.driver.get('http://url.com')
username = self.driver.find_element_by_id('id_username')
print "Found Username"
username.send_keys('[email protected]')
print "Username Entered"
password = self.driver.find_element_by_id('id_password')
print "Found Password"
password.send_keys('testuser')
print "Password Entered"
password.submit()
print "Logged in"
self.driver.find_elements_by_link_text('Notification')[0].click()
print "Going to Notification"
WebDriverWait(self.driver, 10).until(
ajax_complete, "Timeout waiting for page to load"
)
print "ajax loaded string" in self.drive.page_source
@wd.parallel.multiply
def tearDown(self):
print("Link to your job: https://saucelabs.com/jobs/%s" % self.driver.session_id)
self.driver.quit()
print "Quit"
if __name__ == '__main__':
unittest.main()
When I do so I get this:
Found Username
Entered Username
Found Password
Entered Password
Logged in
Going to Cal
Process Process-1:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "build/bdist.macosx-10.8-intel/egg/wd/parallel.py", line 88, in thread_func
f(SubTest(driver))
File "functionalTest.py", line 57, in test_sauce
ajax_complete, "Timeout waiting for page to load"
NameError: global name 'ajax_complete' is not defined
Link to your job: https://saucelabs.com/jobs/06022dc1f54548d98a75f59bd211848d
Quit
I think I'm having trouble accessing the var call ajax_complete
, but i don't know why!
At the end of the day what I want to do is wait for all ajax to be completed before I run my next test...
NOTE: I'm a python newbie, So I'm sorry is this question is really silly.
Upvotes: 1
Views: 3442
Reputation: 599748
Methods in Python are accessed via self
:
WebDriverWait(self.driver, 10).until(
self.ajax_complete, "Timeout waiting for page to load"
)
Note that the ajax_complete
method itself also needs to take self
as the first argument.
Upvotes: 1