1
0

test_deepcoin_control.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import logging
  2. import unittest
  3. from control.plat.deepcoin_control import DeepCoinControl
  4. from control.ui.settings_control import SettingsControl
  5. logging.basicConfig(level=logging.INFO, force=True) # 设置日志级别
  6. class DeepCoinTestCase(unittest.TestCase):
  7. def setUp(self):
  8. settings = SettingsControl('Settings')
  9. serial = '127.0.0.1:64047'
  10. settings.init_adb([f'adb connect {serial}'])
  11. self.dc = settings.connect_dict.get(serial).get('control')
  12. def test_to_top_swipe(self):
  13. """
  14. 滑动到顶部
  15. """
  16. self.dc.to_top_swipe()
  17. def test_to_next_swipe(self):
  18. """
  19. 滑动到下一屏
  20. """
  21. self.dc.to_next_swipe(y=0.6)
  22. def test_save_point(self):
  23. """
  24. 保存坐标
  25. """
  26. self.dc.save_point()
  27. def test_slider_baozhengjin(self):
  28. """
  29. 保证金滑块
  30. """
  31. self.dc.slider_baozhengjin_kaicang()
  32. def test_click_kaicang(self):
  33. """
  34. 开仓
  35. """
  36. self.dc.click_kaicang()
  37. def test_click_pingchang(self):
  38. """
  39. 平仓
  40. """
  41. self.dc.click_pingchang()
  42. def test_select_weituo_xianjia(self):
  43. """
  44. 选择限价委托
  45. """
  46. self.dc.select_kaicang_weituo_xianjia()
  47. def test_click_price(self):
  48. """
  49. 点击价格
  50. """
  51. self.dc.click_price_red()
  52. def test_f1(self):
  53. """
  54. f1 开仓界面,仓位滑竿百分比(30-60)
  55. """
  56. # self.pc.click_kaicang()
  57. # self.pc.slider_baozhengjin_kaicang()
  58. self.dc.event_f1()
  59. def test_f2(self):
  60. """
  61. f2 确认开仓,开多 限价职中间数值
  62. 检查撤销限价委托单
  63. """
  64. # self.pc.click_kaicang()
  65. #
  66. # self.pc.select_kaicang_weituo_xianjia()
  67. # self.pc.d.sleep(0.1)
  68. #
  69. # self.pc.click_price_red()
  70. #
  71. # # self.pc.text_xiadan_shuliang(3)
  72. # self.pc.slider_baozhengjin_kaicang()
  73. #
  74. # self.pc.click_mairu_kaiduo()
  75. self.dc.event_f2()
  76. def test_f3(self):
  77. """
  78. F3 平仓界面 平空,仓位滑竿百分比(90-100)确认开仓,限价职中间数值
  79. """
  80. # self.pc.to_top_swipe(sleep=0.2)
  81. # self.pc.click_pingchang()
  82. # self.pc.slider_baozhengjin_pingcang(offset=1)
  83. self.dc.event_f3()
  84. def test_f4(self):
  85. """
  86. F4 确认平仓 平多 限价取中间数值 检查撤销限价委托单
  87. """
  88. # self.pc.to_top_swipe(sleep=0.2)
  89. # self.pc.click_pingchang()
  90. # self.pc.select_kaicang_weituo_xianjia()
  91. # self.pc.click_price_green()
  92. # # self.pc.text_xiadan_shuliang(3)
  93. # self.pc.slider_baozhengjin_pingcang(offset=1)
  94. # self.pc.click_maichu_pingduo()
  95. self.dc.event_f4()
  96. def test_f5(self):
  97. """
  98. F5 开仓界面胂仓位滑竿百分比(30-60)
  99. """
  100. # self.pc.to_top_swipe(sleep=0.2)
  101. # self.pc.click_kaicang()
  102. # self.pc.slider_baozhengjin_kaicang()
  103. self.dc.event_f5()
  104. def test_f6(self):
  105. """
  106. F6 确认开仓, 开空 限价值中间数值
  107. 检查撤销限价委托单
  108. """
  109. # self.pc.to_top_swipe(sleep=0.1)
  110. # self.pc.click_kaicang()
  111. # self.pc.select_kaicang_weituo_xianjia()
  112. # self.pc.click_price_red()
  113. # # self.pc.text_xiadan_shuliang(3)
  114. # self.pc.click_maichu_kaikong()
  115. self.dc.event_f6()
  116. def test_f7(self):
  117. """
  118. F7 平仓界面二仓位滑竿百分比(90-100)
  119. """
  120. # self.pc.to_top_swipe(sleep=0.2)
  121. # self.pc.click_pingchang()
  122. # self.pc.slider_baozhengjin_pingcang(offset=2)
  123. self.dc.event_f7()
  124. def test_f8(self):
  125. """
  126. F8 确认平仓, 平空 限价职中间数值
  127. 检查撤销限价委托单
  128. """
  129. # self.pc.to_top_swipe()
  130. #
  131. # self.pc.d.sleep(0.1)
  132. #
  133. # self.pc.click_pingchang()
  134. #
  135. # self.pc.click_price_red()
  136. #
  137. # # self.pc.text_xiadan_shuliang(3)
  138. # self.pc.click_maichu_kaikong()
  139. #
  140. # self.pc.click_mairu_pingkong()
  141. self.dc.event_f8()
  142. def test_event_10(self):
  143. self.dc.event_10()
  144. def test_event_11(self):
  145. self.dc.event_11()
  146. def test_jiao_yi(self):
  147. x, y, _ = self.dc.btn_jiao_yi()
  148. logging.info(f"交易坐标: ({x},{y})")
  149. def test_mairu_kaiduo(self):
  150. x, y = self.dc.btn_mairu_kaiduo()
  151. logging.info(f"买入开多: ({x},{y})")
  152. def test_chichang(self):
  153. self.dc.d.xpath()
  154. def test_gengdan(self):
  155. self.dc.to_next_swipe()
  156. x, y = self.dc.btn_gengdan()
  157. logging.info(f"跟单坐标: ({x},{y})")
  158. def test_weituo(self):
  159. self.dc.to_next_swipe()
  160. x, y, _ = self.dc.btn_weituo()
  161. logging.info(f"委托坐标: ({x},{y})")
  162. def test_gendan_click(self):
  163. self.dc.click_xpath('//*[starts-with(@content-desc, "跟单(")]')
  164. def test_yijianchedan_click(self):
  165. """
  166. 一键撤单
  167. """
  168. self.dc.to_next_swipe()
  169. self.dc.click_yijian_chedan()
  170. def test_jiaoyi_select(self):
  171. element = self.dc.d.xpath('//*[@content-desc="交易"]').get()
  172. # 获取元素位置
  173. bounds = element.info['bounds']
  174. # 截图
  175. screenshot = self.dc.d.screenshot()
  176. # 转换为PIL图像
  177. from PIL import Image
  178. img = Image.fromarray(screenshot)
  179. # 获取元素中心点颜色
  180. x = (bounds['left'] + bounds['right']) // 2
  181. y = (bounds['top'] + bounds['bottom']) // 2
  182. return img.getpixel((x, y))
  183. def test_slider_baozhengjin_pingcang(self):
  184. """
  185. 平仓情况 保证金滑块
  186. """
  187. self.dc.slider_baozhengjin_pingcang()
  188. def test_exists(self):
  189. # b = self.pc.check_element_exists('//*[starts-with(@content-desc, "全部委托(")]')
  190. # logging.info("是否存在: %s", b)
  191. b = self.dc.check_element_exists('//*[@content-desc="限价委托"]')
  192. logging.info("是否存在: %s", b)
  193. def test_element(self):
  194. element = self.dc.d.xpath('//*[@content-desc="交易"]').get()
  195. logging.info("交易按钮: %s", element.info)
  196. def test_input(self):
  197. """
  198. 给指定xpath的输入框输入文本
  199. """
  200. self.dc.text_xiadan_shuliang(30)
  201. def test_kaichang_queren(self):
  202. """
  203. 开仓确认
  204. """
  205. x, y, _ = self.dc.get_point({
  206. "name": "btn_kaicang_queren",
  207. "desc": "开仓确认",
  208. "xpath": '//*[@content-desc="开仓确认"]'
  209. })
  210. logging.info(f"开仓确认: ({x},{y})")
  211. if self.dc.check_element_exists('//*[@content-desc="开仓确认"]'):
  212. self.dc.click_xpath('//*[@content-desc="确认"]')
  213. def test_get_appinfo(self):
  214. logging.info(f'>>>{self.dc.d.info}', )
  215. def test_get_label_text(self):
  216. """
  217. 测试获取 委托(1) 中的数字
  218. :return:
  219. """
  220. wt = self.dc.d.xpath('//*[starts-with(@content-desc, "委托(")]')
  221. logging.info(f'>>>{wt}', )
  222. # 获取第一个匹配的元素 (如果存在)
  223. element = wt.get()
  224. if element:
  225. # 获取元素的完整文本,通常 content-desc 就是元素的文本描述
  226. info = element.info
  227. print(f"元素的信息: {info}")
  228. print(f"元素的完整文本: {info['contentDescription']}")
  229. else:
  230. print("没有找到匹配的元素")
  231. if __name__ == '__main__':
  232. unittest.main()