项目创建提交
This commit is contained in:
commit
f92374b617
|
@ -0,0 +1 @@
|
|||
{"cookies": [{"name": "wt_aid", "value": "4fa5e7d6-c9be-4764-8a8e-a012c2f59a0a", "domain": ".pingcode.com", "path": "/", "expires": 1688977282.193057, "httpOnly": false, "secure": false, "sameSite": "Lax"}, {"name": "9daf8dfdc099c207_gdp_user_key", "value": "", "domain": ".pingcode.com", "path": "/", "expires": 1721557967.796379, "httpOnly": false, "secure": false, "sameSite": "Lax"}, {"name": "gdp_user_id", "value": "gioenc-g44d315e%2Cg175%2C5d5a%2Cca0c%2C6c49e819gd7a", "domain": ".pingcode.com", "path": "/", "expires": 1720945282.266952, "httpOnly": false, "secure": false, "sameSite": "Lax"}, {"name": "BAIDUID_BFESS", "value": "B1198C1376C047F9C2B7CD8093295A1A:FG=1", "domain": ".baidu.com", "path": "/", "expires": 1717921282.505039, "httpOnly": false, "secure": true, "sameSite": "None"}, {"name": "AGL_USER_ID", "value": "25ec23c2-fbb1-474a-92d4-8c9a9acbb0f0", "domain": ".pingcode.com", "path": "/", "expires": 1720945282.551833, "httpOnly": false, "secure": false, "sameSite": "Lax"}, {"name": "9daf8dfdc099c207_gdp_cs1", "value": "gioenc-a4agc9b2712c58g9cg5d7853321eb378", "domain": ".pingcode.com", "path": "/", "expires": 1721557967.98716, "httpOnly": false, "secure": false, "sameSite": "Lax"}, {"name": "9daf8dfdc099c207_gdp_gio_id", "value": "gioenc-a4agc9b2712c58g9cg5d7853321eb378", "domain": ".pingcode.com", "path": "/", "expires": 1721557967.98741, "httpOnly": false, "secure": false, "sameSite": "Lax"}, {"name": "9daf8dfdc099c207_gdp_session_id", "value": "5f6536b3-2f3c-4d44-8840-14fa5ebafb03", "domain": ".pingcode.com", "path": "/", "expires": 1686999768, "httpOnly": false, "secure": false, "sameSite": "Lax"}, {"name": "9daf8dfdc099c207_gdp_session_id_5f6536b3-2f3c-4d44-8840-14fa5ebafb03", "value": "true", "domain": ".pingcode.com", "path": "/", "expires": 1721557966.151641, "httpOnly": false, "secure": false, "sameSite": "Lax"}, {"name": "s-647961835acbc8adc29015eb", "value": "6d25f5d7641a419a9e66bd5954a958cf", "domain": ".pingcode.com", "path": "/", "expires": 1687602768.887061, "httpOnly": true, "secure": false, "sameSite": "Lax"}, {"name": "9daf8dfdc099c207_gdp_sequence_ids", "value": "{%22globalKey%22:19%2C%22VISIT%22:3%2C%22PAGE%22:9%2C%22CUSTOM%22:7%2C%22LOGIN_USER_ATTRIBUTES%22:3}", "domain": ".pingcode.com", "path": "/", "expires": 1721557968.137927, "httpOnly": false, "secure": false, "sameSite": "Lax"}], "origins": [{"origin": "https://1234567890.pingcode.com", "localStorage": [{"name": "5f6536b3-2f3c-4d44-8840-14fa5ebafb03_gdp_last_vst", "value": "{\"value\":\"gioenc-{#dwdouUxqd#;#WHRHU#-#aqqWdsrhno#;#0/1/1#-#eauaRntsbdHe#;#a29c2ce7e63348g5#-#edwhbdHe#;#g44d315e,g175,5d5a,ca0c,6c49e819gd7a#-#enlaho#;#0325476981/qhofbned/bnl#-#fhnHe#;#a4agc9b2712c58g9cg5d7853321eb378#-#maoftafd#;#zi,BO#-#qaui#;#.vhjh.rqabdr#-#qmaugnsl#;#vdc#-#rbsddoIdhfiu#;631-#rbsddoVheui#;0391-#rejWdsrhno#;#2/9/3,amqia#-#rdrrhnoHe#;#4g7427c2,3g2b,5e55,9951,05ga4dcagc12#-#uhldrualq#;0797886877056-#uhumd#;#QhofBned#-#trdsHe#;#a4agc9b2712c58g9cg5d7853321eb378#-#usabjhofHe#;#f1#-#fmncamRdptdobdHe#;01-#dwdouRdptdobdHe#;3|\",\"expiredAt\":253402272000000}"}]}, {"origin": "https://pingcode.com", "localStorage": [{"name": "fclog_N4IgLgziBcCMBsAOeBOFB2F93wEywBpwAvGRIgGwHsBzASwBMYQGBDAZgFMBWAFhV4BaWOgBmQ3ulxC08ToN6d07FNxSJRnFAAYQRAA4AnKgwCuAYzB0qAO2YB9UegAyuABoB3AOJuAVgE8IYgAjXgZYTlwqAA8ABX9gmgARPRBzTkMwZlSITggIaxtGZlYGTVFzBEFlTAVzXHNBVk5tRvQwhm561nh4dnNU02LoEFxuTnr+3EFRYODYBXbWQRRcBiFEcxRWbfM57VFdIip9KyYR1MNOTUMrw2YACzAwfQhoAHp32Fx2Xm5sRA6AB0+joNho5hMnCBkIAtu9UtRzKwrLYYKAjFQwFRIRRHs9XiMiA8qBAwDZWLDOMxQeDIQxoXDUvoqJlsgYUQ8KVTmO8CjQinYiLlWIZzA92SAHqwIBKLgBfIhgfz6akjABudAKwToFDoyvFrHB1KIrBgAG1QPYwKwaMwGDjTFSbFliYwGXZoGBDKZOPKALoGUn6wrokDRGDaIj+SOKkCcaJZaBW9XMXBA7RA9ipexa0QwUSsCi5IjRACCxr1rGctGGIFgWD66G+7G06DU8G02h08FSwXMevOID7DAgojFmqHOagIwqtrxRC1ACFOKxIZ7YPL5UA", "value": "fclog_"}]}, {"origin": "https://bvqb20230602032659120.pingcode.com", "localStorage": [{"name": "portal:nav-layout-mode", "value": "\u06e2\u2c2b\u416c\u4020 "}, {"name": "access_token", "value": "\u14e2\u3c34\u404c\u0480\u7126\u1832\u6099\u02e0\u24a1\u2a22\u79c0\u4621\u6433\u2053\u4d20\u7621\u1425\u31e0\u186d\u008c\u3426\u5820\u7023\u203a\u56d0\u0290\u03c5\u032b\u4030\u603d\u2031\u2cb5\u025e\u18a0\u3120\u5b20\u4d20\u2b28\u5521\u3279\u4a23\u5d54\u0151\u5020\u3143\u0e70\u02ec\u52d8\u6036\u402a\u5975\u3e20\u1154\u10fa\u00a5\u4db4\u703a\u2026\u28b3\u4848V\u6551\u2e20\u0cfc\u2542\u4360\u1ad9\u61bd\u2a20\u512b\u36c7\u0239\u2086\u0572\u20e3\u649c\u3874\u4d37\u2a8e\u16ec\u26a0\u4021\u4912\u59b5\u6c91\u351f\u0bb3\u493e\u6cbf\u4770\u0870\u00fc\u0820\u136d\u1938\u0a23\u0660p\u03ba\u7841\u4420\u6641\u405d\u4276\u55a1\u1024\u3bf8X\u4330\u21fb\u31a5\u1193\u218f\u1262\u6023\u2615\u4a71a\u1020 "}, {"name": "lastAccessDashboardId", "value": "\u0da0\u585b\u0159\u40ac\u0100\u3320\u4620\u32f1\u033a\u6073\u1805\u6c25\u306d\u0c94\u4020 "}, {"name": "pingpp_uid", "value": "mCERIo8dTmlwatD5aW8COmQePE1BgvA3"}]}]}
|
|
@ -0,0 +1,11 @@
|
|||
import datetime
|
||||
|
||||
aaa = datetime.datetime.now()
|
||||
|
||||
print(aaa.year)
|
||||
print(aaa.month)
|
||||
print(aaa.day)
|
||||
day_12 = datetime.datetime.now() + datetime.timedelta(days=-12)
|
||||
print(day_12.year)
|
||||
print(day_12.month)
|
||||
print(day_12.day)
|
|
@ -0,0 +1,21 @@
|
|||
from playwright.sync_api import expect, Page
|
||||
|
||||
|
||||
def page_login(page: Page, username: str, password: str):
|
||||
"""
|
||||
通过页面进行登录
|
||||
:param page: page对象
|
||||
:param username:
|
||||
:param password:
|
||||
:return:
|
||||
"""
|
||||
# playwright = sync_playwright().start()
|
||||
# 浏览器 = playwright.chromium.launch(headless=False)
|
||||
# 上下文 = 浏览器.new_context()
|
||||
# page = 上下文.new_page()
|
||||
page.goto("https://0123456789.pingcode.com")
|
||||
page.get_by_placeholder("请输入手机号/邮箱").type(username, delay=30)
|
||||
page.get_by_placeholder("请输入登录密码").fill(password)
|
||||
page.get_by_role("button", name="登录")
|
||||
page.get_by_role("button", name="登录").click()
|
||||
expect(page.locator('.avatar-default').first).to_be_visible()
|
|
@ -0,0 +1,39 @@
|
|||
from playwright.sync_api import expect, Page
|
||||
import os
|
||||
import time
|
||||
from utils.tools import get_path
|
||||
|
||||
|
||||
def page_login_save_cookies(page: Page, username: str, password: str):
|
||||
"""
|
||||
通过页面进行登录
|
||||
:param page: page对象
|
||||
:param username:
|
||||
:param password:
|
||||
:return:
|
||||
"""
|
||||
if os.path.exists(get_path(f"/.auth/{username}.txt")) and int(time.time() - os.path.getctime(get_path(f"/.auth/{username}.txt"))) < 86400:
|
||||
page.context.clear_cookies()
|
||||
with open(get_path(f"/.auth/{username}.txt")) as f:
|
||||
cookies = f.read()
|
||||
cookies = eval(cookies)
|
||||
page.context.add_cookies(cookies)
|
||||
page.goto("https://0123456789.pingcode.com")
|
||||
expect(page.locator('.avatar-default').first).to_be_visible()
|
||||
else:
|
||||
page.context.clear_cookies()
|
||||
page.goto("https://0123456789.pingcode.com")
|
||||
page.get_by_placeholder("请输入手机号/邮箱").type(username, delay=30)
|
||||
page.get_by_placeholder("请输入登录密码").fill(password)
|
||||
page.get_by_role("button", name="登录")
|
||||
page.get_by_role("button", name="登录").click()
|
||||
expect(page.locator('.avatar-default').first).to_be_visible()
|
||||
cookies = page.context.cookies()
|
||||
with open(get_path(f"/.auth/{username}.txt"), "w") as f:
|
||||
f.write(str(cookies))
|
||||
|
||||
|
||||
def 跳转(page: Page, path: str):
|
||||
if path[0] != "/":
|
||||
path = f"/{path}"
|
||||
page.goto(f'{page.url.split(".com")[0]}.com{path}')
|
|
@ -0,0 +1,53 @@
|
|||
from playwright.sync_api import Page
|
||||
from playwright.sync_api import expect, Page
|
||||
import os
|
||||
import time
|
||||
from utils.tools import get_path
|
||||
|
||||
|
||||
class Page_Object:
|
||||
def __init__(self, page: Page):
|
||||
self.page = page
|
||||
def_timeout = 10000
|
||||
self.page.set_default_timeout(def_timeout)
|
||||
self.page.set_default_navigation_timeout(def_timeout)
|
||||
|
||||
def navigate(self):
|
||||
self.跳转()
|
||||
|
||||
def 跳转(self, path: str = None):
|
||||
if path[0] != "/":
|
||||
path = f"/{path}"
|
||||
self.page.goto(f'{self.page.url.split(".com")[0]}.com{path}')
|
||||
|
||||
from playwright.sync_api import expect, Page
|
||||
import os
|
||||
import time
|
||||
from utils.tools import get_path
|
||||
|
||||
def page_login_save_cookies(self, username: str, password: str):
|
||||
"""
|
||||
通过页面进行登录
|
||||
:param username:
|
||||
:param password:
|
||||
:return:
|
||||
"""
|
||||
if os.path.exists(get_path(f"/.auth/{username}.txt")) and int(time.time() - os.path.getctime(get_path(f"/.auth/{username}.txt"))) < 86400:
|
||||
self.page.context.clear_cookies()
|
||||
with open(get_path(f"/.auth/{username}.txt")) as f:
|
||||
cookies = f.read()
|
||||
cookies = eval(cookies)
|
||||
self.page.context.add_cookies(cookies)
|
||||
self.page.goto("https://0123456789.pingcode.com")
|
||||
expect(self.page.locator('.avatar-default').first).to_be_visible()
|
||||
else:
|
||||
self.page.context.clear_cookies()
|
||||
self.page.goto("https://0123456789.pingcode.com")
|
||||
self.page.get_by_placeholder("请输入手机号/邮箱").type(username, delay=30)
|
||||
self.page.get_by_placeholder("请输入登录密码").fill(password)
|
||||
self.page.get_by_role("button", name="登录")
|
||||
self.page.get_by_role("button", name="登录").click()
|
||||
expect(self.page.locator('.avatar-default').first).to_be_visible()
|
||||
cookies = self.page.context.cookies()
|
||||
with open(get_path(f"/.auth/{username}.txt"), "w") as f:
|
||||
f.write(str(cookies))
|
|
@ -0,0 +1,3 @@
|
|||
from modules.Page_object import Page_Object
|
||||
from playwright.sync_api import Page, expect
|
||||
import time
|
|
@ -0,0 +1,39 @@
|
|||
# 人类
|
||||
class human:
|
||||
address = "earth"
|
||||
|
||||
def __init__(self, sex, age, name):
|
||||
self.sex = sex
|
||||
self.age = age
|
||||
self.name = name
|
||||
|
||||
def dance(self):
|
||||
print(f"{self.name} can dance")
|
||||
|
||||
def jump(self):
|
||||
print(f"{self.name} can jump")
|
||||
|
||||
@staticmethod
|
||||
def rap():
|
||||
print("I can rap")
|
||||
|
||||
@classmethod
|
||||
def twoandhalf_year(cls):
|
||||
print("两年半的练习生")
|
||||
|
||||
@property
|
||||
def add_3_age(self):
|
||||
return int(self.age) + 3
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
man = human(sex="man", age="40", name="tom")
|
||||
print(man.name)
|
||||
print(man.address)
|
||||
print(man.age)
|
||||
print(man.sex)
|
||||
man.dance()
|
||||
man.jump()
|
||||
man.rap()
|
||||
human.twoandhalf_year()
|
||||
print(man.add_3_age)
|
|
@ -0,0 +1,23 @@
|
|||
from modules import *
|
||||
|
||||
|
||||
class 产品首页(Page_Object):
|
||||
def __init__(self, page: Page):
|
||||
super().__init__(page)
|
||||
self.新建产品 = self.page.get_by_text("新建产品")
|
||||
self.产品标识 = self.page.get_by_placeholder("大写字母和数字,15 个字符以内")
|
||||
self.输入产品名称 = self.page.get_by_placeholder("输入产品名称")
|
||||
self.选择可见范围 = self.page.locator(' //thy-custom-select[@thyplaceholder="选择可见范围"]')
|
||||
|
||||
def navigate(self):
|
||||
self.跳转("/ship/products")
|
||||
|
||||
def create_产品(self, 产品名称):
|
||||
self.输入产品名称.fill(产品名称)
|
||||
self.选择可见范围.click()
|
||||
self.page.get_by_text("公开").click()
|
||||
self.产品标识.fill(str(time.time_ns())[-12:])
|
||||
self.page.get_by_placeholder("输入产品描述").fill("创建一个产品的测试!")
|
||||
self.page.get_by_text("下一步").click()
|
||||
self.page.get_by_text("确定").click()
|
||||
expect(self.page.get_by_text(产品名称)).to_be_visible()
|
|
@ -0,0 +1,2 @@
|
|||
[pytest]
|
||||
addopts: --headed
|
|
@ -0,0 +1,62 @@
|
|||
# Copyright (c) Microsoft Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import hashlib
|
||||
import shutil
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
from typing import Any, Callable, Dict, Generator, List, Optional
|
||||
|
||||
import pytest
|
||||
from playwright.sync_api import (
|
||||
Browser,
|
||||
BrowserContext,
|
||||
BrowserType,
|
||||
Error,
|
||||
Page,
|
||||
Playwright,
|
||||
sync_playwright,
|
||||
)
|
||||
from slugify import slugify
|
||||
import tempfile
|
||||
from modules.产品首页模块 import 产品首页
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def browser_context_args(browser_context_args):
|
||||
return {
|
||||
**browser_context_args,
|
||||
"viewport": {
|
||||
"width": 1440,
|
||||
"height": 900,
|
||||
},
|
||||
"record_video_size": {
|
||||
"width": 1440,
|
||||
"height": 900,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PageInstance:
|
||||
def __init__(self, page: Page):
|
||||
self.产品首页 = 产品首页(page)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def pw_page(context):
|
||||
page = context.new_page()
|
||||
yield PageInstance(page)
|
|
@ -0,0 +1,20 @@
|
|||
from playwright.sync_api import sync_playwright, expect, Page, BrowserContext, Browser
|
||||
from interface.page_login import page_login
|
||||
from interface.page_login_save_cookie import page_login_save_cookies, 跳转
|
||||
|
||||
|
||||
def test_pw_test(page):
|
||||
playwright = sync_playwright().start()
|
||||
浏览器 = playwright.chromium.launch(headless=False)
|
||||
上下文 = 浏览器.new_context()
|
||||
page = 上下文.new_page()
|
||||
page.goto("https://1234567890.pingcode.com/wiki/spaces")
|
||||
page.get_by_placeholder("请输入手机号/邮箱").type("30278257@qq.com", delay=30)
|
||||
page.get_by_placeholder("请输入登录密码").fill("playwright0")
|
||||
page.get_by_role("button", name="登录")
|
||||
page.get_by_role("button", name="登录").click()
|
||||
expect(page.locator('.avatar-default').first).to_be_visible()
|
||||
page_login_save_cookies(page, "mwn666888@163.com", "winni666888")
|
||||
page_login_save_cookies(page, "30278257@qq.com", "playwright0")
|
||||
跳转(page, "testhub/libraries")
|
||||
page.wait_for_timeout(5000)
|
|
@ -0,0 +1,6 @@
|
|||
def test_产品创建(pw_page):
|
||||
pw_page.产品首页.page_login_save_cookies("30278257@qq.com", "playwright0")
|
||||
pw_page.产品首页.navigate()
|
||||
pw_page.产品首页.新建产品.click()
|
||||
pw_page.产品首页.create_产品("test_7_2")
|
||||
pw_page.产品首页.page.wait_for_timeout(10000)
|
|
@ -0,0 +1,80 @@
|
|||
from interface.page_login_save_cookie import page_login_save_cookies, 跳转
|
||||
from playwright.sync_api import expect, Page
|
||||
import time
|
||||
import pytest
|
||||
产品名称 = ""
|
||||
|
||||
|
||||
def test_创建产品(page):
|
||||
page_login_save_cookies(page, "30278257@qq.com", "playwright0")
|
||||
跳转(page, "/ship/products")
|
||||
page.get_by_text("新建产品").click()
|
||||
global 产品名称
|
||||
产品名称 = f"产品生命周期测试_{time.time_ns()}"
|
||||
page.get_by_placeholder("输入产品名称").fill(产品名称)
|
||||
page.locator(' //thy-custom-select[@thyplaceholder="选择可见范围"]').click()
|
||||
page.get_by_text("公开").click()
|
||||
page.get_by_placeholder("大写字母和数字,15字符以内").fill(str(time.time_ns())[-12:])
|
||||
page.get_by_placeholder("输入产品描述").fill("创建一个产品的测试!")
|
||||
page.get_by_text("下一步").click()
|
||||
page.get_by_text("确定").click()
|
||||
expect(page.get_by_text(产品名称)).to_be_visible()
|
||||
|
||||
|
||||
def test_修改产品(page):
|
||||
page_login_save_cookies(page, "30278257@qq.com", "playwright0")
|
||||
跳转(page, "/ship/products")
|
||||
page.locator('//*[@name="search"]//input').fill(产品名称)
|
||||
page.keyboard.press("Enter")
|
||||
page.get_by_text(产品名称).hover()
|
||||
page.locator('//a[@thytooltip="更多"]').click()
|
||||
page.get_by_text("编辑基本信息").click()
|
||||
page.locator(' //thy-custom-select[@thyplaceholder="选择可见范围"]').click()
|
||||
page.get_by_text("私有").click()
|
||||
产品标识 = str(time.time_ns())[-12:]
|
||||
page.get_by_placeholder("大写字母和数字,15字符以内").fill(产品标识)
|
||||
page.get_by_placeholder("输入产品描述").fill("修改一个产品的测试!")
|
||||
page.get_by_text("确定").click()
|
||||
expect(page.get_by_text("修改产品成功!")).to_be_visible()
|
||||
跳转(page, "/ship/products")
|
||||
page.locator('//*[@name="search"]//input').fill(产品名称)
|
||||
page.keyboard.press("Enter")
|
||||
page.get_by_text(产品名称).hover()
|
||||
page.locator('//a[@thytooltip="更多"]').click()
|
||||
page.get_by_text("产品信息").click()
|
||||
expect(page.get_by_text("私有")).to_be_visible()
|
||||
expect(page.locator(f'//thy-tag[text()="{产品标识}"]')).to_be_visible()
|
||||
expect(page.get_by_text("修改一个产品的测试!")).to_be_visible()
|
||||
|
||||
|
||||
def test_删除产品(page, 删除所有产品生命周期测试_的数据):
|
||||
page_login_save_cookies(page, "30278257@qq.com", "playwright0")
|
||||
跳转(page, "/admin/product/ship/configuration/products")
|
||||
page.locator('//*[@name="search"]//input').fill(产品名称)
|
||||
page.keyboard.press("Enter")
|
||||
page.locator("#axy删除").click()
|
||||
expect(page.get_by_text("删除后如果想找回该产品,可以通过配置中心由管理员进行恢复。")).to_be_visible()
|
||||
page.get_by_text("确定").click()
|
||||
expect(page.get_by_text("删除成功")).to_be_visible()
|
||||
expect(page.get_by_text("暂无数据")).to_be_visible()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def 删除所有产品生命周期测试_的数据(page: Page):
|
||||
yield
|
||||
page_login_save_cookies(page, "30278257@qq.com", "playwright0")
|
||||
跳转(page, "/admin/product/ship/configuration/products")
|
||||
page.locator('//*[@name="search"]//input').fill("产品生命周期测试_")
|
||||
page.keyboard.press("Enter")
|
||||
while True:
|
||||
try:
|
||||
page.get_by_text("暂无数据").wait_for(timeout=3000)
|
||||
break
|
||||
except:
|
||||
page.locator("#axy删除").first.click()
|
||||
page.get_by_text("确定").click()
|
||||
expect(page.get_by_text("删除成功")).to_be_visible()
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
from interface.page_login_save_cookie import page_login_save_cookies, 跳转
|
||||
from playwright.sync_api import expect, Page
|
||||
import time
|
||||
from utils.tools import 日期控件填写
|
||||
import pytest
|
||||
|
||||
|
||||
def test_排期创建(page):
|
||||
page_login_save_cookies(page, "30278257@qq.com", "playwright0")
|
||||
跳转(page, "/ship/products")
|
||||
page.get_by_text("测试专用").click()
|
||||
page.get_by_text("排期").click()
|
||||
page.get_by_text("新建计划").click()
|
||||
计划名称 = f"计划名称_{time.time_ns()}"
|
||||
page.get_by_placeholder("输入计划名称").fill(计划名称)
|
||||
日期控件填写(page, page.get_by_placeholder("选择开始时间"), 0)
|
||||
日期控件填写(page, page.get_by_placeholder("选择结束时间"), 300)
|
||||
page.get_by_text("确定").click()
|
||||
expect(page.locator("tr").filter(has_text=计划名称))
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
from interface.page_login_save_cookie import page_login_save_cookies, 跳转
|
||||
from playwright.sync_api import expect, Page
|
||||
import time
|
||||
from utils.tools import 日期控件填写, get_path
|
||||
import pytest
|
||||
|
||||
|
||||
def test_排期创建(page):
|
||||
page_login_save_cookies(page, "30278257@qq.com", "playwright0")
|
||||
跳转(page, "/ship/products")
|
||||
page.get_by_text("测试专用").click()
|
||||
page.get_by_text("工单").click()
|
||||
while True:
|
||||
try:
|
||||
page.locator('//a[@thytooltip="更多"]').click(timeout=1000)
|
||||
page.get_by_text("导入工单").click(timeout=1000)
|
||||
break
|
||||
except:
|
||||
pass
|
||||
with page.expect_download() as f:
|
||||
page.locator("a").get_by_text("下载模板").click()
|
||||
file_path = get_path(f"download/{time.time_ns()}.xlsx")
|
||||
f.value.save_as(file_path)
|
||||
page.set_input_files('//input[@type="file"]', get_path("upload/testupload.xlsx"))
|
||||
expect(page.get_by_text("testupload.xlsx")).to_be_visible()
|
||||
page.get_by_text("取消").click()
|
||||
page.locator('//span[text()="客户"]').click()
|
||||
page.get_by_text("新建").click()
|
||||
with page.expect_file_chooser() as f:
|
||||
page.get_by_text("点击上传").click()
|
||||
f.value.set_files(get_path("upload/条件.png"))
|
||||
page.get_by_text("确定").last.click()
|
||||
page.wait_for_timeout(100000)
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
from interface.page_login_save_cookie import page_login_save_cookies, 跳转
|
||||
from playwright.sync_api import expect, Page
|
||||
import time
|
||||
import pytest
|
||||
|
||||
|
||||
def test_需求创建(page):
|
||||
page_login_save_cookies(page, "30278257@qq.com", "playwright0")
|
||||
跳转(page, "/ship/products")
|
||||
page.get_by_text("测试专用").click()
|
||||
page.get_by_text("新建需求").click()
|
||||
需求标题 = f"新建需求测试_{time.time_ns()}"
|
||||
page.get_by_placeholder("输入标题").fill(需求标题)
|
||||
page.locator(".thy-icon-bold").click() # 黑体的点击
|
||||
page.locator(".thy-icon-italic").click() # 斜体的点击
|
||||
page.locator(".slate-editable-container").click()
|
||||
page.keyboard.type("测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写")
|
||||
page.keyboard.press("Shift+ArrowLeft")
|
||||
page.keyboard.press("Shift+ArrowLeft")
|
||||
page.locator(".thy-icon-bold").click() # 黑体的点击
|
||||
page.locator(".thy-icon-italic").click() # 斜体的点击
|
||||
expect(page.locator("span").filter(has_text="测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文").first).to_have_attribute("the-bold", "true")
|
||||
expect(page.locator("span").filter(has_text="测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文填写测试需求正文").first).to_have_attribute("the-italic", "true")
|
||||
expect(page.locator("span").filter(has=page.locator('//span[text()="填写"]')).first).not_to_have_attribute("the-bold", "true")
|
||||
expect(page.locator("span").filter(has=page.locator('//span[text()="填写"]')).first).not_to_have_attribute("the-italic", "true")
|
||||
page.get_by_text("确定").click()
|
||||
expect(page.locator("tr").filter(has_text="待评审").filter(has_text=需求标题)).to_be_visible()
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 392 KiB |
|
@ -0,0 +1,22 @@
|
|||
import os
|
||||
from playwright.sync_api import Page, Locator
|
||||
import datetime
|
||||
|
||||
|
||||
def get_path(path: str) -> str:
|
||||
if path[0] != "/":
|
||||
path = f"/{path}"
|
||||
return f"{os.path.abspath(os.path.dirname(os.path.dirname(__file__)))}{path}"
|
||||
|
||||
|
||||
def 日期控件填写(page: Page, locator: Locator, 相对日期: int):
|
||||
temp_time = datetime.datetime.now() + datetime.timedelta(days=相对日期)
|
||||
year = temp_time.year
|
||||
month = temp_time.month
|
||||
day = temp_time.day
|
||||
locator.click()
|
||||
page.locator('.thy-calendar-year-btn').click()
|
||||
page.locator('//td[@role="gridcell"]').filter(has_text=f"{year}").locator("a").click() # 年
|
||||
page.locator('.thy-calendar-month-btn').click()
|
||||
page.locator('//td[@role="gridcell"]').nth(month - 1).click() # 月
|
||||
page.locator('//td[@role="gridcell"][not(contains(@class,"month"))]').filter(has_text=f"{day}").click() # 日
|
Loading…
Reference in New Issue