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 setup(self):
        # 点击关闭弹窗
        find_element.ElementNotAssert(self.driver, home_Page.dialog_home_img_cancel)

        # 点击扫脸按钮
        scan = find_element.element(self.driver, home_Page.scan)
        scan.click()

        # 点击扫脸引导弹窗 -- 出现不稳定 采用容错机制
        find_element.ElementNotAssert(self.driver, ai_Page.aiScan)

        # 点击模拟整形
        ele = find_element.element(self.driver, ai_Page.zhengxing_tab)
        ele.click()

        # 点击3d变脸
        ele = find_element.element(self.driver, ai_Page.three_D_bianlian)
        ele.click()

        # 点击模拟发型
        ele = find_element.element(self.driver, ai_Page.hair_tab)
        ele.click()



    def test_01_ai_hair(self):
        '模拟发型tab点击'
        self.setup()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "page_name": "face_scan",
        #     "business_id": "",
        #     "referrer": "home",
        #     "position": 7,
        #     "referrer_link": [
        #
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "模拟发型"
        # },
        # "type": "on_click_tab",
        result = mitm_query(action="on_click_tab", page_name="face_scan", referrer="home", tab_name="模拟发型")
        AssertLen.maidiannumber(result)


    def test_02_ai_hair(self):
        '模拟发型弹窗关闭按钮点击'
        self.setup()
        # 模拟发型弹窗关闭按钮
        ele = find_element.element(self.driver, ai_Page.hair_close)
        ele.click()
        # "params": {
        #     "button_name": "close",
        #     "business_id": "",
        #     "referrer": "",
        #     "page_name": "face_scan",
        #     "popup_name": "ask_open_album",
        #     "referrer_link": [
        #
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "模拟发型"
        # },
        #  "type":"on_click_button",
        result = mitm_query(action="on_click_button", button_name="close", page_name="face_scan", popup_name="ask_open_album")
        AssertLen.maidiannumber(result)


    def test_03_ai_hair(self):
        '模拟发型弹窗打开相册按钮'
        self.setup()
        # 点击打开相册按钮
        ele = find_element.element(self.driver,ai_Page.hair_open_picture)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "button_name": "open_album",
        #     "business_id": "",
        #     "referrer": "",
        #     "page_name": "face_scan",
        #     "popup_name": "ask_open_album",
        #     "referrer_link": [
        #
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "模拟发型"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", button_name="open_album", page_name="face_scan", popup_name="ask_open_album")
        AssertLen.maidiannumber(result)


    def test_04_ai_hair(self):
        '模拟发型拍照按钮点击'
        self.setup()
        # 模拟发型弹窗关闭按钮
        find_element.ElementNotAssert(self.driver, ai_Page.hair_close)
        # 拍照按钮点击
        ele = find_element.element(self.driver,ai_Page.photo_record_button_hair)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "page_name": "face_scan",
        #     "business_id": "",
        #     "referrer": "home",
        #     "button_name": "take_pic",
        #     "referrer_link": [
        #         "home"
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "模拟发型"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", page_name="face_scan", referrer="home", button_name="take_pic", tab_name="模拟发型")
        AssertLen.maidiannumber(result)













