• python+selenium自动化测试之登录


    selenium_login.py
    
    
    import unittest
    from selenium import webdriver
    
    
    class LoginTest(unittest.TestCase):
        @classmethod
        def setUpClass(cls):
            cls.driver = webdriver.Chrome()
            cls.driver.implicitly_wait(5)
            cls.driver.maximize_window()
    
            cls.driver.get('http://pms.yuncesu12.cn/login')
    # 用户名错误密码正确
        def testlogin(self):
            login_account = self.driver.find_element_by_name('account')
            login_account.clear()
            login_account.send_keys('')
            # name = self.driver.find_element_by_xpath("//input[@class='layui-input']")
            login_password = self.driver.find_element_by_name('password')
            login_password.clear()
            login_password.send_keys('123456')
            login_button = self.driver.find_element_by_class_name('layui-btn')
            login_button.click()
            print('用户名或密码错误')
    
    
        @classmethod
        def tearDownClass(cls):
            # cls.driver.quit()
            pass
    
    
    if __name__ == '__main__':
        unittest.main(verbosity=2)
    selenium_login1.py
    
    
    import unittest
    from selenium import webdriver
    
    
    class LoginTest1(unittest.TestCase):
        @classmethod
        def setUpClass(cls):
            cls.driver = webdriver.Chrome()
            cls.driver.implicitly_wait(5)
            cls.driver.maximize_window()
    
            cls.driver.get('http://pms.yuncesu12.cn/login')
    
        # 用户名正确密码错误
        def testlogin1(self):
            login_account = self.driver.find_element_by_name('account')
            login_account.clear()
            login_account.send_keys('墨子')
            # name = self.driver.find_element_by_xpath("//input[@class='layui-input']")
            login_password = self.driver.find_element_by_name('password')
            login_password.clear()
            login_password.send_keys('12346')
            login_button = self.driver.find_element_by_class_name('layui-btn')
            login_button.click()
            print('用户名或密码错误')
    
        @classmethod
        def tearDownClass(cls):
            # cls.driver.quit()
            pass
    
    
    if __name__ == '__main__':
        unittest.main(verbosity=2)




    selenium_login2.py
    
    import unittest
    from selenium import webdriver
    
    
    class LoginTest2(unittest.TestCase):
        @classmethod
        def setUpClass(cls):
            cls.driver = webdriver.Chrome()
            cls.driver.implicitly_wait(5)
            cls.driver.maximize_window()
    
            cls.driver.get('http://pms.yuncesu.cn/login')
    
        # 用户名密码都错误
        def testlogin2(self):
            login_account = self.driver.find_element_by_name('account')
            login_account.clear()
            login_account.send_keys('墨')
            # name = self.driver.find_element_by_xpath("//input[@class='layui-input']")
            login_password = self.driver.find_element_by_name('password')
            login_password.clear()
            login_password.send_keys('12346')
            login_button = self.driver.find_element_by_class_name('layui-btn')
            login_button.click()
            print('用户名或密码错误')
    
        @classmethod
        def tearDownClass(cls):
            # cls.driver.quit()
            pass
    
    
    if __name__ == '__main__':
        unittest.main(verbosity=2)
    selenium_login3.py
    
    
    import unittest
    from selenium import webdriver
    
    
    class LoginTest3(unittest.TestCase):
        @classmethod
        def setUpClass(cls):
            cls.driver = webdriver.Chrome()
            cls.driver.implicitly_wait(5)
            cls.driver.maximize_window()
    
            cls.driver.get('http://pms.yuncesu12.cn/login')
    
        # 用户名正确密码为空
        def testlogin3(self):
            login_account = self.driver.find_element_by_name('account')
            login_account.clear()
            login_account.send_keys('')
            # name = self.driver.find_element_by_xpath("//input[@class='layui-input']")
            login_password = self.driver.find_element_by_name('password')
            login_password.clear()
            login_password.send_keys('')
            login_button = self.driver.find_element_by_class_name('layui-btn')
            login_button.click()
            print('用户名或密码不能为空')
    
        @classmethod
        def tearDownClass(cls):
            # cls.driver.quit()
            pass
    
    
    if __name__ == '__main__':
        unittest.main(verbosity=2)
    selenium_login4.py
    
    
    import unittest
    from selenium import webdriver
    
    
    class LoginTest4(unittest.TestCase):
        @classmethod
        def setUpClass(cls):
            cls.driver = webdriver.Chrome()
            cls.driver.implicitly_wait(5)
            cls.driver.maximize_window()
    
            cls.driver.get('http://pms.yuncesu12.cn/login')
    
        # 用户名正确都正确
        def testlogin4(self):
            login_account = self.driver.find_element_by_name('account')
            login_account.clear()
            login_account.send_keys('墨子')
            # name = self.driver.find_element_by_xpath("//input[@class='layui-input']")
            login_password = self.driver.find_element_by_name('password')
            login_password.clear()
            login_password.send_keys('123456')
            login_button = self.driver.find_element_by_class_name('layui-btn')
            login_button.click()
            print('登录成功!')
    
        @classmethod
        def tearDownClass(cls):
            # cls.driver.quit()
            pass
    
    
    if __name__ == '__main__':
        unittest.main(verbosity=2)
    testloginsuites.py
    
    
    from selenium_login import LoginTest
    from selenium_login1 import  LoginTest1
    from selenium_login2 import LoginTest2
    from selenium_login3 import LoginTest3
    from selenium_login4 import LoginTest4
    import unittest
    
    login_test = unittest.TestLoader().loadTestsFromTestCase(LoginTest)
    login_test1 = unittest.TestLoader().loadTestsFromTestCase(LoginTest1)
    login_test2 = unittest.TestLoader().loadTestsFromTestCase(LoginTest2)
    login_test3 = unittest.TestLoader().loadTestsFromTestCase(LoginTest3)
    login_test4 = unittest.TestLoader().loadTestsFromTestCase(LoginTest4)
    
    smoke_test = unittest.TestSuite([login_test,login_test1,login_test2 ,login_test3,login_test4])
    
    if __name__ == '__main__':
        unittest.TextTestRunner(verbosity=2).run(smoke_test)
  • 相关阅读:
    Asp.Net Mvc: 应用BindAttribute
    Mvc内建功能(DefaultModelBinder)自动绑定。
    生成随机字母字符串(数字字母混和)
    C#中实现输入汉字获取其拼音(汉字转拼音)的2种方法
    集合里查找数据
    C#自定义导出数据到Excel中的类封装
    MySQL性能优化的最佳20+条经验
    DevExpress.XtraGrid.view.gridview 属性说明
    c# 连接Mysql数据库
    ADO.NET 结构 集中数据库联接结构
  • 原文地址:https://www.cnblogs.com/lxmtx/p/11917675.html
Copyright © 2020-2023  润新知