1
0

7.multiple_session_impliment.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import subprocess
  2. from selenium.webdriver import Chrome
  3. import pywebio
  4. import template
  5. import util, time
  6. from pywebio.input import *
  7. from pywebio.output import *
  8. from pywebio.utils import to_coroutine, run_as_function
  9. def target():
  10. set_auto_scroll_bottom(True)
  11. template.basic_output()
  12. template.background_output()
  13. run_as_function(template.basic_input())
  14. actions(buttons=['Continue'])
  15. template.background_input()
  16. async def async_target():
  17. set_auto_scroll_bottom(True)
  18. template.basic_output()
  19. await template.coro_background_output()
  20. await to_coroutine(template.basic_input())
  21. await actions(buttons=['Continue'])
  22. await template.coro_background_input()
  23. def test(server_proc: subprocess.Popen, browser: Chrome):
  24. template.test_output(browser, percy_prefix='[multi tornado coro]')
  25. time.sleep(1)
  26. template.test_input(browser, percy_prefix='[multi tornado coro]')
  27. time.sleep(3)
  28. browser.get('http://localhost:8080?_pywebio_debug=1&pywebio_api=io2')
  29. template.test_output(browser, percy_prefix='[multi tornado thread]')
  30. time.sleep(1)
  31. template.test_input(browser, percy_prefix='[multi tornado thread]')
  32. def start_test_server():
  33. pywebio.enable_debug()
  34. import tornado.ioloop
  35. import tornado.web
  36. from pywebio.platform.tornado import webio_handler
  37. from pywebio import STATIC_PATH
  38. application = tornado.web.Application([
  39. (r"/io", webio_handler(async_target)),
  40. (r"/io2", webio_handler(target)),
  41. (r"/(.*)", tornado.web.StaticFileHandler,
  42. {"path": STATIC_PATH, 'default_filename': 'index.html'})
  43. ])
  44. application.listen(port=8080, address='localhost')
  45. tornado.ioloop.IOLoop.current().start()
  46. if __name__ == '__main__':
  47. util.run_test(start_test_server, test)