Skip to content

Commit

Permalink
fix #196
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa0128 committed Aug 10, 2023
1 parent fe1ab51 commit c57a439
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 44 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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==版本)
```

### 镜像
Expand Down
31 changes: 11 additions & 20 deletions solox/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions solox/public/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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:

Expand Down
29 changes: 11 additions & 18 deletions solox/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit c57a439

Please sign in to comment.