import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
# import event
from appiumConfigure.config import appiumConfig
from appiumConfigure import find_element
from page import home_Page,search_Page,ai_Page
from Charles.mitm import mitm_query
from appiumConfigure import backtoapp
from Charles import AssertLen
import time
class Case(appiumConfig):

    def test_01_ai_channel(self):
        '模拟双眼皮 - 拍照 - 报告页'
        # 关闭弹窗点击
        find_element.ElementNotAssert(self.driver, home_Page.dialog_home_img_cancel)

        # 首页点击双眼皮按钮
        ele = find_element.element(self.driver, home_Page.double_eye)
        ele.click()
        # 弹窗关闭按钮点击
        find_element.ElementNotAssert(self.driver, ai_Page.double_eye_iv_close_pop)
        # 点击拍照按钮
        ele = find_element.element(self.driver,ai_Page.double_eye_take_photo_record_button)
        ele.click()
        time.sleep(3)
        backtoapp.backapp(self.driver,2)

        # "params": {
        #     "referrer_tab_name": "",
        #     "referrer_id": "34295326",
        #     "in": "1617008282",
        #     "is_first": "1",
        #     "referrer_link": [
        #         "",
        #         "face_scan"
        #     ],
        #     "in_time_millis": 1617008282205,
        #     "out": "1617008297",
        #     "referrer": "face_scan",
        #     "is_push": 0,
        #     "page_name": "eyes_simulator",
        #     "out_time_millis": 1617008297602,
        #     "fake": 0,
        #     "business_id": "",
        #     "extra_param": ""
        # },
        # "type": "page_view",

        result = mitm_query(action="page_view", page_name="eyes_simulator")
        AssertLen.maidiannumber(result)



    def test_02_ai_channel(self):
        '双眼皮 - 面孔起源 - 男 - 拍照 - 报告页'
        # 关闭弹窗点击
        find_element.ElementNotAssert(self.driver, home_Page.dialog_home_img_cancel)

        # 首页点击双眼皮按钮
        ele = find_element.element(self.driver, home_Page.double_eye)
        ele.click()
        # 弹窗关闭按钮点击
        find_element.ElementNotAssert(self.driver, ai_Page.double_eye_iv_close_pop)
        # 点击面孔起源tab
        face_ai_gene = find_element.element(self.driver, ai_Page.face_ai_gene)
        face_ai_gene.click()
        # 点击男生选项
        face_gene_male = find_element.element(self.driver, ai_Page.face_gene_male)
        face_gene_male.click()
        # 点击拍照按钮
        take_photo_record_button = find_element.element(self.driver, ai_Page.take_photo_record_button)
        take_photo_record_button.click()
        time.sleep(1)
        # 点击跳过按钮
        jump = find_element.element(self.driver, ai_Page.jump)
        jump.click()
        time.sleep(2)
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer_tab_name": "",
        #     "referrer_id": "",
        #     "in": "1617009269",
        #     "is_first": "1",
        #     "referrer_link": [
        #         "",
        #         "face_scan",
        #         "face_scan_loading"
        #     ],
        #     "out": "1617009277",
        #     "referrer": "face_scan_loading",
        #     "is_push": "0",
        #     "page_name": "face_institute_report",
        #     "out_time_millis": 1617009277507,
        #     "fake": 0,
        #     "business_id": ""
        # },
        # "type": "page_view",
        result = mitm_query(action="page_view", referrer="face_scan_loading", page_name="face_institute_report")
        AssertLen.maidiannumber(result)



    def test_03_ai_channel(self):
        '双眼皮-测颜值-拍照-报告页'
        # 关闭弹窗点击
        find_element.ElementNotAssert(self.driver, home_Page.dialog_home_img_cancel)
        # 首页点击双眼皮按钮
        ele = find_element.element(self.driver, home_Page.double_eye)
        ele.click()
        # 弹窗关闭按钮点击
        find_element.ElementNotAssert(self.driver, ai_Page.double_eye_iv_close_pop)
        # 点击测颜值tab
        ele = find_element.element(self.driver,ai_Page.scan_tab)
        ele.click()
        # 点击拍照按钮
        ele = find_element.element(self.driver,ai_Page.take_photo_record_button)
        ele.click()
        time.sleep(1)
        # 点击跳过按钮
        ele = find_element.element(self.driver, ai_Page.jump)
        ele.click()
        time.sleep(5)
        backtoapp.backapp(self.driver,2)

    #     "params": {
    #         "message_id": "",
    #         "referrer_link": [
    #             "home",
    #             "face_scan",
    #             "",
    #             "face_scan_loading"
    #         ],
    #         "in": "1617074825",
    #         "out_time_millis": "1617074833608",
    #         "referrer": "face_scan_loading",
    #         "fake": 0,
    #         "page_name": "report_result",
    #         "referrer_id": "",
    #         "business_id": "",
    #         "out": "1617074833",
    #         "referrer_tab_name": "",
    #         "in_time_millis": "1617074825172",
    #         "extra_param": "",
    #         "is_first": 1,
    #         "is_push": 0
    #       "type": "page_view",

        result = mitm_query(action="page_view",referrer="face_scan_loading",page_name="report_result")
        AssertLen.maidiannumber(result)



    def test_04_ai_channel(self):
        '双眼皮-测肤质-拍照-报告页'
        # 关闭弹窗点击
        find_element.ElementNotAssert(self.driver, home_Page.dialog_home_img_cancel)
        # 首页点击双眼皮按钮
        ele = find_element.element(self.driver, home_Page.double_eye)
        ele.click()
        # 弹窗关闭按钮点击
        find_element.ElementNotAssert(self.driver, ai_Page.double_eye_iv_close_pop)
        # 点击测肤质tab
        ele = find_element.element(self.driver, ai_Page.skin_tab)
        ele.click()
        # 点击拍照按钮
        take_photo_record_button = find_element.element(self.driver, ai_Page.take_photo_record_button)
        take_photo_record_button.click()
        time.sleep(10)
        backtoapp.backapp(self.driver,2)

        # "params": {
        #     "message_id": "",
        #     "referrer_link": [
        #         "home",
        #         "face_scan"
        #     ],
        #     "in": "1617089163",
        #     "out_time_millis": "1617089167992",
        #     "referrer": "face_scan",
        #     "fake": 0,
        #     "page_name": "face_detect_result",
        #     "referrer_id": "",
        #     "business_id": "",
        #     "out": "1617089167",
        #     "referrer_tab_name": "",
        #     "in_time_millis": "1617089163776",
        #     "extra_param": "",
        #     "is_first": 0,
        #     "is_push": 0
        # }, "type":"page_view",


        result = mitm_query(action="page_view", page_name="face_detect_result", referrer="face_scan")
        AssertLen.maidiannumber(result)


    def test_05_ai_channel(self):
        '双眼皮-测肤质-模拟整形-拍照-报告页'
        # 关闭弹窗点击
        find_element.ElementNotAssert(self.driver, home_Page.dialog_home_img_cancel)
        # 首页点击双眼皮按钮
        ele = find_element.element(self.driver, home_Page.double_eye)
        ele.click()
        # 弹窗关闭按钮点击
        find_element.ElementNotAssert(self.driver, ai_Page.double_eye_iv_close_pop)
        # 点击测肤质tab
        ele = find_element.element(self.driver, ai_Page.skin_tab)
        ele.click()
        # 点击模拟整形tab
        ele = find_element.element(self.driver, ai_Page.zhengxing_tab)
        ele.click()
        # 点击拍照按钮
        take_photo_record_button = find_element.element(self.driver, ai_Page.take_photo_record_button)
        take_photo_record_button.click()
        time.sleep(2)
        backtoapp.backapp(self.driver,2)

        # "params": {
        #     "message_id": "",
        #     "referrer_link": [
        #         "home",
        #         "face_scan"
        #     ],
        #     "in": "1617091605",
        #     "out_time_millis": "1617091610215",
        #     "referrer": "face_scan",
        #     "fake": 0,
        #     "page_name": "face_simulator_new",
        #     "referrer_id": "",
        #     "business_id": "",
        #     "out": "1617091610",
        #     "referrer_tab_name": "",
        #     "in_time_millis": "1617091605565",
        #     "extra_param": "",
        #     "is_first": 1,
        #     "is_push": 0
        # },  "type":"page_view",
        result = mitm_query(action="page_view", referrer="face_scan", page_name="face_simulator_new")
        AssertLen.maidiannumber(result)


    def test_06_ai_channel(self):
        '双眼皮-测肤质-ai变脸-拍照-报告页'
        # 关闭弹窗点击
        find_element.ElementNotAssert(self.driver, home_Page.dialog_home_img_cancel)
        # 首页点击双眼皮按钮
        ele = find_element.element(self.driver, home_Page.double_eye)
        ele.click()
        # 弹窗关闭按钮点击
        find_element.ElementNotAssert(self.driver, ai_Page.double_eye_iv_close_pop)
        # 点击测肤质tab
        ele = find_element.element(self.driver, ai_Page.skin_tab)
        ele.click()
        # 点击ai变脸按钮
        ele = find_element.element(self.driver,ai_Page.face_ai_plastic)
        ele.click()
        # 点击拍照按钮
        take_photo_record_button = find_element.element(self.driver, ai_Page.take_photo_record_button)
        take_photo_record_button.click()
        time.sleep(10)
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "message_id": "",
        #     "referrer_link": [
        #         "home",
        #         "face_scan"
        #     ],
        #     "in": "1617098159",
        #     "out_time_millis": "1617098167409",
        #     "referrer": "face_scan",
        #     "fake": 0,
        #     "page_name": "ai_change_face",
        #     "referrer_id": "",
        #     "business_id": "",
        #     "out": "1617098167",
        #     "referrer_tab_name": "",
        #     "in_time_millis": "1617098159351",
        #     "extra_param": "",
        #     "is_first": 1,
        #     "is_push": 0
        # },  "type":"page_view",
        result = mitm_query(action="page_view", referrer="face_scan", page_name="ai_change_face")
        AssertLen.maidiannumber(result)









