Skip to content

Commit

Permalink
refactor code style
Browse files Browse the repository at this point in the history
refactor code style
  • Loading branch information
JE-Chen committed Nov 14, 2022
1 parent 0e2fcd5 commit fff1320
Show file tree
Hide file tree
Showing 38 changed files with 176 additions and 154 deletions.
36 changes: 35 additions & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion LEARN.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## Pls read README.md, thanks.
# Pls Read README Thanks
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# je_auto_control
# AutoControl

---

### JE Auto Control as a tool for GUI Testing
#### Features
* Image Detect
* Keyboard Event
* Mouse Event
* Screen
* Action file and executor
* Record Event
* CLI with action file
* Generate HTML Report
* Timeout
## AutoControl as a tool for GUI Testing
### Features
* Image Detect
* Keyboard Event
* Mouse Event
* Screen
* Action file and executor
* Record Event
* CLI with action file
* Generate HTML Report
* Timeout

---

Expand All @@ -36,19 +36,19 @@ pip install je_auto_control

## Info

* requirement
* Python 3.7 & later
* pip 19.3 & later
* requirement
* Python 3.7 & later
* pip 19.3 & later


* Dev env
* windows 11
* osx 11 big sur
* ubuntu 20.0.4
* Dev env
* windows 11
* osx 11 big sur
* ubuntu 20.0.4


* Test on
* windows 10 ~ 11
* osx 10.5 ~ 11 big sur
* ubuntu 20.0.4
* raspberry pi 3B and 4B
* Test on
* windows 10 ~ 11
* osx 10.5 ~ 11 big sur
* ubuntu 20.0.4
* raspberry pi 3B and 4B
3 changes: 1 addition & 2 deletions autocontrol_driver/generate_autocontrol_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
server = start_autocontrol_socket_server()
while not server.close_flag:
pass
else:
sys.exit(0)
sys.exit(0)
except Exception as error:
print(repr(error))
2 changes: 1 addition & 1 deletion je_auto_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
from je_auto_control.utils.test_record.record_test_class import test_record_instance

# utils image
from je_auto_control.wrapper.auto_control_image import screenshot
from je_auto_control.utils.image.screenshot import pil_screenshot

# html report
from je_auto_control.utils.html_report.html_report_generate import generate_html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import os
from Xlib.display import Display
"""
get x system display
"""

# get x system display
display = Display(os.environ['DISPLAY'])
7 changes: 3 additions & 4 deletions je_auto_control/linux_with_x11/core/utils/x11_linux_vk.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
raise AutoControlException(linux_import_error)

import Xlib
from Xlib import XK
from je_auto_control.linux_with_x11.core.utils.x11_linux_display import display

"""
x11 linux virtual keycode
"""

# x11 linux virtual keycode

x11_linux_key_backspace = display.keysym_to_keycode(Xlib.XK.string_to_keysym("BackSpace"))
x11_linux_key_slash_b = display.keysym_to_keycode(Xlib.XK.string_to_keysym("BackSpace"))
x11_linux_key_tab = display.keysym_to_keycode(Xlib.XK.string_to_keysym("Tab"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def press_key(keycode: int) -> None:
time.sleep(0.01)
fake_input(display, X.KeyPress, keycode)
display.sync()
except struct.error as error:
except Exception as error:
print(repr(error), file=sys.stderr)


Expand All @@ -32,5 +32,5 @@ def release_key(keycode: int) -> None:
time.sleep(0.01)
fake_input(display, X.KeyRelease, keycode)
display.sync()
except struct.error as error:
except Exception as error:
print(repr(error), file=sys.stderr)
8 changes: 3 additions & 5 deletions je_auto_control/linux_with_x11/listener/x11_linux_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from je_auto_control.utils.exception.exception_tag import linux_import_error
from je_auto_control.utils.exception.exception_tag import listener_error


if sys.platform not in ["linux", "linux2"]:
raise AutoControlException(linux_import_error)

Expand Down Expand Up @@ -71,7 +70,7 @@ def run(self, reply) -> None:
except AutoControlException:
raise AutoControlException(listener_error)

def record(self, record_queue)-> None:
def record(self, record_queue) -> None:
"""
:param record_queue the queue test_record action
"""
Expand Down Expand Up @@ -133,7 +132,7 @@ def run(self) -> None:
current_display.record_enable_context(self.context, self.handler.run)
current_display.record_free_context(self.context)
# keep running this to get event
next_event = self.root.display.next_event()
self.root.display.next_event()
except AutoControlException:
raise AutoControlException(listener_error)
finally:
Expand Down Expand Up @@ -165,9 +164,8 @@ def x11_linux_record(record_queue) -> None:
xwindows_listener.record(record_queue)


def x11_linux_stop_record() -> None:
def x11_linux_stop_record() -> Queue:
"""
stop test_record action
"""
return xwindows_listener.stop_record()

Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def scroll(scroll_value: int, scroll_direction: int) -> None:
scroll_direction = 6 : direction left
scroll_direction = 7 : direction right
"""
total = 0
for i in range(scroll_value):
click_mouse(scroll_direction)

total = total + i
print("Scroll Value:" + total)
3 changes: 2 additions & 1 deletion je_auto_control/linux_with_x11/record/x11_linux_record.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from typing import Any

from je_auto_control.utils.exception.exceptions import AutoControlException
from je_auto_control.utils.exception.exception_tag import linux_import_error
Expand Down Expand Up @@ -32,7 +33,7 @@ def record(self) -> None:
self.record_queue = Queue()
x11_linux_record(self.record_queue)

def stop_record(self) -> None:
def stop_record(self) -> Queue[Any]:
"""
stop test_record
make a format action queue
Expand Down
6 changes: 3 additions & 3 deletions je_auto_control/osx/core/utils/osx_vk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
if sys.platform not in ["darwin"]:
raise AutoControlException(osx_import_error)

"""
osx keyboard virtual keycode
"""

# osx keyboard virtual keycode

osx_key_a = osx_key_A = 0x00
osx_key_s = osx_key_S = 0x01
osx_key_d = osx_key_D = 0x02
Expand Down
1 change: 0 additions & 1 deletion je_auto_control/osx/listener/osx_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def keyboard_handler(event) -> None:


def osx_record() -> None:
record_queue = Queue()
delegate = AppDelegate.alloc().init()
app.setDelegate_(delegate)
AppHelper.runEventLoop()
Expand Down
3 changes: 3 additions & 0 deletions je_auto_control/osx/mouse/osx_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def scroll(scroll_value: int) -> None:
:param scroll_value scroll count
"""
scroll_value = int(scroll_value)
total = 0
for do_scroll in range(abs(scroll_value)):
scroll_event = Quartz.CGEventCreateScrollWheelEvent(
None,
Expand All @@ -103,3 +104,5 @@ def scroll(scroll_value: int) -> None:
1 if scroll_value >= 0 else -1
)
Quartz.CGEventPost(Quartz.kCGHIDEventTap, scroll_event)
total = total + 1
print("Scroll Value:" + total)
5 changes: 5 additions & 0 deletions je_auto_control/osx/record/osx_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@

class OSXRecorder(object):

def __init__(self):
self.record_flag = False

def record(self) -> None:
self.record_flag = True
osx_record()

def stop_record(self) -> Queue:
record_queue = osx_stop_record()
self.record_flag = False
if record_queue is None:
raise AutoControlJsonActionException
return osx_stop_record()
Expand Down
2 changes: 1 addition & 1 deletion je_auto_control/utils/critical_exit/critcal_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def set_critical_key(self, keycode: [int, str] = None) -> None:
set interrupt key
:param keycode interrupt key
"""
if type(keycode) is int:
if isinstance(keycode, int):
self._exit_check_key = keycode
else:
self._exit_check_key = keys_table.get(keycode)
Expand Down
4 changes: 2 additions & 2 deletions je_auto_control/utils/executor/action_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def execute_action(self, action_list: [list, dict]) -> dict:
:param action_list the list include action
for loop the list and execute action
"""
if type(action_list) is dict:
if isinstance(action_list, dict):
action_list: list = action_list.get("auto_control", None)
if action_list is None:
raise AutoControlActionNullException(executor_list_error)
execute_record_dict = dict()
try:
if len(action_list) > 0 or type(action_list) is list:
if len(action_list) > 0 or isinstance(action_list, list):
pass
else:
raise AutoControlActionNullException(action_is_null_error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def handle(self):
socket.sendto("Return_Data_Over_JE".encode("utf-8"), self.client_address)
socket.sendto("\n".encode("utf-8"), self.client_address)
except Exception as error:
print(repr(error), file=sys.stderr)
try:
socket.sendto(str(error).encode("utf-8"), self.client_address)
socket.sendto("\n".encode("utf-8"), self.client_address)
Expand Down
6 changes: 3 additions & 3 deletions je_auto_control/windows/core/utils/win32_ctype_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import ctypes
from ctypes import wintypes
from ctypes import windll
from je_auto_control.windows.core.utils.win32_vk import *
from je_auto_control.windows.core.utils.win32_vk import win32_EventF_UNICODE, win32_VkToVSC

user32 = ctypes.WinDLL('user32', use_last_error=True)

Expand Down Expand Up @@ -49,14 +49,14 @@ class HardwareInput(ctypes.Structure):


class Input(ctypes.Structure):
class INPUT_Union(ctypes.Union):
class INPUTUnion(ctypes.Union):
_fields_: tuple = (("ki", KeyboardInput),
("mi", MouseInput),
("hi", HardwareInput))

_anonymous_: tuple = ("_input",)
_fields_: tuple = (("type", wintypes.DWORD),
("_input", INPUT_Union))
("_input", INPUTUnion))


def _check_count(result, func, args) -> list:
Expand Down
2 changes: 1 addition & 1 deletion je_auto_control/windows/core/utils/win32_keypress_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def check_key_is_press(keycode: [int, str]) -> bool:
if type(keycode) is int:
if isinstance(keycode, int):
temp: int = ctypes.windll.user32.GetKeyState(keycode)
else:
temp = ctypes.windll.user32.GetKeyState(ord(keycode))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from je_auto_control.windows.core.utils.win32_ctype_input import KeyboardInput
from je_auto_control.windows.core.utils.win32_ctype_input import SendInput
from je_auto_control.windows.core.utils.win32_ctype_input import ctypes
from je_auto_control.windows.core.utils.win32_ctype_input import win32_EventF_KEYUP
from je_auto_control.windows.core.utils.win32_vk import win32_EventF_KEYUP


def press_key(keycode: int) -> None:
Expand Down
Loading

0 comments on commit fff1320

Please sign in to comment.