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,timecard_Page,me_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)]])

    def test_01_me(self):
        '我的按钮点击埋点'
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "page_name": "personal_home",
        #     "position": 4,
        #     "business_id": "",
        #     "referrer": "home",
        #     "tab_type": "out_tab",
        #     "referrer_link": [
        #
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "personal",
        #     "sec_tab_name": ""
        # }, "type":"on_click_tab",
        result = mitm_query(action="on_click_tab", page_name="personal_home", referrer="home", tab_type="out_tab")
        AssertLen.maidiannumber(result)


    def test_02_me(self):
        '个人中心页pv'
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "message_id": "",
        #     "referrer_link": [
        #         "home"
        #     ],
        #     "in": "1624935201",
        #     "out_time_millis": "1624935211136",
        #     "referrer": "home",
        #     "fake": 0,
        #     "page_name": "personal_home",
        #     "referrer_id": "",
        #     "business_id": "",
        #     "out": "1624935211",
        #     "referrer_tab_name": "",
        #     "in_time_millis": "1624935201743",
        #     "extra_param": "",
        #     "is_first": 0,
        #     "is_push": 0
        # },     "type":"page_view",
        result = mitm_query(action="page_view", referrer="home", page_name="personal_home")
        AssertLen.maidiannumber(result)


    def test_03_me(self):
        '个人中心页-日记按钮点击埋点'
        self.driver.tap([[200,500]])
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "page_name": "personal_home",
        #     "business_id": "",
        #     "referrer": "home",
        #     "item_name": "diary",
        #     "referrer_link": [
        #         "home"
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "猜你喜欢"
        # }, "type":"personal_home_click_item",
        result = mitm_query(action="personal_home_click_item",page_name="personal_home", referrer="home", item_name="diary", tab_name="猜你喜欢")
        AssertLen.maidiannumber(result)

    def test_04_me(self):
        '个人中心页-日记本列表页面pv'
        self.driver.tap([[200,500]])
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "message_id": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home"
        #     ],
        #     "in": "1624936635",
        #     "out_time_millis": "1624936655747",
        #     "referrer": "personal_home",
        #     "fake": 0,
        #     "page_name": "my_diary",
        #     "referrer_id": "",
        #     "business_id": "",
        #     "out": "1624936655",
        #     "referrer_tab_name": "",
        #     "in_time_millis": "1624936635240",
        #     "extra_param": "",
        #     "is_first": 1,
        #     "is_push": 0
        # }, "type":"page_view",
        result = mitm_query(action="page_view", referrer="personal_home", page_name="my_diary")
        AssertLen.maidiannumber(result)


    def test_05_me(self):
        '帖子按钮点击'
        self.driver.tap([[300, 520]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer_link": [
        #         "home",
        #         "personal_home"
        #     ],
        #     "tab_name": "public"
        # }, "type":"mytopic_click_tab",
        result = mitm_query(action="mytopic_click_tab", tab_name="public")
        AssertLen.maidiannumber(result)


    def test_06_me(self):
        '个人中心帖子详情页pv'
        self.driver.tap([[300, 520]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "message_id": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home"
        #     ],
        #     "in": "1625042122",
        #     "out_time_millis": "1625042125921",
        #     "referrer": "personal_home",
        #     "fake": 0,
        #     "page_name": "mytopic",
        #     "referrer_id": "",
        #     "business_id": "",
        #     "out": "1625042125",
        #     "referrer_tab_name": "",
        #     "in_time_millis": "1625042122067",
        #     "extra_param": "",
        #     "is_first": 1,
        #     "is_push": 0
        # }, "type":"page_view",
        result = mitm_query(action="page_view", referrer="personal_home", page_name="mytopic")
        AssertLen.maidiannumber(result)

    def test_07_me(self):
        '问题按钮点击'
        self.driver.tap([[650, 500]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #         #     "page_name": "personal_home",
        #         #     "business_id": "",
        #         #     "referrer": "home",
        #         #     "item_name": "answer",
        #         #     "referrer_link": [
        #         #         "home"
        #         #     ],
        #         #     "referrer_id": "",
        #         #     "tab_name": "猜你喜欢"
        #         # }, "type":"personal_home_click_item",
        result = mitm_query(action="personal_home_click_item",page_name="personal_home", referrer="home",item_name="answer")
        AssertLen.maidiannumber(result)


    def test_08_me(self):
        '收藏按钮点击'
        self.driver.tap([[900,520]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "page_name": "personal_home",
        #     "business_id": "",
        #     "referrer": "home",
        #     "item_name": "collection",
        #     "referrer_link": [
        #         "home"
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "猜你喜欢"
        # }, "type":"personal_home_click_item",
        result = mitm_query(action="personal_home_click_item", page_name="personal_home", referrer="home")
        AssertLen.maidiannumber(result)


    def test_09_me(self):
        '收藏按钮点击后收藏列表的pv'
        self.driver.tap([[900,520]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "message_id": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "home",
        #         "personal_home"
        #     ],
        #     "in": "1625047460",
        #     "out_time_millis": "1625047464756",
        #     "referrer": "personal_home",
        #     "fake": 0,
        #     "page_name": "my_favor_service",
        #     "referrer_id": "",
        #     "business_id": "",
        #     "out": "1625047464",
        #     "referrer_tab_name": "",
        #     "in_time_millis": "1625047460341",
        #     "extra_param": "",
        #     "is_first": 1,
        #     "is_push": 0
        # },  "type":"page_view",

        result = mitm_query(action="page_view", referrer="personal_home", page_name="my_favor_service")
        AssertLen.maidiannumber(result)


    def test_10_me(self):
        '我的订单按钮点击'
        ele = find_element.element(self.driver,me_page.my_order)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer": "home",
        #     "referrer_id": "",
        #     "page_name": "personal_home",
        #     "tab_name": "猜你喜欢",
        #     "referrer_link": [
        #
        #     ],
        #     "item_name": "order"
        # },
        # "type": "personal_home_click_item"
        result = mitm_query(action="personal_home_click_item", page_name="personal_home", referrer="personal_home",item_name="order")
        AssertLen.maidiannumber(result)


    def test_11_me(self):
        '我的订单pv'
        ele = find_element.element(self.driver, me_page.my_order)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "message_id": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "home",
        #         "personal_home"
        #     ],
        #     "in": "1625048500",
        #     "out_time_millis": "1625048503654",
        #     "referrer": "personal_home",
        #     "fake": 0,
        #     "page_name": "my_order",
        #     "referrer_id": "",
        #     "business_id": "",
        #     "out": "1625048503",
        #     "referrer_tab_name": "",
        #     "in_time_millis": "1625048500808",
        #     "extra_param": "",
        #     "is_first": 1,
        #     "is_push": 0
        # },  "type":"page_view"
        result = mitm_query(action="page_view", referrer="personal_home", page_name="my_order")
        AssertLen.maidiannumber(result)


    def test_12_me(self):
        '点击美券按钮'
        ele = find_element.element(self.driver, me_page.American_securities)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params":{
        #     "referrer":"home",
        #     "referrer_id":"",
        #     "page_name":"personal_home",
        #     "tab_name":"猜你喜欢",
        #     "referrer_link":[
        #
        #     ],
        #     "item_name":"coupon"
        # },
        # "type":"personal_home_click_item"
        result = mitm_query(action="personal_home_click_item", referrer="home", page_name="personal_home")
        AssertLen.maidiannumber(result)


    def test_13_me(self):
        '美券详情页pv'
        ele = find_element.element(self.driver, me_page.American_securities)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer_tab_name": "",
        #     "referrer_id": "",
        #     "in": "1625106717",
        #     "is_first": "1",
        #     "referrer_link": [
        #         "home",
        #         "personal_home"
        #     ],
        #     "in_time_millis": 1625106717874,
        #     "out": "1625106720",
        #     "referrer": "personal_home",
        #     "is_push": 0,
        #     "page_name": "my_coupon",
        #     "out_time_millis": 1625106720958,
        #     "fake": 0,
        #     "business_id": "",
        #     "extra_param": ""
        # },
        # "type": "page_view",
        result = mitm_query(action="page_view", referrer="personal_home", page_name="my_coupon")
        AssertLen.maidiannumber(result)


    def test_14_me(self):
        '点击美分商城'
        ele = find_element.element(self.driver,me_page.cent)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer": "home",
        #     "referrer_id": "",
        #     "page_name": "personal_home",
        #     "tab_name": "猜你喜欢",
        #     "referrer_link": [
        #
        #     ],
        #     "item_name": "cent_mall"
        # },
        # "type": "personal_home_click_item",
        result = mitm_query(action="personal_home_click_item", item_name="cent_mall", referrer="home", page_name="personal_home")
        AssertLen.maidiannumber(result)


    def test_15_me(self):
        '美分商城详情页pv'
        ele = find_element.element(self.driver, me_page.cent)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer_tab_name": "",
        #     "referrer_id": "",
        #     "in": "1625107068",
        #     "is_first": "1",
        #     "referrer_link": [
        #         "home",
        #         "personal_home"
        #     ],
        #     "in_time_millis": 1625107068285,
        #     "out": "1625107071",
        #     "referrer": "personal_home",
        #     "is_push": 0,
        #     "page_name": "points_shopping_mall",
        #     "out_time_millis": 1625107071211,
        #     "fake": 0,
        #     "business_id": "",
        #     "extra_param": ""
        # },
        # "type": "page_view",
        result = mitm_query(action="page_view", referrer="personal_home", page_name="points_shopping_mall")
        AssertLen.maidiannumber(result)


    def test_16_me(self):
        '签到按钮点击'
        self.driver.tap([[200,1200]])
        backtoapp.backapp(self.driver,2)
        # "params": {
        #         #     "referrer": "home",
        #         #     "referrer_id": "",
        #         #     "page_name": "personal_home",
        #         #     "tab_name": "工具",
        #         #     "referrer_link": [
        #         #
        #         #     ],
        #         #     "item_name": "0"
        #         # },
        #         # "type": "personal_home_click_item",
        result = mitm_query(action="personal_home_click_item", referrer="home", page_name="personal_home", tab_name="工具", item_name="0")
        AssertLen.maidiannumber(result)


    def test_17_me(self):
        '点击任务中心'
        self.driver.tap([[400, 1200]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer": "home",
        #     "referrer_id": "",
        #     "page_name": "personal_home",
        #     "tab_name": "工具",
        #     "referrer_link": [
        #
        #     ],
        #     "item_name": "5"
        # },
        # "type": "personal_home_click_item",
        mitm_query(action="personal_home_click_item", referrer="home", page_name="personal_home", item_name="5")


    def test_18_me(self):
        '点击ai测肤质'
        self.driver.tap([[600,1300]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer": "home",
        #     "referrer_id": "",
        #     "page_name": "personal_home",
        #     "tab_name": "工具",
        #     "referrer_link": [
        #
        #     ],
        #     "item_name": "4"
        # },
        # "type": "personal_home_click_item",
        result = mitm_query(action="personal_home_click_item", referrer="home", page_name="personal_home", tab_name="工具", item_name="4")
        AssertLen.maidiannumber(result)



    def test_19_me(self):
        '点击ai测颜值'
        self.driver.tap([[600, 1300]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer": "home",
        #     "referrer_id": "",
        #     "page_name": "personal_home",
        #     "tab_name": "工具",
        #     "referrer_link": [
        #
        #     ],
        #     "item_name": "19"
        # },
        # "type": "personal_home_click_item",
        result = mitm_query(action="personal_home_click_item", referrer="home", page_name="personal_home", tab_name="工具", item_name="19")
        AssertLen.maidiannumber(result)



    def test_20_me(self):
        '点击模拟整形按钮'
        self.driver.tap([[600, 1300]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer": "home",
        #     "referrer_id": "",
        #     "page_name": "personal_home",
        #     "tab_name": "工具",
        #     "referrer_link": [
        #
        #     ],
        #     "item_name": "20"
        # },
        # "type": "personal_home_click_item",
        result = mitm_query(action="personal_home_click_item", referrer="home", page_name="personal_home",
                            tab_name="工具", item_name="20")
        AssertLen.maidiannumber(result)


    def test_21_me(self):
        '点击客服中心按钮'
        self.driver.tap([[430,1479]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer": "home",
        #     "referrer_id": "",
        #     "page_name": "personal_home",
        #     "tab_name": "工具",
        #     "referrer_link": [
        #
        #     ],
        #     "item_name": "7"
        # },
        # "type": "personal_home_click_item",
        result = mitm_query(action="personal_home_click_item", referrer="home", page_name="personal_home",
                            tab_name="工具", item_name="7")
        AssertLen.maidiannumber(result)



    def test_22_me(self):
        '点击药品验证'
        self.driver.tap([[600,1479]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer": "home",
        #     "referrer_id": "",
        #     "page_name": "personal_home",
        #     "tab_name": "工具",
        #     "referrer_link": [
        #
        #     ],
        #     "item_name": "9"
        # },
        # "type": "personal_home_click_item",
        result = mitm_query(action="personal_home_click_item", referrer="home", page_name="personal_home",
                            tab_name="工具", item_name="9")
        AssertLen.maidiannumber(result)



    def test_23(self):
        '点击粉丝按钮'
        self.driver.tap([[300, 320]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer": "home",
        #     "referrer_id": "",
        #     "page_name": "personal_home",
        #     "tab_name": "猜你喜欢",
        #     "referrer_link": [
        #         "home"
        #     ],
        #     "item_name": "fans"
        # },
        # "type": "personal_home_click_item",
        result = mitm_query(action="personal_home_click_item", referrer="home", page_name="personal_home", tab_name="猜你喜欢", item_name="fans")
        AssertLen.maidiannumber(result)


    def test_24_me(self):
        '点击关注按钮'
        ele = find_element.element(self.driver, me_page.follow)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer": "home",
        #     "referrer_id": "",
        #     "page_name": "personal_home",
        #     "tab_name": "猜你喜欢",
        #     "referrer_link": [
        #
        #     ],
        #     "item_name": "following"
        # },
        # "type": "personal_home_click_item",
        result = mitm_query(action="personal_home_click_item", referrer="home", page_name="personal_home", tab_name="猜你喜欢", item_name="following")
        AssertLen.maidiannumber(result)
