Skip to main content

package help control emulator

Project description

emulator

package này hỗ trợ điều khiển các phần mềm giả lập (Hiện tại chỉ hỗ trợ phần mềm LDPlayer)

Installation

pip install emulator-thw

Usage

Example started

LDPlayer

import emulator


ld = emulator.LDPlayer(ldplayer_dir="C:/LDPlayer/LDPlayer4.0")
print(ld.emulators)

Có hai cách để lấy ldplayer trong LDPlayer là dùng index ld.emulators[0] hoặc dùng name ld.emulator["LDPlayer"]. Tôi khuyên bạn nên sử dụng index, vì name có thể trùng lặp dẫn tới điều khiển sai ldplayer.

Tạo LDPlayer mới

em = ld.new("New-LDPlayer")
em.start()

Xóa LDPlayer

em_remove = ld.emulators[0]
ld.remove(em_remove)

Sao chép LDPlayer

em_copy = ld.emulators[0]
ld.copy(em_copy)

Sắp xếp các cửa sổ LDPlayer

for em in ld.emulators:
    em.start(wait=False)
ld.sort_window()

Đặt giá trị ADB debugging (mặc định sẽ tự bật ADB debugging cho tất cả LDPlayer, nhưng có một số phiên bản LDPlayer mặc dù ADB debugging hiển thị đã bật nhưng không thể kết nối và phải thực hiện bật lại một cách thủ công)

em = ld.emulators[0]
ld.set_ADB_debugging(em, True) # turn on ADB debugging
ld.set_ADB_debugging(em, False) # turn off ADB debugging
em.start(wait=False)

Tạo các hành động

em = ld.emulators[0]
em.start()
em.tap((100, 100)) # code từng dòng
em.wait(3).swipe((200, 100), (10, 100)).wait(3).quit() # code 1 chuỗi hành động

Bỏ qua quit() bằng cách sử dụng with

with ld.emulators[0].start() as em:
    em.tap((100, 100))

List methods

Danh sách các phương thức có thể sử dụng


start

Khởi chạy emulator. Nếu tham số wait=True sẽ gọi phương thức wait_to_stared().

em.start(wait=True)

wait_to_started

Chờ cho quá trình khởi chạy hoàn tất (thực chất là chờ kết nối ADB).

em.wait_to_started()

is_running

Trả về True nếu emulator đang chạy ngược lại False

em.is_running()

restart

Khởi chạy lại emulator, tham số wait tương tự start()

em.restart(wait=True)

rename

Đổi tên emulator thành new_name

em.rename(new_name="New-Name-LDPlayer")

list_packages

trả về danh sách các package đã cài đặt trên thiết bị

packages = em.list_packages()
print(packages)

install_app

Cài đặt ứng dụng, source có thể là đường dẫn tới file .apk hoặc package name

em.install_app(source="example_app.apk")

uninstall_app

Gỡ cài đặt ứng dụng có package name tương ứng. Xem thêm về list_packages

em.uninstall_app(package_name="com.example.app")

run_app

Mở dứng dụng có package name tương ứng. Xem thêm về list_packages

em.run_app(package_name="com.android.chrome")

kill_app

Dừng dứng dụng có package name tương ứng. Xem thêm về list_packages

em.kill_app(package_name="com.android.chrome")

clear_app

Xóa data của ứng dụng có package name tương ứng. Xem thêm về list_packages

em.clear_app(package_name="com.android.chrome")

set_locate

Cài đặt locate

em.set_locate(locate="locate")

update_properties

Cập nhật thông tin thiết bị, tham số prop là 1 dict với key là tên property và value là giá trị tương ứng

em.update_properties(prop)

get_properties

Trả về 1 dict với key là tên property và value là giá trị property

prop = em.get_properties()
print(prop)

setting

cài đặt thông số emlator, tham số là 1 EmulatorOptions

import emulator
from emulator.option import EmulatorOptions


ld = emulator.LDPlayer("path/to/ldplayer/")
options = EmulatorOptions()
options.set_resolution(width=128, height=240, dpi=120)
em = ld.emulators[0]
em.setting(options)
em.start()

down_cpu

em.down_cpu(rate=50)

backup

Tạo file backup emulator

em.backup(file_path="C:/backup.ldbk")

restore

em.restore(file_path="C:/backup.ldbk")

action

actions = {"action": "value"}
em.action(actions=actions)

scan

em.scan(file_path="C:/scan.png")

pull

Đưa file remote từ emulator về PC thành local

em.pull(remote="sdcard/remote.txt", local="C:/local.txt")

push

Đưa file local từ PC lên emulator thành remote

em.push(local="C:/local.txt", remote="sdcard/remote.txt")

capture

Chụp ảnh màn hình và lưu thành as_file

em.capture(as_file="path/to/save_as.png")

adb_connected

Trả về True nếu ADB đã kết nối với emulator ngược lại False. Bạn sẽ cần bật ADB debugging để kết nối ADB

em.adb_connected()

tap

Nhấn vào vị trí pos, là 1 list hoặc tuple có dạng (x, y). Có thể truyền vào nhiều pos để tap nhiều lần vào nhiều vị trí khác nhau.

em.tap((200, 200))
em.tap((150, 200), (250, 250))

tap_to_img

Nhấp vào hình ảnh khớp với hình ảnh được cho. timeout là thời gian chờ hình xuất hiện nếu nhỏ hơn 0 sẽ chờ vô hạn mặc định timeout=0, threshold là độ chính xác khi tìm kiếm, nằm trong khoảng từ 0 tới 1 mặc định threshold=0.8.

em.tap_to_img(img_path="path/to/img", timeout=0, threshold=0.8)

tap_to_imgs

Nhấn vào tất cả hình ảnh khớp với hình ảnh được cho. timeout là thời gian chờ hình xuất hiện nếu nhỏ hơn 0 sẽ chờ vô hạn mặc định timeout=0, threshold là độ chính xác khi tìm kiếm, nằm trong khoảng từ 0 tới 1 mặc định threshold=0.8.

em.tap_to_imgs(img_path="path/to/img", timeout=0, threshold=0.8)

wait_img_existed

Chờ cho tới khi hình ảnh xuất hiện trên màn hình, chờ tối đa timeout giây, nếu timeout=0 sẽ chờ vô hạn cho tới khi có hình ảnh. threshold là độ chính xác khi tìm kiếm nằm trong khoảng 0 tới 1 mặc định threshold=0.8.

em.wait_img_existed(img_path="path/to/img", timeout=0, threshold=0.8)

swipe

Vuốt từ vị trí _from tới vị trí to trong khoảng thời gian duration millisecond.

em.swipe(_from=(100, 200), to=(500, 200), duration=100)

hold

Nhấn giữ tại vị trí pos trong thời gian duration millisecond

em.hold(pos=(250, 150), duration=500)

drag_drop

Kéo thả từ vị trí _from tới vị trí to

em.drag_drop(_from=(250, 150), to=(1000, 150))

send_text

Gửi đoạn văn bản text.

em.send_text(text)

send_event

Gửi event tới emulator. Nhấn giữ nếu long_press = True

import emulator.keys

em.send_event(emulator.keys.KEYCODE_CALL, long_press=False)

home

Nhấn vào nút home

em.home()

back

Nhấn vào nút back

em.back()

app_switcher

Nhấn vào nút app switcher

em.app_switcher()

dump_xml

Lưu window_dump thành file

em.dump_xml(as_file="path/local.xml")

find_node

Trả về Node đầu tiên trong window_dump có giá trị khớp với giá trị đã cho, nếu không tìm được trả về None

from emulator.node import By

node = em.find_node(By.TEXT, "LD Store")

find_nodes

Trả về một list là tất cả các node trong window_dump có giá trị khới với gía trị đã cho

from emulator.node import By

nodes = em.find_nodes(By.TEXT, "LD Store")

wait

Dừng chương trình trong second giây

em.wait(second)

hide

Ẩn emulator

em.hide()

show

Hiển thị emulator

em.show()

quit

Tắt emulator

em.quit()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

emulator-Thw-0.0.11.tar.gz (4.0 MB view hashes)

Uploaded Source

Built Distribution

emulator_Thw-0.0.11-py3-none-any.whl (4.0 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page