Best Python code snippet using splinter
starter.py
Source:starter.py
...53 cls.start_celery_worker()54 ###################################################################55 # Start Flask App56 #57 cls.start_flask_app()58 elif platform.__contains__('linux'):59 ###################################################################60 # Running on Linux61 #62 print('You are on Linux : {}'.format(platform))63 ###################################################################64 # Start Redis if not already running65 #66 subprocess.Popen(REDIS_RESTART_LINUX, shell=True)67 sleep(10)68 ###################################################################69 # Start CeleryBeat if not already running70 #71 cls.start_celery_beat()72 ###################################################################73 # Start Celery-Worker if not already running74 #75 cls.start_celery_worker()76 ###################################################################77 # Start Flask App78 #79 cls.start_flask_app()80 else:81 print('Unknown OS : {}'.format(platform))82 @classmethod83 def start_flask_app(cls):84 try:85 flask_status = subprocess.check_output(FLASK_APP_STATUS_CMD, shell=True).split()86 print("Flask already running")87 ###################################################################88 # Kill pids associated with Flask server89 #90 os.system('kill -9 {}'.format(flask_status[10]))91 os.system('kill -9 {}'.format(flask_status[20]))92 ###################################################################93 # Restart Flask94 #95 print("Starting Flask App......")96 process = subprocess.Popen(FLASK_APP_CMD)97 pid = process.pid...
fake_server.py
Source:fake_server.py
...30def set_post_response():31 env.post_response_location = request.form.get('location')32 env.post_response_code = int(request.form.get('code'))33 return ""34def start_flask_app(host, port):35 """Runs the server."""36 app.run(host=host, port=port)37 app.config['DEBUG'] = False38 app.config['TESTING'] = False39def wait_until_start():40 while True:41 try:42 urlopen('http://%s:%s' % (env.host, env.port))43 break44 except IOError:45 pass46def wait_until_stop():47 while True:48 try:...
conftest.py
Source:conftest.py
1import sys2import os3from multiprocessing import Process4try:5 from urllib import urlopen6except ImportError:7 from urllib.request import urlopen8from tests.fake_webapp import start_flask_app, EXAMPLE_APP9class Env(object):10 def __init__(self):11 self.process = None12 self.host = 'localhost'13 self.port = 500014env = Env()15def wait_until_start():16 while True:17 try:18 results = urlopen(EXAMPLE_APP)19 if results.code == 404:20 raise Exception("%s returned unexpected 404" % EXAMPLE_APP)21 break22 except IOError:23 pass24def wait_until_stop():25 while True:26 try:27 results = urlopen(EXAMPLE_APP)28 if results.code == 404:29 break30 except IOError:31 break32def start_server():33 sys.stderr = open(os.devnull, "w")34 env.process = Process(target=start_flask_app, args=(env.host, env.port))35 env.process.daemon = True36 env.process.start()37 wait_until_start()38def stop_server():39 env.process.terminate()40 env.process.join()41 wait_until_stop()42def pytest_configure(config):43 try:44 start_server()45 except Exception as e:46 sys.stdout.write("Failed to start test server: %s\n\n" % e)47 sys.exit(1)48def pytest_unconfigure(config):...
main_qt.py
Source:main_qt.py
1import webbrowser2from PyQt5.QtGui import QIcon3from PyQt5.QtWidgets import QApplication, QAction, QMenu, QSystemTrayIcon4from src.config.pyinstaller_util import PyInstallerUtil5from src.main import start_flask_app6from threading import Thread, Timer7if __name__ == '__main__':8 qtApp = QApplication([])9 qtApp.setQuitOnLastWindowClosed(False)10 def openBrowser():11 url = "http://127.0.0.1:5000/home"12 webbrowser.open_new_tab(url)13 # Open button14 openAction = QAction("Open")15 openAction.triggered.connect(openBrowser)16 # Quit button17 quit = QAction("Quit")18 quit.triggered.connect(qtApp.quit)19 # Add buttons to menu20 menu = QMenu()21 menu.addAction(openAction)22 menu.addAction(quit)23 # App icon24 icon = QIcon(PyInstallerUtil.load_from_resource('icon.png'))25 # Adding item on the menu bar26 tray = QSystemTrayIcon()27 tray.setIcon(icon)28 tray.setVisible(True)29 # Adding options to the System Tray30 tray.setContextMenu(menu)31 # start flask application32 flaskThread = Thread(target=start_flask_app, daemon=True).start()33 # open the web browser after 1.25 seconds34 Timer(1.25, lambda: openBrowser()).start()...
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!!