diff --git a/README.md b/README.md index e540ddb..42f27bb 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ We are committed to solving inefficient, cumbersome test execution, and our goal - Install Python 3.10 + [**Download**](https://www.python.org/downloads/) - Install adb and configure environment variables (SoloX's adb may not necessarily fit your computer) [**Download**](https://developer.android.com/studio/releases/platform-tools) -💡 Python 3.6 ~ 3.9 , please download a version of solox lower than 2.5.4. +💡 Python 3.6 ~ 3.9 , please download a version of solox lower than 2.5.4. 💡 If Windows users need to test ios, install and start Itunes. [**Documentation**](https://github.com/alibaba/taobao-iphone-device) @@ -39,7 +39,7 @@ We are committed to solving inefficient, cumbersome test execution, and our goal ### default ```shell -pip install -U solox (pip install solox==2.6.8) +pip install -U solox (pip install solox=={version}) ``` ### mirrors @@ -124,9 +124,9 @@ target in ['cpu','memory','network','fps','battery','gpu'] * **Beautiful Report:** A beautiful and detailed report analysis, where to store, visualize, edit, manage, and download all the test cases collected with SoloX no matter where you are or when is it. * **Useful Monitoring Settings:** Support setting alarm values, collecting duration, and accessing mobile devices on other PC machines during the monitoring process. * **PK Model:** Supports simultaneous comparative testing of two mobile devices. + - 🌱2-devices: test the same app on two different phones. - 🌱2-apps: test two different apps on two phones with the same configuration. - * **Collect In Python/API:** Support Python and API to collect performance data, helping users easily integrate into automated testing processes. ## Browser diff --git a/README.zh.md b/README.zh.md index caf72f6..1c8372f 100644 --- a/README.zh.md +++ b/README.zh.md @@ -38,7 +38,7 @@ SoloX - Android/iOS性能数据的实时采集工具。 ### 默认 ```shell -pip install -U solox (指定版本:pip install solox==2.6.8) +pip install -U solox (指定版本:pip install solox==版本) ``` ### 镜像 diff --git a/solox/debug.py b/solox/debug.py index 2270f00..98337aa 100644 --- a/solox/debug.py +++ b/solox/debug.py @@ -15,8 +15,6 @@ from threading import Lock from flask_socketio import SocketIO, disconnect from flask import Flask -import psutil -import signal from pyfiglet import Figlet from solox import __version__ @@ -70,19 +68,12 @@ def disconnect(): thread = False disconnect() -def hostIP(): - try: - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.connect(('8.8.8.8', 80)) - ip = s.getsockname()[0] - except Exception as e: - ip = '127.0.0.1' - finally: - s.close() +def ip() -> str: + ip = socket.gethostbyname(socket.gethostname()) return ip -def listeningPort(port): +def listen(port): if platform.system() != 'Windows': os.system("lsof -i:%s| grep LISTEN| awk '{print $2}'|xargs kill -9" % port) else: @@ -101,32 +92,32 @@ def listeningPort(port): pid_cmd = 'taskkill -PID {} -F'.format(pid_set) os.system(pid_cmd) -def getServerStatus(host: str, port: int): +def status(host: str, port: int): r = requests.get('http://{}:{}'.format(host, port), timeout=2.0) flag = (True, False)[r.status_code == 200] return flag -def openUrl(host: str, port: int): +def open_url(host: str, port: int): flag = True while flag: logger.info('start solox server ...') f = Figlet(font="slant", width=300) print(f.renderText("SOLOX {}".format(__version__))) - flag = getServerStatus(host, port) + flag = status(host, port) webbrowser.open('http://{}:{}/?platform=Android&lan=en'.format(host, port), new=2) logger.info('Running on http://{}:{}/?platform=Android&lan=en (Press CTRL+C to quit)'.format(host, port)) -def startServer(host: str, port: int): +def start(host: str, port: int): socketio.run(app, host=host, debug=False, port=port) -def main(host=hostIP(), port=50003): +def main(host=ip(), port=50003): try: - listeningPort(port=port) + listen(port=port) pool = multiprocessing.Pool(processes=2) - pool.apply_async(startServer, (host, port)) - pool.apply_async(openUrl, (host, port)) + pool.apply_async(start, (host, port)) + pool.apply_async(open_url, (host, port)) pool.close() pool.join() except KeyboardInterrupt: diff --git a/solox/public/common.py b/solox/public/common.py index 7e77b31..d0c2f3a 100644 --- a/solox/public/common.py +++ b/solox/public/common.py @@ -49,7 +49,6 @@ def getDeviceIds(self): for i in range(1, len(Ids) - 1): id, state = Ids[i].strip().split('\t') if state == 'device': - logger.info('debug') deviceIds.append(id) return deviceIds @@ -175,7 +174,8 @@ def getDdeviceDetail(self, deviceId, platform): result['version'] = adb.shell(cmd='getprop ro.build.version.release', deviceId=deviceId) result['serialno'] = adb.shell(cmd='getprop ro.serialno', deviceId=deviceId) cmd = f'ip addr show wlan0 | {self.filterType()} link/ether' - result['wifiadr'] = adb.shell(cmd=cmd, deviceId=deviceId).split(' ')[1] + wifiadr_content = adb.shell(cmd=cmd, deviceId=deviceId) + result['wifiadr'] = Method._index(wifiadr_content.split(' '), 1, '') case Platform.iOS: iosInfo = json.loads(self.execCmd('tidevice info --json')) result['brand'] = iosInfo['DeviceClass'] @@ -705,6 +705,14 @@ def _settings(cls, request): content['solox_host'] = ('', request.cookies.get('solox_host'))[request.cookies.get('solox_host') not in [None, 'NaN']] content['host_switch'] = request.cookies.get('host_switch') return content + + @classmethod + def _index(cls, target: list, index: int, default: any): + try: + return target[index] + except IndexError: + return default + class Install: diff --git a/solox/web.py b/solox/web.py index ed94fee..c397067 100644 --- a/solox/web.py +++ b/solox/web.py @@ -65,19 +65,12 @@ def disconnect(): thread = False disconnect() -def hostIP(): - try: - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.connect(('8.8.8.8', 80)) - ip = s.getsockname()[0] - except Exception as e: - ip = '127.0.0.1' - finally: - s.close() +def ip() -> str: + ip = socket.gethostbyname(socket.gethostname()) return ip -def listeningPort(port): +def listen(port): if platform.system() != 'Windows': os.system("lsof -i:%s| grep LISTEN| awk '{print $2}'|xargs kill -9" % port) else: @@ -96,32 +89,32 @@ def listeningPort(port): pid_cmd = 'taskkill -PID {} -F'.format(pid_set) os.system(pid_cmd) -def getServerStatus(host: str, port: int): +def status(host: str, port: int): r = requests.get('http://{}:{}'.format(host, port), timeout=2.0) flag = (True, False)[r.status_code == 200] return flag -def openUrl(host: str, port: int): +def open_url(host: str, port: int): flag = True while flag: logger.info('start solox server ...') f = Figlet(font="slant", width=300) print(f.renderText("SOLOX {}".format(__version__))) - flag = getServerStatus(host, port) + flag = status(host, port) webbrowser.open('http://{}:{}/?platform=Android&lan=en'.format(host, port), new=2) logger.info('Running on http://{}:{}/?platform=Android&lan=en (Press CTRL+C to quit)'.format(host, port)) -def startServer(host: str, port: int): +def start(host: str, port: int): socketio.run(app, host=host, debug=False, port=port) -def main(host=hostIP(), port=50003): +def main(host=ip(), port=50003): try: - listeningPort(port=port) + listen(port=port) pool = multiprocessing.Pool(processes=2) - pool.apply_async(startServer, (host, port)) - pool.apply_async(openUrl, (host, port)) + pool.apply_async(start, (host, port)) + pool.apply_async(open_url, (host, port)) pool.close() pool.join() except KeyboardInterrupt: