init: 初始化项目
- 创建了基本的项目结构 - 添加了 .gitignore 文件 - 配置了基本的开发环境 - 添加清华镜像源 - 设置了基础的文件夹和文件(如 commons, utils, POM, pytest.ini) 项目说明: - [项目名称]:Web自动化测试 - [项目描述]:基于pytest,selenium的自动化测试工具 - [开发环境]:Python
This commit is contained in:
22
POM/conftest.py
Normal file
22
POM/conftest.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
"""
|
||||
@author: CNWei
|
||||
@Software: PyCharm
|
||||
@contact: t6i888@163.com
|
||||
@file: conftest
|
||||
@date: 2025/4/5 09:28
|
||||
@desc:
|
||||
"""
|
||||
import pytest
|
||||
from selenium.webdriver import Chrome
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def driver():
|
||||
_driver = Chrome()
|
||||
yield _driver
|
||||
_driver.quit()
|
||||
|
||||
|
||||
55
POM/login_page.py
Normal file
55
POM/login_page.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/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)
|
||||
39
POM/test_login.py
Normal file
39
POM/test_login.py
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
"""
|
||||
@author: CNWei
|
||||
@Software: PyCharm
|
||||
@contact: t6i888@163.com
|
||||
@file: main
|
||||
@date: 2025/4/4 17:52
|
||||
@desc:
|
||||
"""
|
||||
from time import sleep
|
||||
import pytest
|
||||
from selenium.webdriver import Chrome
|
||||
from login_page import LoginPage
|
||||
from commons.modules import Browser
|
||||
|
||||
|
||||
@pytest.mark.parametrize("email, password", [("username", "password"), ("<EMAIL>", "<PASSWORD>")])
|
||||
def test_login(driver, email, password):
|
||||
login = LoginPage()
|
||||
|
||||
login.login(email, password)
|
||||
# sleep(10)
|
||||
|
||||
|
||||
def test_logout_1(login_ok):
|
||||
login = LoginPage()
|
||||
login.browser(Browser.CHROME)
|
||||
login.get("https://www.baidu.com/")
|
||||
print("logout")
|
||||
|
||||
|
||||
# @pytest.mark.usefixtures("login_ok")
|
||||
def test_logout_2():
|
||||
login = LoginPage()
|
||||
login.browser(Browser.CHROME)
|
||||
login.get("https://www.baidu.com/")
|
||||
print("logout")
|
||||
Reference in New Issue
Block a user