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

the unittest Import 
from Import DDT DDT, the unpack, Data
from the webdriver Selenium Import
from selenium.webdriver.common.by By Import
Import the unittest, Time

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

# @ represented for extracting the unpack yuan set 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 name and password is empty the user name is blank password is not empty, the password is blank user name is not an error message is returned empty

def getdata ():
isolated # data to the list
return [
[ '', '', 'Please enter the account number'],
[ 'ADMIN', '', 'Please input password']
[ ',' ADMIN ',' Please enter the account number ']
[' ^^^ ',' ',' account malformed ']
]

@ddt
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()

@data(*getdata())
@unpack
def test_login_163(self,username,password,result):
#验证登录163邮箱N中情况
self.driver.find_element(By.ID,"switchAccountLogin").click()
#iframe框架
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 ()
divtext = self.driver.find_element (By.CSS_SELECTOR, 'div.ferrorhead') text.
# Print ( "error message:", divtext)
# assertions - assertion error
self.assertEqual (divtext, the Result)
# exit iframe framework
self.driver.switch_to_default_content ()

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


Guess you like

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