from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import selenium.webdriver.support.expected_conditions as EC
import unittest
from appium import webdriver
def element_to_be_clickable(driver, location=None, selector="xpath"):
wait = WebDriverWait(driver, 20, 1)
if selector == "css":
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, location)))
else:
element = wait.until(EC.element_to_be_clickable((By.XPATH, location)))
return element
def ele_to_located(driver, location=None, selector="xpath"):
wait = WebDriverWait(driver, 20, 1)
if selector == "css":
element = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, location)))
else:
element = wait.until(EC.visibility_of_element_located((By.XPATH, location)))
return element
# 向下滑动。x轴保持不变,y轴:由小变大
def swipe_down(driver, x, y, y1, duration=2000):
driver.swipe(x, y, x, y1, duration)
class SearchPage(unittest.TestCase):
def setUp(self):
desired_cups = {}
desired_cups['platformName'] = 'Android'
desired_cups['platformVersion'] = '7.1.2'
desired_cups['deviceName'] = 'Android Emulator'
desired_cups['automationName'] = 'uiautomator2'
desired_cups['noReset'] = 'false'
desired_cups['autoGrantPermissions'] = 'true'
desired_cups['appPackage'] = 'com.hpbr.bosszhipin'
desired_cups['appActivity'] = 'com.hpbr.bosszhipin.module.launcher.WelcomeActivity'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_cups)
def test_search(self):
accept = element_to_be_clickable(self.driver, "//*[@resource-id='com.hpbr.bosszhipin:id/tv_positive']")
accept.click()
find_job = element_to_be_clickable(self.driver, "//*[@resource-id='com.hpbr.bosszhipin:id/btn_enter_geek']")
find_job.click()
prefix = element_to_be_clickable(self.driver,
"//*[@resource-id='com.hpbr.bosszhipin:id/tv_country_phone_code']")
prefix.click()
x = self.driver.get_window_size()['width']
# 获取屏幕宽
y = self.driver.get_window_size()['height']
ele_to_located(self.driver, "//*[@resource-id='com.hpbr.bosszhipin:id/tv_country']")
#设置 滑动位置
self.driver.swipe(326, 1058, 326, 581, 1000)
self.driver.swipe(326, 581, 326, 1058, 1000)
china = element_to_be_clickable(self.driver,
"//*[contains(@text,'中国大陆')]")
china.click()
iphone = ele_to_located(self.driver, "//*[contains(@text,'手机号码')]")
iphone.clear()
iphone.send_keys("13764000000")
we_chat = ele_to_located(self.driver, "//*[contains(@text,'微信登录')]")
we_chat.click()
authorization = ele_to_located(self.driver, "//*[contains(@text,'同意')]")
authorization.click()
if __name__ == '__main__':
unittest.main()