#coding:utf-8
importunittestfrom common.base importBaseAppfrom appium importwebdriverfrom common.logger importLogfrom selenium.webdriver.support.ui importWebDriverWaitimporttime
desired_caps= {‘platformName‘: ‘Android‘,‘deviceName‘: ‘9a762346‘,‘platformVersion‘: ‘6.0.1‘,‘noReset‘: True,‘unicodeKeyboard‘: True,‘resetKeyboard‘: True,‘appPackage‘: ‘com.android.settings‘,‘appActivity‘: ‘.Settings‘}
u‘‘‘测试wifi连接‘‘‘
classTest(unittest.TestCase):
@classmethoddefsetUpClass(cls):
cls.driver=webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘, desired_caps)
cls.base=BaseApp(cls.driver)
cls.log=Log()defsetUp(self):pass
deftestName(self):
self.log.info(‘设备启动成功‘)
self.size=self.driver.get_window_size()
WebDriverWait(self.driver,30,1).until(lambda x:x.find_element_by_xpath(‘//*[@text="WLAN"]‘)).click()
WebDriverWait(self.driver,30,1).until(lambda x:x.find_element_by_xpath(‘//*[@text="刷新"]‘)).click()
self.log.info(‘点击刷新成功‘)
time.sleep(15)
self.log.info(‘15s搜索完毕‘)
a=self.driver.find_elements_by_id(‘android:id/title‘)
b=[]for j in range(1,31):for i inrange(len(a)):try:
b.append(a[i].text)except:
self.log.info(‘添加文本时发生错误‘)if "iPhone罗" inb:
WebDriverWait(self.driver,60,1).until(lambda x:x.find_element_by_xpath(‘//*[@text="iPhone罗"]‘)).click()
self.log.info(‘第‘+str(j)+‘次滑动设备找到wifi‘)
self.log.info(b)break
else:
x1=self.size[‘width‘] * 0.5y1=self.size[‘height‘] * 0.75y2=self.size[‘height‘] * 0.50self.driver.swipe(x1, y1, x1, y2,200)
self.log.info(list(set(b)))
time.sleep(2)
self.log.info(‘第‘+str(j)+‘次滑动设备wifi未找到,2s后进行下一次寻找‘)try:
WebDriverWait(self.driver,10,1).until(lambda x:x.find_element_by_id(‘com.android.settings:id/password‘)).send_keys(‘11111111111111‘) #输入密码
self.log.info(‘输入密码完成‘)
time.sleep(2)
WebDriverWait(self.driver,10,1).until(lambda x:x.find_element_by_xpath(‘//*[@text="连接"]‘)).click()
self.log.info(‘点击连接成功‘)except:
self.log.info(‘连接按钮没找到(10s),WiFi未找到‘)deftearDown(self):pass@classmethoddeftearDownClass(cls):
cls.driver.quit()if __name__ == "__main__":#import sys;sys.argv = [‘‘, ‘Test.testName‘]
unittest.main()