Best Python code snippet using Airtest
test.py
Source:test.py
...7#def get_external_ip_address():8# s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)9# s.connect(("8.8.8.8", 80))10# return s.getsockname()[0]11def get_ip_address_from_interface(ifname):12 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)13 return socket.inet_ntoa(fcntl.ioctl(s.fileno(),0x8915,struct.pack('256s', ifname[:15]))[20:24])14#ip = get_ip_adress()15#ip=get_ip_address_from_interface("docker0")16ip = "172.17.0.1"17#ip="127.0.0.1"18port_mongo = "27017"19db = "test"20collection = "user"21LOG_FILE = "log.txt"22TOPIC="/test/fogorchestration"23TIMEFRAME = 1024print("IP: " + ip)25client = MQTTClient(ip, "client1")26client.connect()27client.subscribe(TOPIC)28print("Subscribed to topic " + TOPIC)29print("MQTT broker listening on port 1883")...
options.py
Source:options.py
...8from flask import Flask, request, render_template, Response9from werkzeug.exceptions import Unauthorized10from flask.ext.login import login_required11from bartendro.model.version import DatabaseVersion12def get_ip_address_from_interface(ifname):13 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)14 try:15 return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, 16 struct.pack('256s', ifname[:15]))[20:24])17 except IOError:18 return "[none]"19@app.route('/admin/options')20@login_required21def admin_options():22 ver = DatabaseVersion.query.one()23 recover = not request.remote_addr.startswith("10.0.0")24 wlan0 = get_ip_address_from_interface("wlan0")25 eth0 = get_ip_address_from_interface("eth0")26 return render_template("admin/options", 27 options=app.options,28 show_passwd_recovery=recover,29 title="Options", 30 eth0=eth0,31 wlan0=wlan0,32 version = app.version,33 schema = ver.schema)34@app.route('/admin/lost-passwd')35def admin_lost_passwd():36 if request.remote_addr.startswith("10.0.0"):37 raise Unauthorized38 return render_template("admin/lost-passwd", 39 options=app.options)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!