Skip to content

Commit

Permalink
Merge pull request #1 from kaluluosi/ios_connect
Browse files Browse the repository at this point in the history
Ios connect
  • Loading branch information
kaluluosi authored Oct 24, 2023
2 parents fa999ae + 4254239 commit b685294
Show file tree
Hide file tree
Showing 19 changed files with 614 additions and 372 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ output.xml
report.html
.airtest
log*.js
tests/demo/com.netease.poco.u3d.tutorial_Data/output_log.txt
2 changes: 1 addition & 1 deletion docs/libs/DeviceLibrary.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/libs/StdPocoLibrary.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/libs/UnityPocoLibrary.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "robotframework-airtest"
version = "0.1.2"
version = "0.2.0"
description = "网易Airtest/pocoui的Robotframework测试库"
authors = ["kaluluosi <[email protected]>"]
license = "MIT"
Expand All @@ -15,7 +15,7 @@ unity = "robotframework_airtest.vmg.generators.unity:generate"
android = "robotframework_airtest.device.connects.impl.android:AndroidConnectStrategy"
windows = "robotframework_airtest.device.connects.impl.windows:WindowsConnectStrategy"
unity = "robotframework_airtest.device.connects.impl.unity:UnityConnectStrategy"

ios = "robotframework_airtest.device.connects.impl.ios:IOSConnectStrategy"

[tool.poetry.scripts]
ra = "robotframework_airtest.cli:main"
Expand Down
4 changes: 2 additions & 2 deletions robotframework_airtest/device/connects/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_valid_connect_strategy() -> Dict[str, ConnectStrategyBase]:
all_connect_strategies = {}
for ep in entry_points:
connect_strategy = ep.load()
all_connect_strategies[ep.name] = connect_strategy
all_connect_strategies[ep.name.lower()] = connect_strategy

return all_connect_strategies

Expand All @@ -61,7 +61,7 @@ def factory(device_uri: str, pkg_name: str) -> ConnectStrategyBase:
ConnectStrategy: 连接策略实例
"""
res = urlparse(device_uri)
platform = res.scheme
platform = res.scheme.lower()
all_connect_strategies = get_valid_connect_strategy()
connect_strategy = all_connect_strategies.get(platform, None)
if connect_strategy is None:
Expand Down
26 changes: 7 additions & 19 deletions robotframework_airtest/device/connects/impl/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,17 @@
class AndroidConnectStrategy(ConnectStrategyBase):
def connect(self, auto_start_app=False) -> Device:
self.device = connect_device(self.device_uri)
logger.console("设备<{device}>:连接".format(device=self.device_uri))
logger.console(f"设备<{self.device_uri}>:连接")
self.device.unlock()
self.device.wake()
logger.console("启动APP:{}".format(auto_start_app))
logger.console(f"启动APP:{auto_start_app}")
if auto_start_app:
if not self.device.check_app(self.pkg_name):
logger.error(
"设备<{device}>:没有安装app<{app}>,启动失败。".format(
device=self.device_uri, app=self.pkg_name
)
)
logger.error(f"设备<{self.device_uri}>:没有安装app<{self.pkg_name}>,启动失败。")
else:
logger.info(
"设备<{device}>:关闭app<{app}>".format(
device=self.device_uri, app=self.pkg_name
)
)
logger.info(f"设备<{self.device_uri}>:关闭app<{self.pkg_name}>")
self.device.stop_app(self.pkg_name)
logger.info(
"设备<{device}>:启动app<{app}>".format(
device=self.device_uri, app=self.pkg_name
)
)
logger.info(f"设备<{self.device_uri}>:启动app<{self.pkg_name}>")
self.device.start_app(self.pkg_name)
return self.device

Expand All @@ -39,7 +27,7 @@ def disconnect(self):
if self.pkg_name:
try:
self.device.stop_app(self.pkg_name)
except Exception:
logger.warn("APP没有运行,没有停止。")
except Exception as e:
logger.warn(f"APP没有运行,没有停止。{e}")

G.DEVICE_LIST.remove(self.device)
41 changes: 41 additions & 0 deletions robotframework_airtest/device/connects/impl/ios.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from typing import cast
from airtest.core.device import Device
from airtest.core.ios import IOS
from robot.api import logger
from airtest.core.api import connect_device
from airtest.core.helper import G
from ..connect_strategy import ConnectStrategyBase


class IOSConnectStrategy(ConnectStrategyBase):
"""
iOS连接策略
"""

def connect(self, auto_start_app: bool = False) -> Device:
self.device = connect_device(self.device_uri)
self.device = cast(IOS, self.device)
logger.console(f"设备<{self.device_uri}>:连接")

self.device.unlock()

if auto_start_app:
app_list = self.device.list_app()
if self.pkg_name not in app_list:
logger.error(f"设备<{self.device}>:未安装{self.pkg_name},启动失败")
else:
logger.info(f"设备<{self.device}>:关闭app<{self.pkg_name}>")
self.device.stop_app(self.pkg_name)
logger.info(f"设备<{self.device}>:启动app<{self.pkg_name}>")
self.device.start_app(self.pkg_name)

return self.device

def disconnect(self):
if self.is_connected and self.pkg_name:
try:
self.device.stop_app(self.pkg_name)
except Exception as e:
logger.warn(f"APP没有运行,没有停止:{e}")

G.DEVICE_LIST.remove(self.device)
9 changes: 9 additions & 0 deletions robotframework_airtest/poco/android.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from poco.drivers.std import StdPoco
from .std import StdPocoLibrary

from poco.drivers.android.uiautomation import AndroidUiautomationPoco


class AndroidUiAutomationPocoLibrary(StdPocoLibrary):
def _create_poco(self) -> StdPoco:
return AndroidUiautomationPoco()
10 changes: 10 additions & 0 deletions robotframework_airtest/poco/cocosjs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from poco.drivers.std import StdPoco
from .std import StdPocoLibrary
from poco.drivers.cocosjs import CocosJsPoco, CocosJsPocoAgent


class CocosJsPocoLibrary(StdPocoLibrary):
def _create_poco(self) -> StdPoco:
agent = CocosJsPocoAgent(self.addr[1])
poco = CocosJsPoco(agent)
return poco
3 changes: 2 additions & 1 deletion robotframework_airtest/poco/gesture.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from time import sleep
from airtest.core.win.win import Windows
from airtest.core.win import Windows
from airtest.core.android import Android
from poco.gesture import PendingGestureAction


Expand Down
9 changes: 9 additions & 0 deletions robotframework_airtest/poco/ios.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from poco.drivers.std import StdPoco
from .std import StdPocoLibrary

from poco.drivers.ios import iosPoco


class IOSPocoLibrary(StdPocoLibrary):
def _create_poco(self) -> StdPoco:
return iosPoco()
Loading

0 comments on commit b685294

Please sign in to comment.