The operation of the data driving ddt python (Method c)

the unittest Import 
from the webdriver Selenium Import
from selenium.webdriver.common.by By Import
Import the unittest, Time
from Parameterized Import Parameterized

# installation: the install PIP Parameterized

# data-driven model
# Excel DDT DDT TXT + + + DDT DDT YAML

# @ represented by the unpack to extract tuples to multiple parameters
# applications: ui-level automated testing can be achieved in the preparation of test cases to achieve a number of different test points to verify
# 163 E-mail login page for example, there are a variety of test conditions, such as user names and passwords is empty, the user name is blank password is not empty, the password is blank user name is not empty return error messages


class Mail_163 (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):
# verification was 163 N in the case of a mailbox
self.driver.find_element (By.ID, "switchAccountLogin") the Click ().
iframes = self.driver.find_element (By.TAG_NAME, 'iframes')
self.driver.switch_to_frame (iframes)
self.driver.find_element (By.NAME, 'In Email'). send_keys (username)
self.driver.find_element (By.NAME, 'password') .send_keys (password)
the time.sleep (. 1)
self.driver.find_element (By.ID, "doLogin"). the Click ()

# only one list, a list of tuples there
@ parameterized.expand (
[( '', ' ',' Please enter your account "),
(" ADMIN ',' ',' Please enter your password '),
('',' ADMIN ',' Please enter your account '),
(' ^ ^ ^ ',' ',' account malformed ')])
def test_login(self,username,password,result):
#登录163 --异常处理
self.login_163(username,password)
time.sleep(2)
try:
divtext = self.driver.find_element(By.CSS_SELECTOR, 'div.ferrorhead').text
print("错误信息:", divtext)
self.assertEqual(divtext, result)
except Exception as msg:
print("断言失败{}".format(msg))
self.driver.switch_to_default_content()

if __name__ == '__main__':
unittest.main(verbosity=2)

Guess you like

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