Skip to content

Commit

Permalink
add support tidevice xctest -e USE_PORT:8100
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Jan 29, 2021
1 parent af697de commit 499a775
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ $ tidevice kill com.example.demo
$ tidevice applist
```

### 运行XCTest
### 运行WebDriverAgent
> 请先确保手机上已经安装有[WebDriverAgent](https://github.com/appium/WebDriverAgent)应用
```bash
Expand All @@ -79,6 +79,9 @@ $ tidevice xctest -B com.facebook.wda.WebDriverAgent.Runner
[I 210127 11:40:23 _device:1003] ProductVersion: 12.4
[I 210127 11:40:24 _device:952] Start execute test plan with IDE version: 29
[I 210127 11:40:24 _device:875] WebDriverAgent start successfully

# 修改监听端口为8200
$ tidevice xctest -B com.facebook.wda.WebDriverAgent.Runner -e USB_PORT:8200
```

启动后你就可以使用Appium 或者 [facebook-wda](https://github.com/openatx/facebook-wda) 来运行iOS自动化了
Expand Down
5 changes: 4 additions & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ $ tidevice kill com.example.demo
$ tidevice applist
```

### Run XCTest
### Run WebDriverAgent
> Please make sure your iPhone already have [WebDriverAgent](https://github.com/appium/WebDriverAgent) installed
```bash
Expand All @@ -74,6 +74,9 @@ $ tidevice xctest -B com.facebook.wda.WebDriverAgent.Runner
[I 210127 11:40:23 _device:1003] ProductVersion: 12.4
[I 210127 11:40:24 _device:952] Start execute test plan with IDE version: 29
[I 210127 11:40:24 _device:875] WebDriverAgent start successfully

# Change WDA listen port to 8200
$ tidevice xctest -B com.facebook.wda.WebDriverAgent.Runner -e USB_PORT:8200
```

Then you can connect with Appium or [facebook-wda](https://github.com/openatx/facebook-wda)
Expand Down
27 changes: 18 additions & 9 deletions tidevice/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ def cmd_xctest(args: argparse.Namespace):
Run XCTest required WDA installed.
"""
d = _udid2device(args.udid)
d.xctest(args.bundle_id, logger=setup_logger(level=logging.INFO))
env = {}
for kv in args.env or {}:
key, val = kv.split(":", 1)
env[key] = val
if env:
logger.info("Launch env: %s", env)
d.xctest(args.bundle_id, logger=setup_logger(level=logging.INFO), env=env)


def cmd_screenshot(args: argparse.Namespace):
Expand Down Expand Up @@ -230,7 +236,7 @@ def cmd_applist(args: argparse.Namespace):
try:
display_name = info['CFBundleDisplayName']
# major.minor.patch
version = info.get('CFBundleShortVersionString','')
version = info.get('CFBundleShortVersionString', '')
print(bundle_id, display_name, version)
except BrokenPipeError:
break
Expand All @@ -243,8 +249,8 @@ def cmd_launch(args: argparse.Namespace):
d = _udid2device(args.udid)
try:
pid = d.instruments.app_launch(args.bundle_id,
args=args.arguments,
kill_running=args.kill)
args=args.arguments,
kill_running=args.kill)
print("PID:", pid)
except ServiceError as e:
sys.exit(e)
Expand Down Expand Up @@ -278,14 +284,12 @@ def cmd_developer(args: argparse.Namespace):
def cmd_test(args: argparse.Namespace):
print("Just test")
# files = os.listdir(path)

# Here need device unlocked
# signatures = d.imagemounter.lookup()
# if signatures:
# logger.info("DeveloperImage already mounted")
# return




_commands = [
Expand Down Expand Up @@ -339,7 +343,10 @@ def cmd_test(args: argparse.Namespace):
help="test application bundle id"),
dict(args=['-I', '--install-wda'],
action='store_true',
help='install webdriveragent app')
help='install webdriveragent app'),
dict(args=['-e', '--env'],
action='append',
help="set env with format key:value, support multi -e"),
],
help="run XCTest"),
dict(action=cmd_screenshot,
Expand All @@ -357,7 +364,9 @@ def cmd_test(args: argparse.Namespace):
dict(args=['arguments'], nargs='*', help='app arguments'),
],
help="launch app with bundle_id"),
dict(action=cmd_developer, command="developer", help="mount developer image to device"),
dict(action=cmd_developer,
command="developer",
help="mount developer image to device"),
dict(action=cmd_kill,
command="kill",
flags=[dict(args=['name'], help='pid or bundle_id')],
Expand Down
6 changes: 4 additions & 2 deletions tidevice/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ def instruments(self) -> ServiceInstruments:
def _launch_wda(self,
bundle_id: str,
session_identifier: uuid.UUID,
env: dict = {},
logger: logging.Logger = logging,
quit_event: threading.Event = None) -> int: # pid

Expand Down Expand Up @@ -817,6 +818,7 @@ def _launch_wda(self,
'MJPEG_SERVER_PORT': '',
'USE_PORT': '',
} # yapf: disable
app_env.update(env)

if self.major_version() >= 11:
app_env['DYLD_INSERT_LIBRARIES'] = '/Developer/usr/lib/libMainThreadChecker.dylib'
Expand Down Expand Up @@ -898,7 +900,7 @@ def _fnmatch_find_bundle_id(self, bundle_id: str) -> str:
key=lambda v: v != 'com.facebook.wda.irmarunner.xctrunner')
return bundle_ids[0]

def xctest(self, bundle_id="com.facebook.*.xctrunner", logger=None):
def xctest(self, bundle_id="com.facebook.*.xctrunner", logger=None, env: dict={}):
"""
Launch xctrunner and wait until quit
"""
Expand Down Expand Up @@ -979,7 +981,7 @@ def _show_log_message(m: DTXMessage):
# launch test app
# index: 1540

pid = self._launch_wda(bundle_id, session_identifier, logger)
pid = self._launch_wda(bundle_id, session_identifier, env=env, logger=logger)

# xcode call the following commented method, twice
# but it seems can be ignored
Expand Down

0 comments on commit 499a775

Please sign in to comment.