-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
aino980
committed
Aug 15, 2024
1 parent
de0c9d9
commit aeb1044
Showing
12 changed files
with
121 additions
and
47 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from module import * | ||
from module.BasePage import PageObject | ||
|
||
|
||
class Baidu(PageObject): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,48 @@ | ||
import pytest | ||
import time | ||
from playwright.sync_api import Page, expect, BrowserContext | ||
import os | ||
import sys | ||
import re | ||
from playwright.sync_api import Page, expect, BrowserContext, Locator | ||
from module.BasePage import PageObject | ||
from utils.GetPath import get_path | ||
from filelock import FileLock | ||
from data_module.my_Data import MyData | ||
from data_module.auth_Data import MyData | ||
from utils.globalMap import GlobalMap | ||
from module.BaiduPage import Baidu | ||
from module.登录页 import 登录页_类 | ||
from module.我的任务 import 我的任务_类 | ||
from module.项目集 import 项目集_类 | ||
from module.项目集 import 项目集_类 | ||
|
||
|
||
class PageIns: | ||
def __init__(self, page: Page): | ||
self.page = page | ||
self.百度 = Baidu(self.page) | ||
self.登录页 = 登录页_类(self.page) | ||
self.我的任务 = 我的任务_类(self.page) | ||
self.项目集 = 项目集_类(self.page) | ||
|
||
@staticmethod | ||
def 使用new_context登录并返回实例化的page(new_context, 用户别名): | ||
global_map = GlobalMap() | ||
被测环境 = global_map.get("env") | ||
用户名 = MyData().userinfo(被测环境, 用户别名)["username"] | ||
密码 = MyData().userinfo(被测环境, 用户别名)["password"] | ||
with FileLock(get_path(f".temp/{被测环境}-{用户别名}.lock")): | ||
if os.path.exists(get_path(f".temp/{被测环境}-{用户别名}.json")): | ||
context: BrowserContext = new_context(storage_state=get_path(f".temp/{被测环境}-{用户别名}.json")) | ||
page = context.new_page() | ||
my_page = PageIns(page) | ||
my_page.我的任务.navigate() | ||
expect(my_page.登录页.用户名输入框.or_(my_page.登录页.通知铃铛)).to_be_visible() | ||
if my_page.登录页.用户名输入框.count(): | ||
my_page.登录页.登录(用户名, 密码) | ||
my_page.page.context.storage_state(path=get_path(f".temp/{被测环境}-{用户别名}.json")) | ||
else: | ||
context: BrowserContext = new_context() | ||
page = context.new_page() | ||
my_page = PageIns(page) | ||
my_page.登录页.登录(用户名, 密码) | ||
my_page.page.context.storage_state(path=get_path(f".temp/{被测环境}-{用户别名}.json")) | ||
return my_page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import random | ||
|
||
from module import * | ||
|
||
|
||
class Table: | ||
def __init__(self, page: Page, 唯一文字: str, 表格序号: int = -1): | ||
self.page = page | ||
self.page.wait_for_load_state("networkidle") | ||
self.table_div = self.page.locator(".ant-table-wrapper").filter(has_text=唯一文字).nth(表格序号) | ||
self.table_header_tr = self.table_div.locator("//thead/tr") | ||
|
||
def get_header_index(self, 表头文字: str) -> int: | ||
return self.table_header_tr.locator("th").all_text_contents().index(表头文字) | ||
|
||
def get_row_locator(self, 行元素定位: Locator) -> Locator: | ||
return self.table_div.locator("tr").filter(has=行元素定位) | ||
|
||
def get_cell(self, 表头文字or列序号: str | int, 行元素定位or行序号or行文字: Locator | int | str) -> Locator: | ||
if isinstance(表头文字or列序号, str): | ||
列序号 = self.get_header_index(表头文字or列序号) | ||
else: | ||
列序号 = 表头文字or列序号 | ||
|
||
if isinstance(行元素定位or行序号or行文字, Locator): | ||
行定位 = self.get_row_locator(行元素定位or行序号or行文字) | ||
elif isinstance(行元素定位or行序号or行文字, str): | ||
行定位 = self.table_div.locator("tr").filter(has_text=行元素定位or行序号or行文字) | ||
else: | ||
行定位 = self.table_div.locator("tbody").locator('//tr[not(@aria-hidden="true")]').nth(行元素定位or行序号or行文字) | ||
|
||
return 行定位.locator("td").nth(列序号) | ||
|
||
def get_row_dict(self, 行元素定位or行序号: Locator | int = "random") -> dict: | ||
if isinstance(行元素定位or行序号, int): | ||
tr = self.table_div.locator("tbody").locator("tr").locator("visible=true").nth(行元素定位or行序号) | ||
elif isinstance(行元素定位or行序号, Locator): | ||
tr = self.table_div.locator("tr").filter(has=行元素定位or行序号) | ||
else: | ||
all_tr = self.table_div.locator("tbody").locator("tr").locator("visible=ture").all() | ||
tr = random.choice(all_tr) | ||
|
||
td_text_list = tr.locator("td").all_text_contents() | ||
header_text_list = self.table_header_tr.locator("th").all_text_contents() | ||
row_dict = dict(zip(header_text_list, td_text_list)) | ||
return row_dict | ||
|
||
def get_col_list(self, 表头文字: str) -> list: | ||
index = self.get_header_index(表头文字) | ||
all_tr = self.table_div.locator("tbody").locator("tr").locator("visible=true").all() | ||
col_list = [] | ||
for tr in all_tr: | ||
col_list.append(tr.locator("td").nth(index).text_content()) | ||
return col_list | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from module import * | ||
from module.BasePage import PageObject | ||
|
||
|
||
class 我的任务_类(PageObject): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from module import * | ||
from module.BasePage import PageObject | ||
|
||
|
||
class 登录页_类(PageObject): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from playwright.sync_api import Page, expect, Browser, BrowserContext | ||
from module.PageInstance import PageIns | ||
from module import PageIns | ||
import pytest | ||
from filelock import FileLock | ||
from utils.GetPath import get_path | ||
from utils.globalMap import GlobalMap | ||
from module.BasePage import 使用new_context登录并返回实例化的page | ||
from module import PageIns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from testcases import * | ||
|
||
|
||
def test_new_context(new_context): | ||
my_page_测试员 = PageIns.使用new_context登录并返回实例化的page(new_context, "测试员") | ||
my_page_测试员.项目集.navigate() | ||
# index = my_page_测试员.项目集.主表格.get_header_index("开始时间") | ||
# loc = my_page_测试员.项目集.主表格.get_row_locator(my_page_测试员.page.get_by_text("table_test")) | ||
# my_page_测试员.项目集.主表格.get_cell(1, 10).text_content() | ||
# my_page_测试员.项目集.主表格.get_row_dict() | ||
my_page_测试员.项目集.主表格.get_col_list() |