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_skin(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
        skin_tab = find_element.element(self.driver, ai_Page.skin_tab)
        skin_tab.click()

        backtoapp.backapp(self.driver,3)
        #{'page_name': 'face_scan',
        # 'referrer_link': [''],
        # 'tab_name': 'AI测肤',
        # 'position': 1}
        # 'type': 'on_click_tab',
        result = mitm_query(action="on_click_tab", page_name="face_scan", tab_name="AI测肤", position=1)
        AssertLen.maidiannumber(result)


    def test_02_ai_skin(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
        skin_tab = find_element.element(self.driver, ai_Page.skin_tab)
        skin_tab.click()

        # 点击相册按钮
        PictureButton = find_element.element(self.driver, ai_Page.PictureButton)
        PictureButton.click()

        # 退至后台
        backtoapp.backapp(self.driver, 2)

        # 点击相册埋点
        # "params": {
        #     "button_name": "album",
        #     "page_name": "face_scan",
        #     "tab_name": "AI测脸",
        #     "referrer_link": [
        #         ""
        #     ]
        # },
        # "type": "on_click_button"

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


    def test_03_ai_skin(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
        skin_tab = find_element.element(self.driver, ai_Page.skin_tab)
        skin_tab.click()

        # 点击上次报告按钮
        Last_report = find_element.element(self.driver, ai_Page.Last_report)
        Last_report.click()

        # 退至后台
        backtoapp.backapp(self.driver, 2)

        # "params": {
        #     "button_name": "last_report",
        #     "page_name": "face_scan",
        #     "tab_name": "AI测脸",
        #     "referrer_link": [
        #         ""
        #     ]
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", page_name="face_scan", button_name="last_report", tab_name="AI测肤")
        AssertLen.maidiannumber(result)


    def test_04_ai_skin(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
        skin_tab = find_element.element(self.driver, ai_Page.skin_tab)
        skin_tab.click()

        # 点击拍照按钮
        take_photo_record_button = find_element.element(self.driver, ai_Page.take_photo_record_button)
        take_photo_record_button.click()

        # 退至后台
        backtoapp.backapp(self.driver, 3)

        # {'button_name': 'take_pic', 、
        # 'page_name': 'face_scan',
        # 'tab_name': 'AI测脸',
        #  'referrer_link': ['']},
        # 'type': 'on_click_button'

        result = mitm_query(action="on_click_button", tab_name="AI测肤", page_name="face_scan", button_name="take_pic")
        AssertLen.maidiannumber(result)