- 创建了基本的项目结构 - 添加了 .gitignore 文件 - 配置了基本的开发环境 - 添加清华镜像源 - 设置了基础的文件夹和文件(如 commons, utils, POM, pytest.ini) 项目说明: - [项目名称]:Web自动化测试 - [项目描述]:基于pytest,selenium的自动化测试工具 - [开发环境]:Python
56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
#!/usr/bin/env python
|
|
# coding=utf-8
|
|
|
|
"""
|
|
@author: CNWei
|
|
@Software: PyCharm
|
|
@contact: t6i888@163.com
|
|
@file: test_login
|
|
@date: 2025/4/4 15:42
|
|
@desc:
|
|
"""
|
|
from time import sleep
|
|
|
|
from selenium.webdriver import Chrome
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.remote.webdriver import WebDriver
|
|
from commons.modules import Browser
|
|
|
|
import pytest
|
|
|
|
from commons.driver import KeyWordDriver
|
|
|
|
|
|
class LoginPage(KeyWordDriver):
|
|
url = "/users/login"
|
|
email = '//*[@id="email"]'
|
|
email_title = '//*[@id="root"]/div[1]/div/div/form/div[1]/label'
|
|
password = '//*[@id="pass"]'
|
|
login_submit = '//*[@id="root"]/div[1]/div/div/form/div[3]/button'
|
|
|
|
# def __init__(self, browser: Browser):
|
|
# super().__init__(browser)
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def login(self, email, password):
|
|
self.browser(Browser.EDGE)
|
|
self.get(self.url)
|
|
self.input(1, self.email, email)
|
|
self.input(By.XPATH, self.password, password)
|
|
text = self.get_text(By.XPATH, self.email_title)
|
|
print(text)
|
|
self.click(By.XPATH, self.login_submit)
|
|
sleep(10)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
from commons.settings import configs
|
|
|
|
_email = configs.username
|
|
_password = configs.password
|
|
login = LoginPage()
|
|
login.base_url(configs.base_url)
|
|
|
|
login.login(_email, _password)
|