class OMS(AbTemplate):
    # file_name = os.path.basename(__file__).replace(".pyc", "_case").replace(".py", "_case")
    # case_info = file_name.split("_", 1)
    # case_id = case_info[0]
    # case_name = case_info[1]
    # testcaseinfo = testcaseinfo.TestCaseInfo(case_id, case_name, "功能测试")
    # logger = noteLog.Loggger(case_name)
    # testcaseinfo.setLogPath(logger.rel_file)

    # case info
    phone_value = "13810345799"

    # page info
    user_manage_page = usermanage.UserManagePage()
    user_detail_page = userdetail.UserDetailPage()

    order_detail_page = orderdetail.OrderDetail()
    contract_detail_page = contractdetail.ContactDetailPage()
    stationunit_detail_page = stationunitdetail.StationunitDetailPage()
    pay_detail_page = paydetail.PayDetailPage()
    promote_detail_page = promotedetail.PromoteDetailPage()

    @skip("js scroll screen always error pause this case for now")
    @retrying.retry(retry_on_exception=retry_if_timeout_exception, stop_max_attempt_number=2)
    def test_case(self):
        self.util_init(__file__)
        self.testcaseinfo.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
        if self.flag > 1:
            self.setUp()
        try:
            # print self.case_name
            self.step = "convert to user manage page"
            self.logger.info(self.step)
            self.convert_URL = urldata.URLData().get_user_manage_page_url()
            self.convert_to_url(self.convert_URL)
            self.wait_url_to_be(self.convert_URL)

            self.step = "input phone"
            self.logger.info(self.step)
            self.wait_visable(self.user_manage_page.phone_text_box)
            self.fill(self.user_manage_page.phone_text_box, self.phone_value)

            self.step = "click query"
            self.logger.info(self.step)
            self.click(self.user_manage_page.query_user_button)

            self.step = "click username"
            self.logger.info(self.step)
            self.wait_clickable(self.user_manage_page.user_username)
            self.click(self.user_manage_page.user_username)
            self.switch_handel()

            self.step = "screen scroll"
            self.logger.info(self.step)
            js = "document.getElementsByClassName('list_details historyOrderBox')[0].scrollIntoView(true)"
            self.driver.execute_script(js)

            self.step = "click history order's order link"
            self.logger.info(self.step)
            self.wait_clickable(self.user_detail_page.history_order_order)
            self.click(self.user_detail_page.history_order_order)

            self.step = "match order page theme"
            self.logger.info(self.step)
            self.wait_visable(self.order_detail_page.order_detail_theme)
            self.assertEqual("订单详情", self.get_text_Infor(self.order_detail_page.order_detail_theme), "订单链接不匹配")
            self.back()

            self.step = "screen scroll"
            self.logger.info(self.step)
            js = "document.getElementsByClassName('list_details historyOrderBox')[0].scrollIntoView(true)"
            self.driver.execute_script(js)

            self.step = "click history order's unit link"
            self.logger.info(self.step)
            self.wait_clickable(self.user_detail_page.history_order_unit)
            self.click(self.user_detail_page.history_order_unit)
            self.switch_handel()

            self.step = "match unit page theme"
            self.logger.info(self.step)
            self.wait_visable(self.stationunit_detail_page.unit_detail_theme)
            self.assertEqual("仓位详情", self.get_text_Infor(self.stationunit_detail_page.unit_detail_theme), "仓位链接不匹配")
            self.driver.back()

            self.step = "screen scroll"
            self.logger.info(self.step)
            js = "document.getElementsByClassName('list_details historyOrderBox')[0].scrollIntoView(true)"
            self.driver.execute_script(js)

            self.step = "click history order's contract link"
            self.logger.info(self.step)
            self.wait_clickable(self.user_detail_page.history_order_contract)
            self.click(self.user_detail_page.history_order_contract)
            self.switch_handel()

            self.step = "match contract page theme"
            self.logger.info(self.step)
            self.wait_visable(self.contract_detail_page.contact_detail_theme)
            self.assertEqual("合同详情", self.get_text_Infor(self.contract_detail_page.contact_detail_theme), "合同链接")
            self.driver.back()

            self.step = "screen scroll"
            self.logger.info(self.step)
            js = "document.getElementsByClassName('list_details historyOrderBox')[0].scrollIntoView(true)"
            self.driver.execute_script(js)

            self.step = "click history order's payid link"
            self.logger.info(self.step)
            self.wait_clickable(self.user_detail_page.history_order_payid)
            self.click(self.user_detail_page.history_order_payid)
            self.switch_handel()

            self.step = "match payid page theme"
            self.logger.info(self.step)
            self.wait_visable(self.pay_detail_page.pay_detail_theme)
            self.assertEqual("支付信息", self.get_text_Infor(self.pay_detail_page.pay_detail_theme), "支付链接不匹配")
            self.driver.back()

            self.step = "screen scroll"
            self.logger.info(self.step)
            js = "document.getElementsByClassName('list_details historyOrderBox')[0].scrollIntoView(true)"
            self.driver.execute_script(js)

            self.step = "click history order's promote link"
            self.logger.info(self.step)
            self.wait_clickable(self.user_detail_page.history_order_promote)
            self.click(self.user_detail_page.history_order_promote)
            self.switch_handel()

            self.step = "match promote page theme"
            self.logger.info(self.step)
            self.wait_visable(self.promote_detail_page.promote_detail_theme)
            self.assertEqual("优惠券详情", self.get_text_Infor(self.promote_detail_page.promote_detail_theme), "优惠券链接不匹配")
            self.driver.back()

            self.testcaseinfo.result = "Pass"
            pass
        except TimeoutException:
            self.timeout_method()
        except Exception as err:
            self.exception_method(err)
        finally:
            self.finally_method()
class OMS(AbTemplate):
    # sometimes run the file name is file.py sometimes is file.pyc so we need replace by this way
    # file_name = os.path.basename(__file__).replace(".pyc", "").replace(".py", "_case")
    # case_info = file_name.split("_", 1)
    # case_id = case_info[0]
    # case_name = case_info[1]
    # testcaseinfo = testcaseinfo.TestCaseInfo(case_id, case_name, "功能测试")
    # logger = noteLog.Loggger(case_name)
    # testcaseinfo.setLogPath(logger.rel_file)

    # case info

    company_value = "新海汇"
    area_value = "北京市"
    unit_type_value = "迷你仓"
    station_value = "双井国贸"
    unit_value = "双井 A1"
    order_type_value = "续仓"
    order_statu_value = "完成"
    pay_method_value = "微信"
    order_id_value = "1007082102089340"
    start_date_value = "2019-07-20"
    end_date_value = "2019-08-23"

    # page info
    order_manage_page = ordermanage.orderManagePage()
    order_detail_page = orderdetail.OrderDetail()
    unit_detail_page = stationunitdetail.StationunitDetailPage()
    pay_detail_page = paydetail.PayDetailPage()
    contact_detail_page = contractdetail.ContactDetailPage()
    user_detail_page = userdetail.UserDetailPage()

    @retrying.retry(retry_on_exception=retry_if_timeout_exception,
                    stop_max_attempt_number=2)
    def test_case_by(self):
        self.util_init(__file__)
        self.testcaseinfo.name = self.case_name + "_by"
        self.testcaseinfo.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
        if self.flag > 1:
            self.setUp()
        try:
            self.step = "convert to order manage page"
            self.logger.info(self.step)
            self.convert_URL = urldata.URLData().get_order_manage_page_url()
            self.convert_to_url(self.convert_URL)
            self.wait_url_to_be(self.convert_URL)

            self.step = "select company"
            self.logger.info(self.step)
            self.wait_visable(self.order_manage_page.company_select)
            self.Select(self.order_manage_page.company_select,
                        self.company_value)

            self.step = "select area"
            self.logger.info(self.step)
            self.Select(self.order_manage_page.area_select, self.area_value)

            self.step = "select unit type"
            self.logger.info(self.step)
            self.Select(self.order_manage_page.unit_type_select,
                        self.unit_type_value)

            self.step = "select station"
            self.logger.info(self.step)
            self.Select(self.order_manage_page.manage_station_select,
                        self.station_value)

            self.step = "fill unit"
            self.logger.info(self.step)
            self.fill(self.order_manage_page.unit_box, self.unit_value)

            self.step = "select order type"
            self.logger.info(self.step)
            self.Select(self.order_manage_page.order_type_select,
                        self.order_type_value)

            self.step = "select order statu"
            self.logger.info(self.step)
            self.Select(self.order_manage_page.order_statu_select,
                        self.order_statu_value)

            self.step = "select pay method"
            self.logger.info(self.step)
            self.Select(self.order_manage_page.pay_method_select,
                        self.pay_method_value)

            self.step = "fill start date time"
            self.logger.info(self.step)
            self.clear(self.order_manage_page.manage_start_time)
            self.fill(self.order_manage_page.manage_start_time,
                      self.start_date_value)

            self.step = "fill end date time"
            self.logger.info(self.step)
            self.clear(self.order_manage_page.manage_end_time)
            self.fill(self.order_manage_page.manage_end_time,
                      self.end_date_value)

            self.step = "fill order value"
            self.logger.info(self.step)
            self.fill(self.order_manage_page.order_id_box, self.order_id_value)

            self.step = "click query"
            self.logger.info(self.step)
            self.click(self.order_manage_page.query_button)

            self.step = "match order id"
            self.logger.info(self.step, 10)
            self.assertEqual(
                self.get_text_Infor(self.order_manage_page.orider_link),
                self.order_id_value, "查询结果订单号不匹配")

            self.step = "match unit type"
            self.logger.info(self.step)
            self.assertEqual(
                self.get_text_Infor(self.order_manage_page.unit_type_info),
                self.order_type_value, "订单类型不匹配")

            self.step = "click order link"
            self.logger.info(self.step)
            self.wait_clickable(self.order_manage_page.orider_link)
            self.click(self.order_manage_page.orider_link)
            self.switch_handel()

            self.step = "match order link"
            self.logger.info(self.step)
            self.wait_visable(self.order_detail_page.order_detail_theme)
            now_theme = self.get_text_Infor(
                self.order_detail_page.order_detail_theme)
            self.assertEquals(now_theme, "订单详情", "订单链接跳转不匹配")
            self.driver.close()
            self.switch_handel()

            self.step = "click unit link"
            self.logger.info(self.step)
            self.wait_clickable(self.order_manage_page.unit_link)
            self.click(self.order_manage_page.unit_link)
            self.switch_handel()

            self.step = "match unit link"
            self.logger.info(self.step)
            self.wait_visable(self.unit_detail_page.unit_detail_theme)
            now_theme = self.get_text_Infor(
                self.unit_detail_page.unit_detail_theme)
            self.assertEquals(now_theme, "仓位详情", "仓位链接跳转不匹配")
            self.driver.close()
            self.switch_handel()

            self.step = "click user link"
            self.logger.info(self.step)
            self.wait_clickable(self.order_manage_page.user_link)
            self.click(self.order_manage_page.user_link)
            self.switch_handel()

            self.step = "match user link"
            self.logger.info(self.step)
            self.wait_visable(self.user_detail_page.user_detail_theme)
            now_theme = self.get_text_Infor(
                self.user_detail_page.user_detail_theme)
            self.assertEquals(now_theme, "用户详情", "用户链接跳转不匹配")
            self.driver.close()
            self.switch_handel()

            self.step = "click contract link"
            self.logger.info(self.step)
            self.wait_clickable(self.order_manage_page.contract_link)
            self.click(self.order_manage_page.contract_link)
            self.switch_handel()

            self.step = "match contract link"
            self.logger.info(self.step)
            self.wait_visable(self.contact_detail_page.contact_detail_theme)
            now_theme = self.get_text_Infor(
                self.contact_detail_page.contact_detail_theme)
            self.assertEquals("合同详情", now_theme, "合同链接跳转不匹配")
            self.driver.close()
            self.switch_handel()

            self.step = "click pay link"
            self.logger.info(self.step)
            self.wait_clickable(self.order_manage_page.payment_link)
            self.click(self.order_manage_page.payment_link)
            self.switch_handel()

            self.step = "match pay link"
            self.logger.info(self.step)
            self.wait_visable(self.pay_detail_page.pay_detail_theme)
            now_theme = self.get_text_Infor(
                self.pay_detail_page.pay_detail_theme)
            self.assertEquals("支付信息", now_theme, "支付链接跳转不匹配")
            self.driver.close()
            self.switch_handel()

            self.testcaseinfo.result = "Pass"
            pass
        except TimeoutException:
            self.timeout_method()
        except Exception as err:
            self.exception_method(err)
        finally:
            self.finally_method()

    @retrying.retry(retry_on_exception=retry_if_timeout_exception,
                    stop_max_attempt_number=2)
    def test_case_all(self):
        self.util_init(__file__)
        self.testcaseinfo.name = self.case_name + "_all"
        self.testcaseinfo.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
        if self.flag > 1:
            self.setUp()
        try:
            self.step = "convert to order manage page"
            self.logger.info(self.step)
            self.convert_URL = urldata.URLData().get_order_manage_page_url()
            self.convert_to_url(self.convert_URL)
            self.wait_url_to_be(self.convert_URL)

            self.step = "select company"
            self.logger.info(self.step)
            self.wait_clickable(self.order_manage_page.query_button)
            self.Select(self.order_manage_page.company_select,
                        self.company_value)

            self.step = "click query"
            self.logger.info(self.step)
            self.click(self.order_manage_page.query_button)

            self.step = "match result"
            self.logger.info(self.step, 10)
            if not self.find_element(self.order_manage_page.user_phone_info):
                raise Exception("not find result")

            self.testcaseinfo.result = "Pass"

        except TimeoutException:
            self.timeout_method()
        except Exception as err:
            self.exception_method(err)
        finally:
            self.finally_method()