def clear(locationType, locationExpression, *arg): # 清空输入框 global driver try: getElement(driver, locationType, locationExpression).clear() except Exception as e: raise e
def clear(locationType, locatorExpression, *arg): # 清除输入框默认内容 global driver try: getElement(driver, locationType, locatorExpression) except Exception, e: raise e
def input_string(locationType, locationExpression, contant): # 输入框输入数据 global driver try: getElement(driver, locationType, locationExpression).send_keys(contant) except Exception as e: raise e
def click(locationType, locationExpression): # 输入框输入数据 global driver try: getElement(driver, locationType, locationExpression).click() except Exception as e: raise e
def ctrl_keys(locationType,locatorExpression,keybord_key,*arg): # 按下Ctrl+键盘按键 global driver try: getElement(driver,locationType,locatorExpression).send_keys(Keys.CONTROL+keybord_key) except Exception,e: raise e
def input_string(locationType,locatorExpression,inputContent,*arg): # 在页面输入框中输入数据 global driver try: getElement(driver,locationType,locatorExpression).send_keys(inputContent) except Exception, e: raise e
def download_file(locationType,locatorExpression,*arg): # 下载文件 global driver try: getElement(driver,locationType,locatorExpression).click() except Exception, e: raise e
def input_string(locationType, locatorExpression, inputContent): global driver try: getElement(driver, locationType, locatorExpression).send_keys(inputContent) except Exception as e: raise e
def clear(locatorType, locatoeExpression, *arg): # 清除输入框中内容 global driver try: getElement(driver, locatorType, locatoeExpression).clear() except Exception as e: raise e
def click(locationType,locatorExpression,*args): global driver try: getElement(driver,locationType,locatorExpression).click() except Exception, e: print str(e) raise e
def click(locatorType, locatorExpression, *arg): # 单击页面元素 global driver try: getElement(driver, locatorType, locatorExpression).click() except Exception as e: raise e
def click_pc(locationType, locatorExpression, *arg): # 点击页面元素 global driver try: time.sleep(1) getElement(driver, locationType, locatorExpression).click() except Exception as err: raise err
def input_string(locationTpye, locatorExpression, inputContent): # 在页面输入框输入数据 global driver try: getElement(driver, locationTpye, locatorExpression).send_keys(inputContent) except BaseException as e: raise e
def assert_webelementexist(locationType, locatorExpression, *arg): #断言元素是否存在,待调试 Aug 6th 2018 global driver try: getElement(driver, locationType, locatorExpression).isElementPresent() # return True except Exception as e: raise e
def input_string(locationType, locatorExpression, inputContent): # 在页面输入框中输入数据 global driver print("%s %s %s" % (locationType, locatorExpression, inputContent)) try: getElement(driver, locationType, locatorExpression).send_keys(inputContent) except Exception as e: raise e
def input_Fromtime(locationTpye, locatorExpression, *arg): # 在页面输入框输入数据 global driver validityFromTime = getvalidityTime() print(validityFromTime) try: getElement(driver, locationTpye, locatorExpression).send_keys(validityFromTime) except BaseException as e: raise e
class Test_login(object): """ """ @pytest.fixture(scope="class", autouse=True) def prepare(self, driver, env): with allure.step("测试数据准备:"): pass @allure.step("测试数据数据清理:") def fin(): """ Clean up test environment after testing """ pass case, parameter = obj.getElementObject("login") @pytest.mark.run(order=1) @allure.step(title='登录') @pytest.mark.parametrize("case,elements_data", parameter, ids=case) def test_login(self, env, driver, case, api, elements_data): with allure.step("邮箱登录"): url_login = env['host']['ke'] + api['account']['login'] visit_url(url_login) time.sleep(5) try: assert_title("登录-有道精品课") waitutil = WaitUtil(driver) username_obj = elements_data["userName"] waitutil.visibilityOfElementLocated(username_obj[0], username_obj[1]) userName = getElement(driver, username_obj[0], username_obj[1]) userName.send_keys(username_obj[2]) pwd_obj = elements_data["pwd"] pwd = getElement(driver, pwd_obj[0], pwd_obj[1]) pwd.send_keys(pwd_obj[2]) login_button_obj = elements_data["loginbutton"] loginbutton = getElement(driver, login_button_obj[0], login_button_obj[1]) loginbutton.click() time.sleep(5) except Exception as e: capturePic = capture_screen(driver) logging.debug("失败的截图:{}".format(capturePic)) error_info = traceback.format_exc() logging.debug("error info is:{}".format(error_info))
def getText(locationType, locatorExpression, *arg): #获取页面元素文本 global driver try: return getElement(driver, locationType, locatorExpression).text except Exception as err: raise err
def switch_to_frame(locationType, frameLocatorExpression, *arg): global driver try: driver.switch_to.frame( getElement(driver, locationType, frameLocatorExpression)) except Exception as e: raise e
def doubleclick(locationType, locatorExpression): global driver try: action = ActionChains(driver) action.double_click(getElement(driver, locationType, locatorExpression)).perform() except Exception as e: raise e
def switch_to_frame(locationType,frameLocatorExpression,*args): global driver try: driver.switch_to_frame(getElement(driver, locationType, frameLocatorExpression)) except Exception, e: print "Frame error" raise e
def switch_to_frame(locationType,frameLocatorExpression,*arg): #切换进入frame global driver try: driver.switch_to.frame(getElement(driver,locationType,frameLocatorExpression)) except Exception as e: print("frame error") raise e
def getAttr(locationType, locatorExpression, attrName, *arg): #获取页面元素文本 global driver try: return getElement(driver, locationType, locatorExpression).get_attribute(attrName) except Exception as err: raise err
def scroll_page(locationType, locatorExpression, *arg): #页面滑动,元素定位 Aug 9th 2018 global driver try: element = getElement(driver, locationType, locatorExpression) ActionChains(driver).move_to_element(element).perform() except Exception as e: raise e
def mouse_hover(locationType,locatorExpression,*arg): # 鼠标悬停在某个元素上 global driver try: hover_element = getElement(driver,locationType,locatorExpression) ActionChains(driver).move_to_element(hover_element).perform() except Exception,e: raise e
def getidfromxpath(locatorExpression): global driver try: #elementid = driver.find_element_by_xpath(locatorExpression).id elementid = getElement(driver, 'xpath', locatorExpression).get_attribute('id') return elementid except Exception as e: raise e
def select_option(locationType,locatorExpression,element_value,*arg): # 在option中选择对象 global driver try: option_list = Select(getElement(driver,locationType,locatorExpression)) option_list.select_by_value(element_value) except Exception,e: raise e
def get_text(locationType, locatorExpression, *arg): # 获取页面文本 global driver try: mytext = getElement(driver, locationType, locatorExpression).text return mytext except Exception as e: raise e
def switch_to_frame(locationType, frameLocatorExpression, *arg): #切换进入frame try: driver.switch_to_frame( getElement(driver, locationType, frameLocatorExpression)) except Exception, e: print "frame error" raise e
def move_to_element_with_offset(locationType, locatorExpression,x,y): global driver action=ActionChains(driver) try: x=int(x) y=int(y) action.move_to_element_with_offset(getElement(driver,locationType, locatorExpression),x,y) except Exception as e: raise