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)

 

你可能感兴趣的:(python+selenium自动化测试之登录)