unittest 单元测试框架 web测试

1. 使用unittest单元测试框架

# coding:utf-8
# coding:cp936
from selenium import webdriver
from time import sleep
import unittest

class my_test(unittest.TestCase):           # my_test类继承unittest框架的TestCase类
    def setUp(self):                        # setUp 设置初始化
        self.broswer = webdriver.Chrome()
        self.broswer.maximize_window()
        self.broswer.implicitly_wait(10)
        self.url1 = "http://192.168.129.10"

    def test_baidu(self):                  # 测试脚本
        broswer = self.broswer
        broswer.get(self.url1)
        broswer.find_element_by_id("loguserName").clear()
        broswer.find_element_by_id("loguserName").send_keys("admin")
        broswer.find_element_by_id("loguserPwd").clear()
        broswer.find_element_by_id("loguserPwd").send_keys("12345678")
        broswer.find_element_by_id("btnLogin").click()
        sleep(2)

    def tearDown(self):                  # tearDown 恢复
        self.broswer.quit()

if __name__ == "__main__":
    unittest.main()

你可能感兴趣的:(selenium自动化测试)