Mail163.yaml configuration file as follows:
login_data:
url: 'https://mail.163.com/'
Case1:
the User: ''
passwd: ''
errorText: 'Please enter account number'
Case2:
the User: 'ADMIN'
passwd: ''
errorText: 'Please enter your password '
Case3:
User:' '
the passwd:' ADMIN '
Case 4:
User: "&&& ^^^'
the passwd: ''
the errorText: 'account malformed'
YAML Import
Import unittest
from the Selenium Import webdriver
from selenium.webdriver.common.by By Import
Import Time
#yaml Profile https://www.ibm.com/developerworks/cn/xml/x-cn-yamlintro/index.html
# installation : PIP yaml the install
DEF getData ():
# yaml read value
yamlindex = Open ( 'Mail163.yaml', 'R & lt', encoding = 'UTF-. 8')
# read out the contents of the file
data = yaml.load ( yamlindex)
return Data
class Mail_163 (of unittest.TestCase):
DEF the 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").click()
def Assert_Text(self):
#断言 :文本断言
try:
divtext = self.driver.find_element(By.CSS_SELECTOR, 'div.ferrorhead').text
divtext return
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 (getData () [' Case1 '] [' User '], getData () [' Case1 '] [' the passwd '])
self.assertEqual (self.Assert_Text (), getData () [' Case1 ' ] [ 'the errorText'])
DEF test_username_null (Self):
'' 'authentication: user name is not empty blank password prompt an error message to' ''
self.login_163 (getData () [ 'Case2'] [ 'user'] , getData () [ 'Case2'] [ 'the passwd'])
self.assertEqual (self.Assert_Text (), getData () [ 'Case2'] [ 'errorText'])
DEF test_passwd_null (Self):
'' 'Authentication: User name is not empty blank password prompt an error message' ''
self.login_163 (getData () [ 'Case3'] [ 'User'], getData () [ 'Case3'] [ 'the passwd'])
self.assertEqual (self.Assert_Text (), getData () [ 'Case1'] [ 'errorText'])
DEF test_username_input_format (Self):
'' 'authentication: user name input error message prompts illegal character' ''
self.login_163 (getData () [ 'Case 4'] [ 'the user'], getData () [ 'Case 4'] [ 'the passwd'])
self.assertEqual (self.Assert_Text (), getData () [ 'Case 4'] [ 'the errorText'])
IF the __name__ == '__main__':
unittest.main (the verbosity = 2 )