-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use u2.jar instead of test apk (#1004)
* use u2.jar instead of test apk * update toast api, use d.last_toast to get toast, d.clear_toast() to reset it * add more unittests * fix multi thread when use connect
- Loading branch information
1 parent
7ba4852
commit c25a3e5
Showing
36 changed files
with
757 additions
and
278 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# coding: utf-8 | ||
# author: codeskyblue | ||
|
||
import pytest | ||
import uiautomator2 as u2 | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def d(): | ||
_d = u2.connect_usb() | ||
_d.press("home") | ||
yield _d | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def app(d: u2.Device): | ||
d.app_start("com.example.u2testdemo", stop=True) | ||
d(text="Addition").wait() | ||
yield d |
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,57 @@ | ||
# coding: utf-8 | ||
# author: codeskyblue | ||
|
||
import pytest | ||
import uiautomator2 as u2 | ||
|
||
|
||
PACKAGE = "com.example.u2testdemo" | ||
|
||
|
||
def test_wait_activity(d: u2.Device): | ||
# assert app.wait_activity('.MainActivity', timeout=10) | ||
|
||
d.app_start(PACKAGE, activity=".AdditionActivity", wait=True) | ||
assert d.wait_activity('.AdditionActivity', timeout=3) | ||
assert not d.wait_activity('.NotExistActivity', timeout=1) | ||
|
||
|
||
def test_app_wait(app: u2.Device): | ||
assert app.app_wait(PACKAGE, front=True) | ||
|
||
|
||
def test_app_start_stop(d: u2.Device): | ||
assert PACKAGE in d.app_list() | ||
d.app_stop(PACKAGE) | ||
assert PACKAGE not in d.app_list_running() | ||
d.app_start(PACKAGE, wait=True) | ||
assert PACKAGE in d.app_list_running() | ||
|
||
|
||
def test_app_clear(d: u2.Device): | ||
d.app_clear(PACKAGE) | ||
# d.app_stop_all() | ||
|
||
|
||
def test_app_info(d: u2.Device): | ||
d.app_info(PACKAGE) | ||
with pytest.raises(u2.AppNotFoundError): | ||
d.app_info("not.exist.package") | ||
|
||
|
||
def test_auto_grant_permissions(d: u2.Device): | ||
d.app_auto_grant_permissions(PACKAGE) | ||
|
||
|
||
def test_session(d: u2.Device): | ||
app = d.session(PACKAGE) | ||
assert app.running() is True | ||
assert app.pid > 0 | ||
old_pid = app.pid | ||
|
||
app.restart() | ||
assert old_pid != app.pid | ||
|
||
with app: | ||
app(text="Addition").info | ||
|
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,41 @@ | ||
# coding: utf-8 | ||
# author: codeskyblue | ||
|
||
from typing import Optional | ||
import uiautomator2 as u2 | ||
|
||
|
||
def get_app_process_pid(d: u2.Device) -> Optional[int]: | ||
for line in d.shell("ps -u shell").output.splitlines(): | ||
fields = line.split() | ||
if fields[-1] == 'app_process': | ||
pid = fields[1] | ||
return int(pid) | ||
return None | ||
|
||
|
||
def kill_app_process(d: u2.Device) -> bool: | ||
pid = get_app_process_pid(d) | ||
if not pid: | ||
return False | ||
d.shell(f"kill {pid}") | ||
return True | ||
|
||
|
||
def test_uiautomator_keeper(d: u2.Device): | ||
kill_app_process(d) | ||
d.sleep(.2) | ||
assert get_app_process_pid(d) is None | ||
d.shell('rm /data/local/tmp/u2.jar') | ||
|
||
d.start_uiautomator() | ||
assert get_app_process_pid(d) > 0 | ||
|
||
d.stop_uiautomator() | ||
assert get_app_process_pid(d) is None | ||
|
||
|
||
def test_debug(d: u2.Device): | ||
d.debug = True | ||
d.info | ||
|
Oops, something went wrong.