diff --git a/case/test_dde_1271027.py b/case/test_dde_1271027.py new file mode 100644 index 0000000000000000000000000000000000000000..861dff84cee99f69d0933cb05f2d289ad7c0d5d4 --- /dev/null +++ b/case/test_dde_1271027.py @@ -0,0 +1,23 @@ +from case.base_case import BaseCase +from method.dde_method import DdeMethod +from pylinuxauto import sleep +from nocmd import Cmd + + +class TestDdeCase(BaseCase): + def test_dde_1271027(self): + """控制中心中修改非当前用户密码""" + DdeMethod().dde_method_add_common_account_by_control_center() + sleep(6) + a = Cmd.run("echo uostest12#$ | sudo -S grep '^test:' /etc/shadow") + DdeMethod().dde_method_change_other_account_password_by_control() + sleep(3) + b = Cmd.run("echo uostest12#$ | sudo -S grep '^test:' /etc/shadow") + self.assert_not_equal(a, b) + + def teardown_method(self): + """关闭控制中心窗口""" + DdeMethod().dde_control_center_method_click_by_attr("test") + DdeMethod().dde_method_reset_other_account_password_from_change_password_by_control_center() + DdeMethod().dde_method_delete_test_account_by_control_center() + DdeMethod().dde_method_close_window() diff --git a/case/test_dde_1271093.py b/case/test_dde_1271093.py new file mode 100644 index 0000000000000000000000000000000000000000..29b1c9000bbd066be0106714e0e5bcdf41090b22 --- /dev/null +++ b/case/test_dde_1271093.py @@ -0,0 +1,75 @@ +import pylinuxauto +import pytest +from case.base_case import BaseCase +from pylinuxauto import sleep +from method.dde_method import DdeMethod + + +class TestDdeCase(BaseCase): + def test_dde_1271093_1(self, clear_test_file_1): + """用文本编辑器打开txt文件""" + euler = DdeMethod() + euler.dde_method_create_file_in_documents_by_cmd("test1.txt") + euler.dde_method_open_software_by_launcher("wenbenbianjiqi") + sleep(6) + euler.dde_editor_method_click_menu_btn_by_attr() + euler.dde_editor_method_choose_open_file_option_by_attr() + sleep(3) + euler.dde_editor_method_click_documents_in_pop_window_by_img() + sleep(2) + pylinuxauto.ctrl_a() + pylinuxauto.enter() + self.assert_ocr_exist("This is test message") + + def test_dde_1271093_2(self, clear_test_file_2): + """用文本编辑器打开xml文件""" + euler = DdeMethod() + euler.dde_method_create_file_in_documents_by_cmd("test1.xml") + euler.dde_method_open_software_by_launcher("wenbenbianjiqi") + sleep(6) + euler.dde_editor_method_click_menu_btn_by_attr() + euler.dde_editor_method_choose_open_file_option_by_attr() + sleep(3) + euler.dde_editor_method_click_documents_in_pop_window_by_img() + sleep(2) + pylinuxauto.ctrl_a() + pylinuxauto.enter() + self.assert_ocr_exist("This is test message") + + def test_dde_1271093_3(self, clear_test_file_3): + """用文本编辑器打开json文件""" + euler = DdeMethod() + euler.dde_method_create_file_in_documents_by_cmd("test1.json") + euler.dde_method_open_software_by_launcher("wenbenbianjiqi") + sleep(6) + euler.dde_editor_method_click_menu_btn_by_attr() + euler.dde_editor_method_choose_open_file_option_by_attr() + sleep(3) + euler.dde_editor_method_click_documents_in_pop_window_by_img() + sleep(2) + pylinuxauto.ctrl_a() + pylinuxauto.enter() + self.assert_ocr_exist("This is test message") + + @pytest.fixture() + def clear_test_file_1(self): + """关闭控制中心窗口""" + yield + DdeMethod().dde_method_delete_file_in_documents_by_cmd("test1.txt") + DdeMethod().dde_method_close_window() + sleep(3) + + @pytest.fixture() + def clear_test_file_2(self): + """关闭控制中心窗口""" + yield + DdeMethod().dde_method_delete_file_in_documents_by_cmd("test1.xml") + DdeMethod().dde_method_close_window() + sleep(3) + + @pytest.fixture() + def clear_test_file_3(self): + """关闭控制中心窗口""" + yield + DdeMethod().dde_method_delete_file_in_documents_by_cmd("test1.json") + DdeMethod().dde_method_close_window() diff --git a/method/assert_method.py b/method/assert_method.py index 5d8dfe5776229dde99f2c3ad51adeef595b00535..a475a66a999f016fd6218d19a28002c40b52aa11 100644 --- a/method/assert_method.py +++ b/method/assert_method.py @@ -21,3 +21,65 @@ class AssertMethod(Assert): def assert_image_not_exist_in_dde(cls, img_name, rate=0.8): """断言图像不存在于dde界面中""" cls.assert_image_not_exist(f"{config.ASSERT_RES}/{img_name}", rate=rate) + + @staticmethod + def assert_equal(expect, actual): + """判断预期值<{{expect}>与实际值<{{actual}>相等""" + if expect != actual: + raise AssertionError(f"预期值<{expect}>与实际值<{actual}>不相等") + + @staticmethod + def assert_not_equal(expect, actual): + """判断预期值<{{expect}>与实际值<{{actual}>不相等""" + if expect == actual: + raise AssertionError(f"预期值<{expect}>与实际值<{actual}>相等") + + @staticmethod + def assert_in(target: str, pool: str): + """判断<{{target}}>在<{{pool}}>中""" + if target not in pool: + raise AssertionError(f"<{target}>不在<{pool}>中") + + @staticmethod + def assert_not_in(target: str, pool: str): + """判断<{{target}}>不在<{{pool}}>中""" + if target in pool: + raise AssertionError(f"<{target}>在<{pool}>中") + + @staticmethod + def assert_sequence_in(target: list, pool: list): + """判断<{{target}}>在<{{pool}}>中""" + for i in target: + if i not in pool: + raise AssertionError(f"{pool}中不存在{i}") + + @staticmethod + def assert_sequence_not_in(target: list, pool: list): + """判断<{{target}}>不在<{{pool}}>中""" + for i in target: + if i in pool: + raise AssertionError(f"{pool}中存在{i}") + + @staticmethod + def assert_true(expect): + """断言{{expect}}结果为真""" + if not expect: + raise AssertionError(f"<{expect}>不为真") + + @staticmethod + def assert_false(expect): + """断言{{expect}}结果为假""" + if expect: + raise AssertionError(f"<{expect}>不为假") + + @staticmethod + def assert_any(expect): + """断言任一{{expect}}结果为真""" + if not any(expect): + raise AssertionError(f"<{expect}>均不为真") + + @staticmethod + def assert_all(expect): + """断言所有{{expect}}结果为真""" + if not all(expect): + raise AssertionError(f"<{expect}>不均为真") diff --git a/method/base_method.py b/method/base_method.py index 1ed529f5c495676aa4f14986aed5c237f899444d..9b98586bdecd7bd2c49a6e3b0a48926068698e07 100644 --- a/method/base_method.py +++ b/method/base_method.py @@ -10,6 +10,7 @@ from funnylog2.config import config as funnylog2_config funnylog2_config.CLASS_NAME_ENDSWITH = ["Method"] import pylinuxauto from config import config +from nocmd import Cmd class BaseMethod: @@ -23,6 +24,10 @@ class BaseMethod: """通过ocr识别点击""" pylinuxauto.find_element_by_ocr(text).click() + def dde_method_double_click_by_ocr(self, text): + """通过ocr识别双击""" + pylinuxauto.find_element_by_ocr(text).double_click() + def dde_method_click_by_img(self, img_name): """通过图像识别点击""" pylinuxauto.find_element_by_image(f"{config.IMAGE_RES}/{img_name}").click() @@ -30,3 +35,12 @@ class BaseMethod: def dde_method_right_click_by_ocr(self, text): """通过ocr识别右键点击""" pylinuxauto.find_element_by_ocr(text).right_click() + + def dde_method_create_file_in_documents_by_cmd(self, filename): + """通过给定名称在 文档 目录下创建文件""" + Cmd.run(f"touch ~/Documents/{filename}") + Cmd.run(f"echo 'This is test message' >> ~/Documents/{filename}") + + def dde_method_delete_file_in_documents_by_cmd(self, filename): + """通过给定名称在 文档 目录下删除文件""" + Cmd.run(f"rm ~/Documents/{filename}") diff --git a/method/dde_editor_method.py b/method/dde_editor_method.py new file mode 100644 index 0000000000000000000000000000000000000000..5ad59d1d3fd6d9ab5f4315bc40a05303b7e3e747 --- /dev/null +++ b/method/dde_editor_method.py @@ -0,0 +1,25 @@ +from time import sleep +from funnylog2.config import config as funnylog2_config + +funnylog2_config.CLASS_NAME_ENDSWITH = ["Method"] +import pylinuxauto +from method.base_method import BaseMethod + + +class DdeEditorMethod(BaseMethod): + def dde_editor_method_click_by_attr(self, path): + """在文本编辑器中通过元素点击""" + pylinuxauto.find_element_by_attr_path(f"/deepin-editor/{path}").click() + + def dde_editor_method_click_menu_btn_by_attr(self): + """在文本编辑器中通过元素点击右上角菜单按钮""" + self.dde_editor_method_click_by_attr("DTitlebarDWindowOptionButton") + + def dde_editor_method_choose_open_file_option_by_attr(self): + """在文本编辑器的菜单栏中选择 打开文件 选项""" + pylinuxauto.find_element_by_ocr("打开文件").click() + + +if __name__ == "__main__": + sleep(3) + DdeEditorMethod().dde_editor_method_click_menu_btn_by_attr() diff --git a/method/dde_method.py b/method/dde_method.py index 81f1b2dcdf1eab4ab52f9ae2b62e3c2beec8c536..d125317f1cf3ff76323ede3a19c049998733b29f 100644 --- a/method/dde_method.py +++ b/method/dde_method.py @@ -9,6 +9,7 @@ from time import sleep from funnylog2.config import config as funnylog2_config from method.base_method import BaseMethod from method.dde_browser_method import DdeBrowserMethod +from method.dde_editor_method import DdeEditorMethod funnylog2_config.CLASS_NAME_ENDSWITH = ["Method"] from funnylog2 import log @@ -21,7 +22,12 @@ from method.dde_font_manager_method import DdeFontManagerMethod @log class DdeMethod( - DdeDockMethod, DdeControlCenterMethod, DdeLauncherMethod, DdeFontManagerMethod, DdeBrowserMethod + DdeDockMethod, + DdeControlCenterMethod, + DdeLauncherMethod, + DdeFontManagerMethod, + DdeBrowserMethod, + DdeEditorMethod, ): """应用方法主类""" @@ -253,6 +259,11 @@ class DdeMethod( sleep(3) pylinuxauto.enter() + def dde_editor_method_click_documents_in_pop_window_by_img(self): + """在文本编辑器的文件管理器弹窗中点击左侧 文档 目录""" + self.dde_method_click_by_ocr("系统盘") + self.dde_method_click_by_img("file_manager_left_view_documents.png") + if __name__ == "__main__": sleep(3) diff --git a/method/image_res/file_manager_left_view_documents.png b/method/image_res/file_manager_left_view_documents.png new file mode 100644 index 0000000000000000000000000000000000000000..0919c0b4ed8f5fbf3e5ab91e3a2187356806e648 Binary files /dev/null and b/method/image_res/file_manager_left_view_documents.png differ