diff --git a/.circleci/config.yml b/.circleci/config.yml index 56e4199..ea520b4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,36 +11,42 @@ jobs: steps: - checkout + # pip require package - run: command: pip install --user -r requirements.txt name: pip requirements.txt + # screen test - run: command: python ./circle_ci_test/screen/screen_test.py name: screen_test + - run: + command: python ./circle_ci_test/screen/screenshot_test.py + name: screenshot_test + # keyboard test - run: command: python ./circle_ci_test/keyboard/keyboard_type_test.py name: keyboard_test - - run: - command: python ./circle_ci_test/mouse/mouse_test.py - name: mouse_test - - run: - command: python ./circle_ci_test/mouse/mouse_scroll_test.py - name: scroll_test - run: command: python ./circle_ci_test/keyboard/keyboard_write_test.py name: keyboard_write_test - - run: - command: python ./circle_ci_test/screen/screenshot_test.py - name: screenshot_test - - run: - command: python ./circle_ci_test/exception/test_auto_control_exception.py - name: test_auto_control_exception - run: command: python ./circle_ci_test/keyboard/keyboard_is_press_test.py name: keyboard_is_press_test - run: command: python ./circle_ci_test/keyboard/hotkey_test.py name: hotkey_test + # mouse test + - run: + command: python ./circle_ci_test/mouse/mouse_test.py + name: mouse_test + - run: + command: python ./circle_ci_test/mouse/mouse_scroll_test.py + name: scroll_test + # exception test + - run: + command: python ./circle_ci_test/exception/test_auto_control_exception.py + name: test_auto_control_exception + # image detect - run: command: python ./circle_ci_test/image/locate_all_image_test.py name: locate_all_image_test @@ -50,21 +56,25 @@ jobs: - run: command: python ./circle_ci_test/image/locate_image_center_test.py name: locate_image_center_test + # critical exit - run: command: python ./circle_ci_test/critical_exit/critical_exit_test.py name: critical_exit_test - run: command: python ./circle_ci_test/critical_exit/real_critical_test.py name: real_critical_test + # record - run: command: python ./circle_ci_test/record/record_test.py name: record_test + # execute - run: command: python ./circle_ci_test/execute_action/execute_action_test.py name: execute_action_test + # json - run: - command: python ./circle_ci_test/execute_action/json_action_test.py - name: json_action_test + command: python ./circle_ci_test/json/json_test.py + name: json_test workflows: main: diff --git a/.idea/workspace.xml b/.idea/workspace.xml index afdf837..bebf000 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,8 @@ + - - - - - + - - + + + + + @@ -54,15 +54,15 @@ + - - - + + - + + - @@ -269,6 +269,8 @@ + + @@ -315,7 +317,7 @@ - + diff --git a/circle_ci_test/execute_action/json_action_test.py b/circle_ci_test/json/json_test.py similarity index 100% rename from circle_ci_test/execute_action/json_action_test.py rename to circle_ci_test/json/json_test.py diff --git a/je_auto_control/__init__.py b/je_auto_control/__init__.py index 1b92ab7..6615e0e 100644 --- a/je_auto_control/__init__.py +++ b/je_auto_control/__init__.py @@ -43,12 +43,13 @@ from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlJsonActionException from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlRecordException from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlActionNullException +from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlActionException # record from je_auto_control.wrapper.auto_control_record import record from je_auto_control.wrapper.auto_control_record import stop_record # json -from je_auto_control.utils.action_executer.action_execute import execute_action -from je_auto_control.utils.action_file.json_loader import read_action_json -from je_auto_control.utils.action_file.json_loader import write_action_json +from je_auto_control.utils.action_executer.action_executor import execute_action +from je_auto_control.utils.action_file.json_file import read_action_json +from je_auto_control.utils.action_file.json_file import write_action_json diff --git a/je_auto_control/utils/action_executer/action_execute.py b/je_auto_control/utils/action_executer/action_executor.py similarity index 67% rename from je_auto_control/utils/action_executer/action_execute.py rename to je_auto_control/utils/action_executer/action_executor.py index f167418..b1f10f2 100644 --- a/je_auto_control/utils/action_executer/action_execute.py +++ b/je_auto_control/utils/action_executer/action_executor.py @@ -1,3 +1,4 @@ +from je_auto_control import AutoControlActionException from je_auto_control import AutoControlActionNullException from je_auto_control import check_key_is_press from je_auto_control import click_mouse @@ -19,6 +20,8 @@ from je_auto_control import special_table from je_auto_control import type_key from je_auto_control import write +from je_auto_control.utils.je_auto_control_exception.exception_tag import action_is_null_error +from je_auto_control.utils.je_auto_control_exception.exception_tag import cant_execute_action_error event_dict = { # mouse @@ -46,35 +49,43 @@ "locate_and_click": ("locate_and_click", locate_and_click), # screen "size": ("size", size), - "screenshot": ("screenshot", screenshot), - # python's basic function - "print": ("print", print) - + "screenshot": ("screenshot", screenshot) } +def execute_event(action): + event = event_dict.get(action[0]) + if event[0] in ["click_mouse"]: + event[1](action[0], action[1], action[2]) + elif event[0] in ["type_key", "press_key", "release_key", "check_key_is_press", "write"]: + event[1](action[1]) + elif event[0] in ["position", "record", "stop_record", "size"]: + event[1]() + elif event[0] in ["set_position", "screenshot"]: + event[1](action[1], action[2]) + elif event[0] in ["locate_all_image", "locate_image_center", "press_mouse", "release_mouse"]: + event[1](action[1], action[2], action[3]) + elif event[0] in ["scroll", "locate_and_click"]: + event[1](action[1], action[2], action[3], action[4]) + + def execute_action(action_list: list): """ :param action_list the list include action for loop the list and execute action """ + execute_record_string = "" if action_list is None: - raise AutoControlActionNullException + raise AutoControlActionNullException(action_is_null_error) for action in action_list: - event = event_dict.get(action[0]) - print("execute: ", str(action)) - if event[0] in ["click_mouse"]: - event[1](action[0], action[1], action[2]) - elif event[0] in ["type_key", "press_key", "release_key", "check_key_is_press", "write", "print"]: - event[1](action[1]) - elif event[0] in ["position", "record", "stop_record", "size"]: - event[1]() - elif event[0] in ["set_position", "screenshot"]: - event[1](action[1], action[2]) - elif event[0] in ["locate_all_image", "locate_image_center", "press_mouse", "release_mouse"]: - event[1](action[1], action[2], action[3]) - elif event[0] in ["scroll", "locate_and_click"]: - event[1](action[1], action[2], action[3], action[4]) + try: + execute_event(action) + except AutoControlActionException: + raise AutoControlActionException(cant_execute_action_error) + temp_string = "execute: " + str(action) + print(temp_string) + execute_record_string = "".join([execute_record_string, temp_string + "\n"]) + return execute_record_string if __name__ == "__main__": @@ -105,5 +116,5 @@ def execute_action(action_list: list): ("press_mouse", "mouse_left", 500, 500), ("release_mouse", "mouse_left", 500, 500) ] - execute_action(test_list) - + print("\n\n") + print(execute_action(test_list)) diff --git a/je_auto_control/utils/action_file/json_loader.py b/je_auto_control/utils/action_file/json_file.py similarity index 100% rename from je_auto_control/utils/action_file/json_loader.py rename to je_auto_control/utils/action_file/json_file.py diff --git a/je_auto_control/utils/je_auto_control_exception/exception_tag.py b/je_auto_control/utils/je_auto_control_exception/exception_tag.py index 879d58b..117a1e0 100644 --- a/je_auto_control/utils/je_auto_control_exception/exception_tag.py +++ b/je_auto_control/utils/je_auto_control_exception/exception_tag.py @@ -56,6 +56,7 @@ """ json action file tag """ +cant_execute_action_error = "can't execute action" cant_find_json_error = "can't find json file" cant_save_json_error = "can't save json file" action_is_null_error = "json action is null" diff --git a/je_auto_control/utils/je_auto_control_exception/exceptions.py b/je_auto_control/utils/je_auto_control_exception/exceptions.py index 7165dcc..6503c99 100644 --- a/je_auto_control/utils/je_auto_control_exception/exceptions.py +++ b/je_auto_control/utils/je_auto_control_exception/exceptions.py @@ -1,34 +1,73 @@ +""" +general +""" + + class AutoControlException(Exception): pass +""" +Keyboard +""" + + class AutoControlKeyboardException(AutoControlException): pass +class AutoControlCantFindKeyException(AutoControlException): + pass + + +""" +Mouse +""" + + class AutoControlMouseException(AutoControlException): pass +""" +Screen +""" + + class AutoControlScreenException(AutoControlException): pass -class AutoControlCantFindKeyException(AutoControlException): - pass +""" +Image detect +""" class ImageNotFoundException(AutoControlException): pass +""" +Record +""" + + class AutoControlRecordException(AutoControlException): pass +""" +Execute action +""" + + class AutoControlJsonActionException(AutoControlException): pass class AutoControlActionNullException(AutoControlException): pass + + +class AutoControlActionException(AutoControlException): + pass diff --git a/je_auto_control/wrapper/auto_control_record.py b/je_auto_control/wrapper/auto_control_record.py index 5c2f2b3..030f8ef 100644 --- a/je_auto_control/wrapper/auto_control_record.py +++ b/je_auto_control/wrapper/auto_control_record.py @@ -1,6 +1,6 @@ import sys -from je_auto_control.utils.action_executer.action_execute import execute_action +from je_auto_control.utils.action_executer.action_executor import execute_action from je_auto_control.utils.je_auto_control_exception.exception_tag import macos_record_error from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlException from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlJsonActionException diff --git a/setup.py b/setup.py index 9d4eec3..eed2cc2 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="je_auto_control", - version="0.0.64", + version="0.0.66", author="JE-Chen", author_email="zenmailman@gmail.com", description="auto testing", diff --git a/test/platform_independent/test/execute_action/json_action_test.py b/test/platform_independent/test/json/json_test.py similarity index 100% rename from test/platform_independent/test/execute_action/json_action_test.py rename to test/platform_independent/test/json/json_test.py