def loginNot(self, driver, text): txt = text.encode("utf-8") if cmp(txt, "登录/注册") != 0: commonProc().swipeUp(driver) driver.find_element_by_id( "cc.wulian.smarthomev6:id/item_setting").click() driver.wait_activity(".main.mine.setting.SettingActivity", 3) driver.find_element_by_id( "cc.wulian.smarthomev6:id/item_setting_logout").click() sleep(2) commonProc().swipeDown(driver)
def nonePass(self, driver): commonProc().updateButton(driver) driver.find_element_by_xpath( "//android.widget.LinearLayout[@resource-id='cc.wulian.smarthomev6:id/bottom_navigation_bar_item_container']/android.widget.FrameLayout[5]/android.widget.FrameLayout[1]" ).click() text = commonProc().getText( driver, "cc.wulian.smarthomev6:id/item_account_login_name") self.loginNot(driver, text) driver.find_element_by_id( "cc.wulian.smarthomev6:id/item_account_login").click() driver.wait_activity(".main.login.SigninActivity", 3) driver.find_element_by_id( "cc.wulian.smarthomev6:id/username").send_keys("15951644332") driver.find_element_by_id( "cc.wulian.smarthomev6:id/password").send_keys("") if driver.find_element_by_id( "cc.wulian.smarthomev6:id/login").is_enabled(): commonProc().messageShow("登录按钮未禁用!")
def loginSuccess(self, driver): # driver.find_element_by_id(excel.idCon("btn_negative")).click() commonProc().updateButton(driver) driver.find_element_by_xpath(excel.xpathCon("mine")).click() text = commonProc().getText(driver, excel.idCon("item_account_login_name")) self.loginNot(driver, text) driver.find_element_by_id(excel.idCon("item_account_login")).click() driver.wait_activity(excel.activityCon("SigninActivity"), 3) driver.find_element_by_id( excel.idCon("username")).send_keys("15951644332") driver.find_element_by_id( excel.idCon("password")).send_keys("123456abcd") driver.find_element_by_id(excel.idCon("login")).click() commonProc().waitForPageById( driver, excel.idCon("fixed_bottom_navigation_container"), "登录失败!") print "登陆成功啦"
def InputAsSure(self, driver): commonProc().updateButton(driver) driver.find_element_by_xpath( "//android.widget.LinearLayout[@resource-id='cc.wulian.smarthomev6:id/bottom_navigation_bar_item_container']/android.widget.FrameLayout[5]/android.widget.FrameLayout[1]" ).click() text = commonProc().getText( driver, "cc.wulian.smarthomev6:id/item_account_login_name") self.loginNot(driver, text) driver.find_element_by_id( "cc.wulian.smarthomev6:id/item_account_login").click() driver.wait_activity(".main.login.SigninActivity", 3) driver.find_element_by_id( "cc.wulian.smarthomev6:id/username").send_keys("15951644332") driver.find_element_by_id( "cc.wulian.smarthomev6:id/password").send_keys("123456ab") for i in range(0, 10): driver.find_element_by_id("cc.wulian.smarthomev6:id/login").click() if commonProc().findItem(driver, "找回密码"): break commonProc().clickById(driver, "cc.wulian.smarthomev6:id/dialog_btn_positive") commonProc().waitActivity(driver, ".main.account.ForgotAccountActivity", "未进入忘记密码页面")
def wrongUser(self, driver): commonProc().updateButton(driver) driver.find_element_by_xpath( "//android.widget.LinearLayout[@resource-id='cc.wulian.smarthomev6:id/bottom_navigation_bar_item_container']/android.widget.FrameLayout[5]/android.widget.FrameLayout[1]" ).click() text = commonProc().getText( driver, "cc.wulian.smarthomev6:id/item_account_login_name") self.loginNot(driver, text) driver.find_element_by_id( "cc.wulian.smarthomev6:id/item_account_login").click() driver.wait_activity(".main.login.SigninActivity", 3) driver.find_element_by_id( "cc.wulian.smarthomev6:id/username").send_keys("15951644") driver.find_element_by_id( "cc.wulian.smarthomev6:id/password").send_keys("123456abcd") driver.find_element_by_id("cc.wulian.smarthomev6:id/login").click() s = commonProc().findToast(driver, "账号或密码不正确") print(s) if s == False: commonProc().messageShow("未弹出账号或密码不正确的提示框")
# -*- coding: utf-8 -*- # creaded by 赵永健,管家测试页面 import unittest from time import sleep from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from process.commonProc import commonProc from public.openWeb import openWeb o = openWeb() com = commonProc() class houseKeeperTest(unittest.TestCase): def setUp(self): o.writeSetUp() self.driver = o.getDr() com.login(self.driver) def tearDown(self): o.writeTearDown() # 1、定时任务开关控制 def testTimedTask(self): u'''定时任务开关控制测试用例''' self.driver.find_element_by_xpath( "//*[@id='app']/div/section[3]/div/ul/li[4]").click() self.driver.find_element_by_xpath(
def switch(self, driver, num): if num == 0: # 版本更新取消按钮 commonProc().initApp(driver) elif num == 1: #点击我的 driver.find_element_by_xpath(excel.xpathCon("mine")).click() elif num == 2: #判断是否登录,登录就退出 text = commonProc().getText(driver, excel.idCon("item_account_login_name")) loginProc().loginNot(driver, text) elif num == 3: #点击用户名,进入登录页 driver.find_element_by_id( excel.idCon("item_account_login")).click() driver.wait_activity(excel.activityCon("SigninActivity"), 3) elif num == 4: driver.find_element_by_id(excel.idCon("username")).send_keys( lm.userName) elif num == 5: driver.find_element_by_id(excel.idCon("password")).send_keys( lm.password) elif num == 6: driver.find_element_by_id(excel.idCon("login")).click() elif num == 7: #登录之后进入首页 sleep(3) commonProc().waitForPageById( driver, excel.idCon("fixed_bottom_navigation_container"), lm.msg) elif num == 8: #判断登录按钮禁用 if driver.find_element_by_id(excel.idCon("login")).is_enabled(): commonProc().messageShow(lm.msg) elif num == 9: #toast提示 s = commonProc().findToast(driver, lm.msg) print(s) if s == False: commonProc().messageShow("未弹出" + lm.msg + "的提示框") elif num == 10: #连续3次输入错误密码 for i in range(0, 10): driver.find_element_by_id(excel.idCon("login")).click() sleep(2) if commonProc().findItem(driver, "找回密码"): break elif num == 11: #点击取消按钮 commonProc().clickById(driver, lm.buttonTxt) elif num == 12: #判断是否进入忘记密码页面 commonProc().waitActivity( driver, excel.activityCon("ForgotAccountActivity"), lm.msg) #H5页面测试 elif num == 13: #判断是否登录,未登录则登录 commonProc().loginOrNot(driver) elif num == 14: #点击设备 commonProc().clickByXpath(driver, excel.xpathCon("device")) elif num == 15: #点击移动插座 commonProc().clickDevice( driver, lm.deviceName, "//android.widget.ListView[@resource-id='cc.wulian.smarthomev6:id/lv_device']/android.widget.LinearLayout[7]" ) elif num == 16: #进入设备详情页面 commonProc().waitActivity(driver, ".main.device.DeviceDetailActivity", lm.msg) sleep(2) elif num == 17: #切换到H5页面点击开关,点击更多 commonProc().switch_h5(driver) # 点击打开按钮 commonProc().clickByXpath(driver, "/html/body/section[1]/div[2]") # 打开更多按钮 commonProc().clickByXpath(driver, "/html/body/header/div/a[3]") sleep(2) elif num == 18: #切换到app页面,点击 commonProc().switch_app(driver) commonProc().clickById( driver, "cc.wulian.smarthomev6:id/item_device_more_rename") elif num == 19: #点击首页 commonProc().clickByXpath( driver, "//android.widget.LinearLayout[@resource-id='cc.wulian.smarthomev6:id/bottom_navigation_bar_item_container']/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]" ) elif num == 20: #往下滑动 commonProc().swipeDown(driver) elif num == 21: #点击全部场景 commonProc().clickByXpath( driver, "//android.support.v7.widget.RecyclerView[@resource-id='cc.wulian.smarthomev6:id/home_scene_recyclerview']/android.widget.LinearLayout[8]" ) elif num == 22: #点击添加 commonProc().clickById( driver, "cc.wulian.smarthomev6:id/all_scene_image_add") sleep(2) elif num == 23: #增加场景,输入点击 commonProc().switch_h5(driver) # commonProc().enterTextByXpath(driver,"//*[@id='customScene_input_name']","测试"+random.randint(1,100)) driver.find_element_by_xpath( "//*[@id='customScene_input_name']").send_keys( random.randint(1, 10000)) commonProc().clickByXpath(driver, "/html/body/section[2]/a[1]") commonProc().clickByXpath(driver, "//*[@id='customScene_sure']")
def enterOnH5(self, driver): commonProc().updateButton(driver) driver.find_element_by_xpath( "//android.widget.LinearLayout[@resource-id='cc.wulian.smarthomev6:id/bottom_navigation_bar_item_container']/android.widget.FrameLayout[5]/android.widget.FrameLayout[1]" ).click() commonProc().loginOrNot(driver) commonProc().clickByXpath( driver, "//android.widget.LinearLayout[@resource-id='cc.wulian.smarthomev6:id/bottom_navigation_bar_item_container']/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]" ) commonProc().swipeDown(driver) commonProc().clickByXpath( driver, "//android.support.v7.widget.RecyclerView[@resource-id='cc.wulian.smarthomev6:id/home_scene_recyclerview']/android.widget.LinearLayout[4]" ) commonProc().clickById(driver, "cc.wulian.smarthomev6:id/all_scene_image_add") sleep(2) commonProc().switch_h5(driver) commonProc().enterTextByXpath(driver, "//*[@id='customScene_input_name']", "小博") commonProc().clickByXpath(driver, "/html/body/section[2]/a[1]") commonProc().clickByXpath(driver, "//*[@id='customScene_sure']")
def clickOnH5(self, driver): commonProc().updateButton(driver) driver.find_element_by_xpath( "//android.widget.LinearLayout[@resource-id='cc.wulian.smarthomev6:id/bottom_navigation_bar_item_container']/android.widget.FrameLayout[5]/android.widget.FrameLayout[1]" ).click() commonProc().loginOrNot(driver) commonProc().clickByXpath( driver, "//android.widget.LinearLayout[@resource-id='cc.wulian.smarthomev6:id/bottom_navigation_bar_item_container']/android.widget.FrameLayout[2]/android.widget.FrameLayout[1]" ) # for i in range(0,10): # commonProc().swipeUp(driver) # if commonProc().findItem(driver, "移动插座"): # break # commonProc().clickByXpath(driver, "//android.widget.ListView[@resource-id='cc.wulian.smarthomev6:id/lv_device']/android.widget.LinearLayout[7]") commonProc().clickDevice( driver, "移动插座", "//android.widget.ListView[@resource-id='cc.wulian.smarthomev6:id/lv_device']/android.widget.LinearLayout[7]" ) commonProc().waitActivity(driver, ".main.device.DeviceDetailActivity", "进入设备详情页面失败!") # print driver.contexts # driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {"name":"WEBVIEW_cc.wulian.smarthomev6"}) # print driver.current_context # print driver.page_source sleep(2) commonProc().switch_h5(driver) # 点击打开按钮 commonProc().clickByXpath(driver, "/html/body/section[1]/div[2]") # 打开更多按钮 commonProc().clickByXpath(driver, "/html/body/header/div/a[3]") # driver.find_element_by_xpath("/html/body/section[1]/div[2]").click() sleep(2) # 打开更多按钮 # driver.find_element_by_xpath("/html/body/header/div/a[3]").click() # sleep(2) commonProc().switch_app(driver) commonProc().clickById( driver, "cc.wulian.smarthomev6:id/item_device_more_rename")