from appium import webdriver
import pytest
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.webdriver import WebDriver
import time
"""
1 、进入雪球首页,进入基金的新闻页(不是第一个基金按钮),对他以及它右侧的每个新闻栏目,
执行上滑5次,进入下个栏目用从右边到左边滑动
2、滑动使用相对坐标,不使用绝对坐标
"""
class Test_Python_520(object):
def setup_method(self):
self.driver=self.restart_app()
self.driver.find_element_by_xpath("//*[contains(@resource-id,'indicator')]//*[@text='基金']").click()
def test_Fund_TowardsDown(self):
for i in range(7):
for i in range(5):
Test_Python_520.towards(self,0.8,0.8,0.2,0.2)
Test_Python_520.towards(self,0.8,0.8,0.2,0.8)
def towards(self,w1,h1,w2,h2):
rect=self.driver.get_window_rect()
time.sleep(2)
action = TouchAction(self.driver)
action.press(x=rect['width']*w1, y=rect['height']*h1).move_to(x=rect['width']*w2, y=rect['height']*h2).release().perform()
time.sleep(2)
@classmethod
def restart_app(cls) -> WebDriver:
caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "hogwarts"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps['noReset']=True
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
driver.implicitly_wait(10)
return driver