import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
from Charles.mitm import mitm_query
from Charles import AssertLen
from appiumConfigure.config import appiumConfig
from appiumConfigure import find_element
from appiumConfigure import backtoapp
from page import home_Page, ai_Page

class Case(appiumConfig):


    def test_01_ai_zhengxing(self):
        '模拟整形tab埋点点击'
        # 点击关闭弹窗
        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)
        # 点击模拟整形tab
        ele = find_element.element(self.driver,ai_Page.zhengxing_tab)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer": "",
        #     "referrer_id": "",
        #     "page_name": "face_scan",
        #     "tab_name": "模拟整形",
        #     "referrer_link": [
        #         ""
        #     ],
        #     "position": 5,
        #     "business_id": "34027087"
        # },
        # "type": "on_click_tab",

        result = mitm_query(action="on_click_tab", page_name="face_scan", tab_name="模拟整形")
        AssertLen.maidiannumber(result)


    def test_02_ai_zhengxing(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)
        # 点击模拟整形tab
        ele = find_element.element(self.driver, ai_Page.zhengxing_tab)
        ele.click()
        # 点击模拟整形相册按钮
        ele = find_element.element(self.driver,ai_Page.zhengxing_picture_button)
        ele.click()
        backtoapp.backapp(self.driver,2)

        # "params": {
        #     "referrer": "",
        #     "referrer_id": "",
        #     "button_name": "album",
        #     "page_name": "face_scan",
        #     "tab_name": "AI整形",
        #     "referrer_link": [
        #         ""
        #     ],
        #     "business_id": "34027087"
        # },
        # "type": "on_click_button",

        result = mitm_query(action="on_click_button", button_name="album", page_name="face_scan", tab_name="AI整形")
        AssertLen.maidiannumber(result)