test_settings.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # coding: utf-8
  2. #
  3. import time
  4. import pytest
  5. import uiautomator2 as u2
  6. def test_set_xpath_debug(dev: u2.Device):
  7. with pytest.raises(TypeError):
  8. dev.settings['xpath_debug'] = 1
  9. dev.settings['xpath_debug'] = True
  10. assert dev.settings['xpath_debug'] == True
  11. dev.settings['xpath_debug'] = False
  12. assert dev.settings['xpath_debug'] == False
  13. def test_wait_timeout(d: u2.Device):
  14. d.settings['wait_timeout'] = 19.0
  15. assert d.wait_timeout == 19.0
  16. d.settings['wait_timeout'] = 10
  17. assert d.wait_timeout == 10
  18. d.implicitly_wait(15)
  19. assert d.settings['wait_timeout'] == 15
  20. def test_operation_delay(dev: u2.Session):
  21. x, y = dev(text="App").center()
  22. # 测试前延迟
  23. start = time.time()
  24. dev.settings['operation_delay'] = (1, 0)
  25. dev.click(x, y)
  26. time_used = time.time() - start
  27. assert 1 < time_used < 1.5
  28. # 测试后延迟
  29. start = time.time()
  30. dev.settings['operation_delay_methods'] = ['press', 'click']
  31. dev.settings['operation_delay'] = (0, 2)
  32. dev.press("back")
  33. time_used = time.time() - start
  34. # assert time_used > 2
  35. #2 < time_used < 2.5
  36. # 测试operation_delay_methods
  37. start = time.time()
  38. dev.settings['operation_delay_methods'] = ['press']
  39. # dev.jsonrpc = Mock()
  40. dev.click(x, y)
  41. time_used = time.time() - start
  42. # assert 0 < time_used < 0.5