Example #1
0
class TeleActions():
    '''
    classdocse
    '''
    def __init__(self):

        self.getinfo = SetParameters()
        self.commonActions = CommonActions()

    def accessTeleRecharge(self, driver, area_row, area_col, num_row, num_col):
        #进入固话充值
        try:
            self.commonActions.publishMsg(driver)
        except:
            print "没有推送消息!"
        teleRechargexpath = self.getinfo.setElementConfig(10, 5)
        try:
            WebDriverWait(
                driver,
                30).until(lambda the_driver: the_driver.find_element_by_xpath(
                    teleRechargexpath).is_displayed())
        except:
            print "not found!"
        time.sleep(1)
        driver.find_element_by_xpath(teleRechargexpath).click()
        telephoneAreaId = self.getinfo.setTelePhoneConfig(1, 8)
        telephoneAreaNum = self.getinfo.setTelePhoneConfig(area_row, area_col)
        self.commonActions.switchToIframe(driver)
        driver.find_element_by_id(telephoneAreaId).send_keys(telephoneAreaNum)
        telephoneNumId = self.getinfo.setTelePhoneConfig(2, 8)
        telephoneNum = self.getinfo.setTelePhoneConfig(num_row, num_col)
        driver.find_element_by_id(telephoneNumId).send_keys(telephoneNum)

    def clickConfirmRecharge(self, driver):
        confirmPayxpath = self.getinfo.setTelePhoneConfig(10, 8)
        driver.find_element_by_xpath(confirmPayxpath).click()

    def teleRecharge(self, driver, area_row, area_col, num_row, num_col):
        self.accessTeleRecharge(driver, area_row, area_col, num_row, num_col)
        amountXpath = self.getinfo.setTelePhoneConfig(5, 8)
        driver.find_element_by_xpath(amountXpath).click()
        quickPayXpath = self.getinfo.setTelePhoneConfig(9, 8)
        driver.find_element_by_xpath(quickPayXpath).click()
        self.clickConfirmRecharge(driver)

    def teleRechargeError(self, driver, area_row, area_col, num_row, num_col):
        self.accessTeleRecharge(driver, area_row, area_col, num_row, num_col)
        amountXpath = self.getinfo.setTelePhoneConfig(5, 8)
        driver.find_element_by_xpath(amountXpath).click()
        quickPayXpath = self.getinfo.setTelePhoneConfig(9, 8)
        driver.find_element_by_xpath(quickPayXpath).click()

    def verifyTeleRechargeError(self, driver):
        errorResult = self.getinfo.setTelePhoneConfig(16, 7)
        errorResultXpath = self.getinfo.setTelePhoneConfig(16, 8)
        errorInfo = driver.find_element_by_xpath(errorResultXpath).text
        flag = False
        if errorInfo == errorResult:
            flag = True
            return flag

        return flag

    def verifyTeleRechargeNotSupport(self, driver):
        errorResult = self.getinfo.setTelePhoneConfig(17, 7)
        errorResultXpath = self.getinfo.setTelePhoneConfig(17, 8)
        errorInfo = driver.find_element_by_xpath(errorResultXpath).text
        flag = False
        if errorInfo == errorResult:
            flag = True
            return flag

        return flag

    def teleRechargeProvinceCheck(self, driver, area_row, area_col, num_row,
                                  num_col):
        self.accessTeleRecharge(driver, area_row, area_col, num_row, num_col)
        province = self.getinfo.setTelePhoneConfig(area_row, (area_col + 4))
        l_province_xpath = self.getinfo.setTelePhoneConfig(12, 8)
        try:
            WebDriverWait(
                driver,
                30).until(lambda the_driver: the_driver.find_element_by_xpath(
                    l_province_xpath).is_displayed())
        except:
            print "not found!"
        l_province = driver.find_element_by_xpath(l_province_xpath).text
        flag = False
        if province == l_province:
            flag = True
            return flag
        else:
            return flag

        return flag

    def teleRechargeNumCheck(self, driver, area_row, area_col, num_row,
                             num_col):
        self.accessTeleRecharge(driver, area_row, area_col, num_row, num_col)
        l_area = self.getinfo.setTelePhoneConfig(area_row, area_col)
        l_num = str(int(self.getinfo.setTelePhoneConfig(num_row, num_col)))
        l_area_num = l_area + "-" + l_num
        l_area_checkId = self.getinfo.setTelePhoneConfig(3, 8)
        l_area_check = driver.find_element_by_xpath(l_area_checkId).text
        l_num_checkId = self.getinfo.setTelePhoneConfig(4, 8)
        l_num_check = driver.find_element_by_xpath(l_num_checkId).text
        l_area_num_check = l_area_check + l_num_check
        flag = False
        if l_area_num == l_area_num_check:
            flag = True
            return flag

        return flag

    def cancleRecharge(self, driver, area_row, area_col, num_row, num_col):
        self.accessTeleRecharge(driver, area_row, area_col, num_row, num_col)
        amountXpath = self.getinfo.setTelePhoneConfig(5, 8)
        driver.find_element_by_xpath(amountXpath).click()
        quickPayXpath = self.getinfo.setTelePhoneConfig(9, 8)
        driver.find_element_by_xpath(quickPayXpath).click()
        canclexpathId = self.getinfo.setTelePhoneConfig(11, 8)
        try:
            WebDriverWait(driver, 30).until(
                lambda the_driver: the_driver.find_element_by_xpath(
                    canclexpathId).is_displayed(), u"没有找到取消按钮")
        except Exception, e:
            print e
            pass
        driver.find_element_by_xpath(canclexpathId).click()
        area_num = self.getAreaNum(area_row, area_col, num_row, num_col)

        return area_num
class AdvantageActions():
    '''
    classdocse
    '''
    def __init__(self):

        self.getinfo = SetParameters()
        self.commonActions = CommonActions()

    def adRecharge(self, driver, phone_row, phone_col, amount_row, amount_col):
        #话费充值
        self.enterAdRecharge(driver, phone_row, phone_col, amount_row,
                             amount_col)
        self.adReChargeConfirm(driver)

    def enterAdRecharge(self, driver, phone_row, phone_col, amount_row,
                        amount_col):
        self.commonActions.publishMsg(driver)
        iframe = self.getinfo.setElementConfig(8, 5)
        item = self.getinfo.setElementConfig(11, 5)
        try:
            #WebDriverWait(driver, 20).until(lambda the_driver: the_driver.find_element_by_xpath(mbRecharge).is_displayed())
            #element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, mbRecharge)))
            time.sleep(5)
            driver.find_element_by_xpath(item).click()
        except:
            print "element error"
        driver.switch_to_frame(iframe)
        phonenumber = self.getinfo.setAdRechargeConfig(phone_row, phone_col)
        rechargeAmount = self.getinfo.setElementConfig(amount_row, amount_col)
        #amount=driver.find_element_by_xpath(rechargeAmount).text
        phonenumberId = self.getinfo.setElementConfig(15, 5)
        confirmRechargeId = self.getinfo.setElementConfig(24, 5)
        driver.find_element_by_id(phonenumberId).send_keys(phonenumber)
        driver.find_element_by_xpath(rechargeAmount).click()
        driver.find_element_by_xpath(confirmRechargeId).click()

    def adReChargeConfirm(self, driver):
        ensureId = self.getinfo.setElementConfig(26, 5)
        driver.find_element_by_id(ensureId).click()

    def disAdRecharge(self, driver, phone_row, phone_col):
        self.commonActions.publishMsg(driver)
        item = self.getinfo.setElementConfig(11, 5)
        iframe = self.getinfo.setElementConfig(8, 5)
        try:
            #WebDriverWait(driver, 20).until(lambda the_driver: the_driver.find_element_by_xpath(mbRecharge).is_displayed())
            #element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, mbRecharge)))
            time.sleep(5)
            driver.find_element_by_xpath(item).click()
        except:
            print "element error"
        driver.switch_to_frame(iframe)
        phonenumberId = self.getinfo.setElementConfig(15, 5)
        phonenumber = self.getinfo.setAdRechargeConfig(phone_row, phone_col)
        driver.find_element_by_id(phonenumberId).send_keys(phonenumber)
        #回到主窗体,因为提示语在主窗体,否则无法定位
        driver.switch_to_default_content()
        infoXpath = self.getinfo.setAdRechargeConfig(1, 5)
        self.commonActions.waitForElement(driver, infoXpath)
        info = driver.find_element_by_xpath(infoXpath).text
        print info

        return info

    def verifyDisAdRecharge(self, info):
        result = self.getinfo.setAdRechargeConfig(8, 2)
        flag = False
        if info == result:
            flag = True
            return flag

        return flag

    def verifyAdRechargeErrorNum(self, info):
        result = self.getinfo.setAdRechargeConfig(9, 2)
        flag = False
        if info == result:
            flag = True
            return flag

        return flag