zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    随题而学(二)多维数组转一维数组
    随题而学(一)
    谁能破解“无法定位程序输入点ucrtbase.abort与动态链接库api-ms-win-crt-runtime-l1-1-0.dll上”
    虚拟机8—tools安装失败
    win7介绍
    win xp安装
    Linux正则表达式,grep总结,sed用法
    Linux将用户添加到组的指令
    xxx is not in the sudoers file.This incident will be reported.的解决方法
    69-70连接查询
  • 原文地址:https://www.cnblogs.com/lxmtx/p/11917675.html
Copyright © 2011-2022 走看看