Recently I have been doing the practice of Socket interface testing, and I have been using Java or Groovy language to write functions and scripts. Since my colleague is learning Python, I helped organize a Python version of socket. IO interface test script.

The Java version reads as follows:

  • Socket interface development and testing
  • Text-based HTTP client in IntelliJ
  • Client encapsulation based on WebSocket
  • Client encapsulation based on socket. IO
  • Socket.IO interface multi-user testing practice
  • GiteeaddressGitee.com/fanapi/test…
  • GitHubaddressGithub.com/JunManYuanL…

Python version does not provide the login function, because what is more, so let the students use a postman or Charles on | Fiddler tool such as after completion of the user login token.

To install the socket. IO package, run the following command: pip3 install python-socketio There are many online tutorials here.

The script content is as follows:

import socketio
import time


# wiki address: http://wiki.okjiaoyu.cn/pages/viewpage.action?spaceKey=RJBK&title=ailearn-instruction-svr
def func(token="", uid=0, room=0) :
    sio = socketio.Client()
    event = 'my_event'

    @sio.event()
    def my_response(data) :
        # handle the message
        # sio.emit('my_event', {"cmd": "joinRoom", "roomId": 8888})
        print(data)

    @sio.event
    def connect() :
        print("I'm connected!")

    @sio.event
    def connect_error() :
        print("The connection failed!")

    @sio.event
    def disconnect() :
        print("I'm disconnected!")

    url = 'http://ailearn-instruction-stress.xk12.cn:38999/?systemId={uid}&loginType=3&token={token}&userType=1'
    # dev environment URL, port 38899
    # url = 'http://ailearn-instruction-dev.xk12.cn:38899/?systemId={uid}&loginType=3&token={token}&userType=1'
    url = url.format(uid=uid, token=token)

    sio.connect(
        url,transports=["websocket"])
    print('my sid is', sio.sid)
    time.sleep(3)
    You must register and join the room operation. Room is the activityID for publishing teaching activities
    sio.emit(event, {"cmd": "register"."userId": uid, "role": "T"."deviceVersion": "1.0"."s_sid": sio.sid, "token": token})
    sio.emit(event, {"cmd": "joinRoom"."roomId": room})
    time.sleep(3)


if __name__ == '__main__':
    func(token="519594cc8e3a4bd68679b2b613c20536", uid=61951375269, room=43548)

Copy the code

Level is limited, can only write a rough script, barely run, for reference only.


The public,FunTester, non-famous test development, the article records learning and comprehension, welcome to pay attention to, exchange growth.

FunTester hot text selection

  • How to become a Full stack automation engineer
  • Bind mobile phone number performance test
  • Fixed QPS pressure test
  • Open source etiquette
  • Groovy uses topics in JMeter
  • Client encapsulation based on WebSocket
  • Client encapsulation based on socket. IO
  • Socket.IO interface multi-user testing practice
  • The Definitive Guide to Java Performance
  • UI testing