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,swip
from page import home_Page,search_Page,ai_Page,timecard_Page,me_page,doctorhome_Page
from Charles.mitm import mitm_query
from appiumConfigure import backtoapp
from Charles import AssertLen
import time
from selenium.webdriver.common.action_chains import ActionChains
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support.wait import WebDriverWait
from appium.webdriver.mobilecommand import MobileCommand
class Case(appiumConfig):

    def setUp(self):
        super().setUp()
        # 关闭弹窗点击
        find_element.ElementNotAssert(self.driver, home_Page.dialog_home_img_cancel)
        time.sleep(5)
        # 点击我的按钮
        y = self.driver.get_window_size()['height']
        x = self.driver.get_window_size()['width']
        print(x, y)
        self.driver.tap([[int(x-10), int(y-10)]])
        ele = find_element.element(self.driver,me_page.follow)
        ele.click()
        time.sleep(1)
        self.driver.tap([[500,500]])



    def test_01_doctor_home(self):
        '医生主页pv'
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer_tab_name": "",
        #     "referrer_id": "",
        #     "in": "1625641471",
        #     "is_first": "1",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_focus"
        #     ],
        #     "in_time_millis": 1625641471814,
        #     "out": "1625641479",
        #     "referrer": "my_focus",
        #     "is_push": 0,
        #     "page_name": "expert_detail",
        #     "out_time_millis": 1625641479221,
        #     "fake": 0,
        #     "business_id": "458fa922fde945cb901c1547f6d91ed1",
        #     "extra_param": "{\"is_video\":\"1\"}"
        # },
        # "type": "page_view",
        result = mitm_query(action="page_view", referrer="my_focus", page_name="expert_detail")
        AssertLen.maidiannumber(result)


    def test_02_doctor_home(self):
        '返回按钮点击埋点'
        # ele = find_element.element(self.driver,doctorhome_Page.cannel)
        # ele.click()

        self.driver.tap([[50,200]])

        # "params": {
        #     "referrer": "my_focus",
        #     "referrer_id": "",
        #     "button_name": "exit",
        #     "page_name": "expert_detail",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_focus"
        #     ],
        #     "business_id": "458fa922fde945cb901c1547f6d91ed1"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", referrer="my_focus", button_name="exit")
        AssertLen.maidiannumber(result)

    def test_03_doctor_home(self):
        '点击分享按钮'
        ele = find_element.element(self.driver,doctorhome_Page.doctor_share)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer": "my_focus",
        #     "referrer_id": "",
        #     "page_name": "expert_detail",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_focus"
        #     ],
        #     "business_id": "458fa922fde945cb901c1547f6d91ed1",
        #     "url": "https://m.igengmei.com/expert/458fa922fde945cb901c1547f6d91ed1?is_share=1"
        # },
        # "type": "page_click_share",
        result = mitm_query(action="page_click_share", referrer="my_focus", page_name="expert_detail")
        AssertLen.maidiannumber(result)

    def test_04_doctor_home(self):
        '点击位置获取按钮'
        self.driver.tap([[800,700]])
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer": "my_focus",
        #     "referrer_id": "",
        #     "button_name": "organization_locate",
        #     "page_name": "expert_detail",
        #     "tab_name": "综合",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_focus"
        #     ],
        #     "business_id": "458879d7095c4f90a60b64a430cb3544"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", referrer="my_focus", button_name="organization_locate",page_name="expert_detail")
        AssertLen.maidiannumber(result)


    def test_05_doctor_home(self):
        '点击拨打电话按钮'
        self.driver.tap([[900, 700]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer": "my_focus",
        #     "referrer_id": "",
        #     "button_name": "电话咨询",
        #     "page_name": "expert_detail",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_focus"
        #     ],
        #     "business_id": "458879d7095c4f90a60b64a430cb3544"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", referrer="my_focus", button_name="电话咨询", page_name="expert_detail")
        AssertLen.maidiannumber(result)

