Passing variables to functions in Python
Posted
by
brno792
on Stack Overflow
See other posts from Stack Overflow
or by brno792
Published on 2012-12-07T23:01:17Z
Indexed on
2012/12/07
23:03 UTC
Read the original article
Hit count: 245
Im writing test scripts in python for selenium web testing.
How do I pass parameters through a python function to call in a later function? I first have a login test function. Then I have a new user registration function. Im trying to pass the Username and Password I use in the registration function to the testLogin function that I call inside the testRegister function.
This is my python code:
userName = "admin"
password = "admin"
#pass username and password variables to this function
def testLogin(userName,password):
browser = webdriver.Firefox()
browser.get("http://url/login")
element = browser.find_element_by_name("userName")
element.send_keys(userName)
element = browser.find_element_by_name("userPassword")
element.send_keys(password)
element.send_keys(Keys.RETURN)
browser.close()
# test registration
def testRegister():
browser = webdriver.Firefox()
browser.get("http://url/register")
#new username variable
newUserName = "test"
element = browser.find_element_by_name("regUser")
element.send_keys(newUserName)
#new password variable
newUserPassword = "test"
element = browser.find_element_by_name("regPassword")
element.send_keys(newUserPassword)
#
#now test if user is registered, I want to call testLogin with the test user name and pw.
testLogin(newUserName,newUserPassword)
browser.close()
© Stack Overflow or respective owner