14.django_multiple_session_impliment.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import subprocess
  2. import time
  3. from selenium.webdriver import Chrome
  4. import pywebio
  5. import template
  6. import util
  7. from pywebio.input import *
  8. from pywebio.utils import to_coroutine, run_as_function
  9. def target():
  10. template.basic_output()
  11. template.background_output()
  12. run_as_function(template.basic_input())
  13. actions(buttons=['Continue'])
  14. template.background_input()
  15. async def async_target():
  16. template.basic_output()
  17. await template.coro_background_output()
  18. await to_coroutine(template.basic_input())
  19. await actions(buttons=['Continue'])
  20. await template.coro_background_input()
  21. def test(server_proc: subprocess.Popen, browser: Chrome):
  22. template.test_output(browser)
  23. time.sleep(2)
  24. template.test_input(browser)
  25. time.sleep(2)
  26. template.save_output(browser, '14.django_multiple_session_impliment.html')
  27. browser.get('http://localhost:8080/?app=p2&_pywebio_debug=1')
  28. template.test_output(browser, action_delay=1.5)
  29. time.sleep(2)
  30. template.test_input(browser, action_delay=1.5)
  31. time.sleep(2)
  32. template.save_output(browser, '14.django_multiple_session_impliment.html')
  33. def start_test_server():
  34. from pywebio.platform.django import start_server
  35. pywebio.enable_debug()
  36. start_server({'p1': target, 'p2': async_target}, port=8080, host='127.0.0.1', cdn=False)
  37. if __name__ == '__main__':
  38. util.run_test(start_test_server, test, address='http://localhost:8080/?app=p1')