web自动化-登录
Posted 测试媛S
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了web自动化-登录相关的知识,希望对你有一定的参考价值。
from selenium import webdriver
import unittest
import time
from ddt import ddt, data
from pages.login_page import LoginPage
from datas import login_data
from common.read_config import ReadConfig
from common.log import Log
@ddt
class TestLogin(unittest.TestCase):
"""登录"""
config = ReadConfig()
log = Log()
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome()
url = cls.config.get_value(‘environment‘, ‘url‘)
cls.driver.get(url)
cls.driver.maximize_window()
cls.login_page = LoginPage(cls.driver)
def setUp(self):
pass
def test_login_success(self):
self.login_page.send_phone_value(login_data.correct[‘phone‘])
self.login_page.send_password_value(login_data.correct[‘password‘])
self.login_page.click_submit_element()
try:
self.assertTrue(login_data.correct[‘expected‘] in self.login_page.get_success_info().text)
except AssertionError as e:
self.log.log_error(‘断言失败{}‘.format(e))
@data(*login_data.error_msg)
def test_login_error_msg(self, data):
self.login_page.send_phone_value(data[‘phone‘])
self.login_page.send_password_value(data[‘password‘])
self.login_page.click_submit_element()
time.sleep(3)
try:
self.assertTrue(data[‘expected‘] == self.login_page.get_error_msg_info().text)
except AssertionError as e:
self.log.log_error(‘断言失败{}‘.format(e))
self.login_page.clear_phone_value()
self.login_page.clear_password_value()
def test_login_error_flash(self):
self.login_page.send_phone_value(login_data.error_flash[‘phone‘])
self.login_page.send_password_value(login_data.error_flash[‘password‘])
self.login_page.click_submit_element()
time.sleep(3)
try:
self.assertTrue(login_data.error_flash[‘expected‘] == self.login_page.get_error_flash_info().text)
except AssertionError as e:
self.log.log_error(‘断言失败{}‘.format(e))
self.login_page.clear_phone_value()
self.login_page.clear_password_value()
def tearDown(self):
pass
@classmethod
def tearDownClass(cls):
cls.driver.quit()
if __name__==‘__main__‘:
unittest.main()
以上是关于web自动化-登录的主要内容,如果未能解决你的问题,请参考以下文章
Cypress web自动化31-request发post请求登录接口