The operation of the data driving python Excel (Method a)

A, Mail163.xlsx the following data:

 

 

Two, Mail163.py script as follows

to xlrd Import 
Import the unittest
from the webdriver Selenium Import
from selenium.webdriver.common.by Import By
Import Time

# installation: the install to xlrd PIP
DEF readExcel (nrow):
'' 'Excel data read' ''
Table xlrd.open_workbook = ( 'Mail163 .xlsx ',' R & lt ')
Sheet = table.sheet_by_index (0)
return sheet.row_values (nrow)

DEF readusername (nrow):
' '' reads the user name data '' '
return readExcel (nrow) [0]

DEF readpassword (nrow):
'' 'reads the password data' ''
return readExcel (nrow) [. 1]

DEF ReadResult (nrow):
'' 'to read the expected result data' ''
return readExcel(nrow)[2]

class Mail_163(unittest.TestCase):
def setUp(self) -> None:
self.driver = webdriver.Chrome()
self.driver.maximize_window()
self.driver.implicitly_wait(5)
self.driver.get("https://mail.163.com/")

def tearDown(self) -> None:
self.driver.quit()

def login_163(self,username,password):
#验证登录163邮箱N中情况
self.driver.find_element(By.ID,"switchAccountLogin").click()
iframe = self.driver.find_element(By.TAG_NAME,'iframe')
self.driver.switch_to_frame(iframe)
self.driver.find_element(By.NAME,'email').send_keys(username)
self.driver.find_element(By.NAME,'password').send_keys(password)
time.sleep(1)
self.driver.find_element (By.ID, "doLogin") the Click ().

DEF Assert_Text (Self):
# asserted: text asserts
the try:
divtext = self.driver.find_element (By.CSS_SELECTOR, 'div.ferrorhead'). text
return divtext
the except Exception aS MSG:
Print (. "assertion failures} {" the format (MSG))
self.driver.switch_to_default_content ()

DEF test_username_password_null (Self):
'' 'authentication: user name and password is empty error message indicates' ''
self.login_163 (readusername (. 1), readpassword (. 1))
self.assertEqual (self.Assert_Text (), ReadResult (. 1))

DEF test_username_null (Self):
'' 'authentication: user name blank password is not empty the error message indicates' ''
self.login_163 (readusername (2), readpassword (2))
self.assertEqual (self.Assert_Text (), ReadResult (2))

DEF test_passwd_null (Self):
'' 'Authentication: User name is not empty error message indicates a null password' ''
self.login_163 (readusername (. 3), readpassword (3))
self.assertEqual (self.Assert_Text (), ReadResult (3))

DEF test_username_input_format (Self):
'' 'verify: enter the username illegal character error message prompts' ''
self.login_163 (readusername (4 ), readpassword (. 4))
self.assertEqual (self.Assert_Text (), ReadResult (. 4))


IF the __name__ == '__main__':
unittest.main (the verbosity = 2) # log details

Guess you like

Origin www.cnblogs.com/Teachertao/p/11707748.html