First of all, I created several functions in order to use them instead of the "find_element_by _..." and login () functions by default to create a "browser". Here is how I use it:
def login():
browser = webdriver.Firefox()
return browser
def find_element_by_id_u(browser, element):
try:
obj = WebDriverWait(browser, 10).until(
lambda browser : browser.find_element_by_id(element)
)
return obj
driver = login()
find_element_by_link_text_u(driver, 'the_id')
Now I use such tests through jenkins (and run them in a virtual machine). And in case I got a TimeoutException, the browser session will not be killed, and I will have to manually go to the virtual machine and kill the Firefox process. And Jenkins won't stop working while the web browser is running.
, , , - .
, , . , , , :
def find_element_by_id_u(browser, element):
try:
obj = WebDriverWait(browser, 1).until(
lambda browser : browser.find_element_by_id(element)
)
return obj
except TimeoutException, err:
print "Timeout Exception for element '{elem}' using find_element_by_id\n".format(elem = element)
print traceback.format_exc()
browser.close()
sys.exit(1)
driver = login()
driver .get(host)
find_element_by_id_u('jj_username').send_keys('login' + Keys.TAB + 'passwd' + Keys.RETURN)
"lambda browser: browser.find_element_by_id (element)", . 3000 , .
.
PS: , , login(), script .