使用 Python 语言

用法示例

  1. import unittest
  2. from macaca import WebDriver
  3. desired_caps = {
  4. 'platformName': 'Desktop', // iOS, Android, Desktop
  5. 'browserName': 'Chrome' // Chrome, Electron
  6. 'app': 'path/to/app' // Only for mobile
  7. }
  8. server_url = {
  9. 'hostname': '127.0.0.1',
  10. 'port': 3456
  11. }
  12. class MacacaTest(unittest.TestCase):
  13. @classmethod
  14. def setUpClass(cls):
  15. cls.driver = WebDriver(desired_caps, server_url)
  16. cls.driver.init()
  17. @classmethod
  18. def tearDownClass(cls):
  19. cls.driver.quit()
  20. def test_get_url(self):
  21. self.driver.get('https://www.google.com')
  22. self.assertEqual(self.driver.title, 'Google')
  23. def test_search_macaca(self):
  24. self.driver \
  25. .element_by_id("lst-ib") \
  26. .send_keys("macaca") \
  27. self.driver \
  28. .element_by_name("btnK") \
  29. .click()
  30. html = self.driver.source
  31. self.assertTrue('macaca' in html)
  32. if __name__ == '__main__':
  33. unittest.main()

相关链接

原文: https://macacajs.github.io/zh/python