1
0

test_deepcoin_control.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import logging
  2. import unittest
  3. from plat.deepcoin_control import DeepCoinControl
  4. logging.basicConfig(level=logging.INFO, force=True) # 设置日志级别
  5. class MyTestCase(unittest.TestCase):
  6. def setUp(self):
  7. self.pc = DeepCoinControl('Deepcoin')
  8. self.pc.connect_adb('127.0.0.1:6555')
  9. def test_to_top_swipe(self):
  10. """
  11. 滑动到顶部
  12. """
  13. self.pc.to_top_swipe()
  14. def test_to_next_swipe(self):
  15. """
  16. 滑动到下一屏
  17. """
  18. self.pc.to_next_swipe()
  19. def test_save_point(self):
  20. """
  21. 保存坐标
  22. """
  23. self.pc.save_point()
  24. def test_slider_baozhengjin(self):
  25. """
  26. 保证金滑块
  27. """
  28. self.pc.slider_baozhengjin_kaicang()
  29. def test_click_kaicang(self):
  30. """
  31. 开仓
  32. """
  33. self.pc.click_kaicang()
  34. def test_click_pingchang(self):
  35. """
  36. 平仓
  37. """
  38. self.pc.click_pingchang()
  39. def test_select_weituo_xianjia(self):
  40. """
  41. 选择限价委托
  42. """
  43. self.pc.select_kaicang_weituo_xianjia()
  44. def test_click_price(self):
  45. """
  46. 点击价格
  47. """
  48. self.pc.click_price_red()
  49. def test_f1(self):
  50. """
  51. f1 开仓界面,仓位滑竿百分比(30-60)
  52. """
  53. self.pc.click_kaicang()
  54. self.pc.slider_baozhengjin_kaicang()
  55. def test_f2(self):
  56. """
  57. f2 确认开仓,开多 限价职中间数值
  58. 检查撤销限价委托单
  59. """
  60. self.pc.click_kaicang()
  61. self.pc.select_kaicang_weituo_xianjia()
  62. self.pc.d.sleep(0.1)
  63. self.pc.click_price_red()
  64. self.pc.text_xiadan_shuliang(3)
  65. self.pc.click_mairu_kaiduo()
  66. def test_f3(self):
  67. """
  68. F3 平仓界面 平空,仓位滑竿百分比(90-100)确认开仓,限价职中间数值
  69. """
  70. self.pc.to_top_swipe(sleep=0.2)
  71. self.pc.click_pingchang()
  72. self.pc.slider_baozhengjin_pingcang(offset=1)
  73. def test_f4(self):
  74. """
  75. F4 确认平仓 平多 限价取中间数值 检查撤销限价委托单
  76. """
  77. self.pc.to_top_swipe(sleep=0.2)
  78. self.pc.click_pingchang()
  79. self.pc.select_kaicang_weituo_xianjia()
  80. self.pc.click_price_green()
  81. self.pc.text_xiadan_shuliang(3)
  82. self.pc.click_maichu_pingduo()
  83. def test_f5(self):
  84. """
  85. F5 开仓界面胂仓位滑竿百分比(30-60)
  86. """
  87. self.pc.to_top_swipe(sleep=0.2)
  88. self.pc.click_kaicang()
  89. self.pc.slider_baozhengjin_kaicang()
  90. def test_f6(self):
  91. """
  92. F6 确认开仓, 开空 限价值中间数值
  93. 检查撤销限价委托单
  94. """
  95. self.pc.to_top_swipe(sleep=0.1)
  96. self.pc.click_kaicang()
  97. self.pc.select_kaicang_weituo_xianjia()
  98. self.pc.click_price_red()
  99. # self.pc.text_xiadan_shuliang(3)
  100. self.pc.click_maichu_kaikong()
  101. def test_f7(self):
  102. """
  103. F7 平仓界面二仓位滑竿百分比(90-100)
  104. """
  105. self.pc.to_top_swipe(sleep=0.2)
  106. self.pc.click_pingchang()
  107. self.pc.slider_baozhengjin_pingcang(offset=2)
  108. def test_f8(self):
  109. """
  110. F8 确认平仓, 平空 限价职中间数值
  111. 检查撤销限价委托单
  112. """
  113. self.pc.to_top_swipe()
  114. self.pc.d.sleep(0.1)
  115. self.pc.click_pingchang()
  116. self.pc.click_price_red()
  117. self.pc.text_xiadan_shuliang(3)
  118. self.pc.click_mairu_pingkong()
  119. def test_jiao_yi(self):
  120. x, y = self.pc.btn_jiao_yi()
  121. logging.info(f"交易坐标: ({x},{y})")
  122. def test_mairu_kaiduo(self):
  123. x, y = self.pc.btn_mairu_kaiduo()
  124. logging.info(f"买入开多: ({x},{y})")
  125. def test_chichang(self):
  126. self.pc.d.xpath()
  127. def test_gengdan(self):
  128. self.pc.to_next_swipe()
  129. x, y = self.pc.btn_gengdan()
  130. logging.info(f"跟单坐标: ({x},{y})")
  131. def test_weituo(self):
  132. self.pc.to_next_swipe()
  133. x, y = self.pc.btn_weituo()
  134. logging.info(f"委托坐标: ({x},{y})")
  135. def test_gendan_click(self):
  136. self.pc.click_xpath('//*[starts-with(@content-desc, "跟单(")]')
  137. def test_yijianchedan_click(self):
  138. """
  139. 一键撤单
  140. """
  141. self.pc.to_next_swipe()
  142. self.pc.click_yijian_chedan()
  143. def test_jiaoyi_select(self):
  144. element = self.pc.d.xpath('//*[@content-desc="交易"]').get()
  145. # 获取元素位置
  146. bounds = element.info['bounds']
  147. # 截图
  148. screenshot = self.pc.d.screenshot()
  149. # 转换为PIL图像
  150. from PIL import Image
  151. img = Image.fromarray(screenshot)
  152. # 获取元素中心点颜色
  153. x = (bounds['left'] + bounds['right']) // 2
  154. y = (bounds['top'] + bounds['bottom']) // 2
  155. return img.getpixel((x, y))
  156. def test_slider_baozhengjin_pingcang(self):
  157. """
  158. 平仓情况 保证金滑块
  159. """
  160. self.pc.slider_baozhengjin_pingcang()
  161. def test_exists(self):
  162. # b = self.pc.check_element_exists('//*[starts-with(@content-desc, "全部委托(")]')
  163. # logging.info("是否存在: %s", b)
  164. b = self.pc.check_element_exists('//*[@content-desc="限价委托"]')
  165. logging.info("是否存在: %s", b)
  166. def test_element(self):
  167. element = self.pc.d.xpath('//*[@content-desc="交易"]').get()
  168. logging.info("交易按钮: %s", element.info)
  169. def test_input(self):
  170. """
  171. 给指定xpath的输入框输入文本
  172. """
  173. self.pc.text_xiadan_shuliang(30)
  174. def test_kaichang_queren(self):
  175. """
  176. 开仓确认
  177. """
  178. x, y, _ = self.pc.get_point({
  179. "name": "btn_kaicang_queren",
  180. "desc": "开仓确认",
  181. "xpath": '//*[@content-desc="开仓确认"]'
  182. })
  183. logging.info(f"开仓确认: ({x},{y})")
  184. if self.pc.check_element_exists('//*[@content-desc="开仓确认"]'):
  185. self.pc.click_xpath('//*[@content-desc="确认"]')
  186. if __name__ == '__main__':
  187. unittest.main()