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,me_page,diaryposts_detailpage_Page
from Charles.mitm import mitm_query
from appiumConfigure import backtoapp
from Charles import AssertLen
import time
import json
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)]])
        self.driver.tap([[900,520]])
        ele = find_element.element(self.driver,me_page.rijitie)
        ele.click()
        # 到达帖子详情页
        ele = find_element.element(self.driver,me_page.rijitietab_click)
        ele.click()
        find_element.ElementNotAssert(self.driver, diaryposts_detailpage_Page.highlight_word)
        time.sleep(1)


    def test_01_posts_detailpage(self):
        '日记贴详情页pv'
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "message_id": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "in": "1629717577",
        #     "out_time_millis": "1629717584568",
        #     "referrer": "my_favor_topic",
        #     "fake": 0,
        #     "page_name": "topic_detail",
        #     "referrer_id": "",
        #     "business_id": "21041087",
        #     "out": "1629717584",
        #     "referrer_tab_name": "",
        #     "in_time_millis": "1629717577239",
        #     "extra_param": "",
        #     "is_first": 1,
        #     "is_push": 0
        # },
        #
        # "type": "page_view",
        result = mitm_query(action="page_view",page_name="topic_detail",referrer="my_favor_topic")
        AssertLen.maidiannumber(result)


    def test_02_posts_detailpage(self):
        '返回按钮点击埋点'
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.cannel)
        ele.click()
        # "params": {
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "button_name": "return",
        #     "page_name": "topic_detail"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", button_name="return", page_name="topic_detail")
        AssertLen.maidiannumber(result)


    def test_03_posts_detailpage(self):
        '搜索框按钮点击'
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.search_click)
        ele.click()
        # "params": {
        #     "page_name": "topic_detail",
        #     "tab": "",
        #     "referrer": "my_favor_topic",
        #     "input_type": "详情页默认词",
        #     "business_id": "21041087",
        #     "query": "水光针",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "referrer_id": ""
        # },
        # "type": "do_search",
        result = mitm_query(action="do_search", page_name="topic_detail", referrer="my_favor_topic", input_type="详情页默认词")
        AssertLen.maidiannumber(result)


    def test_04_posts_detailpage(self):
        '收藏按钮点击-取消收藏'
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.collection)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # 收藏按钮点击-收藏
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.collection)
        ele.click()

        # "params": {
        #     "business_id": "21041087",
        #     "page_name": "topic_detail",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "button_name": "no_attention",
        #     "referrer": "my_favor_topic",
        #     "referrer_id": ""
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button",page_name="topic_detail", button_name="no_attention",referrer="my_favor_topic")
        AssertLen.maidiannumber(result)





    def test_05_posts_detailpage(self):
        '收藏按钮点击'
        #取消收藏
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.collection)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # 收藏按钮点击-收藏
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.collection)
        ele.click()
        # "params": {
        #     "business_id": "21041087",
        #     "page_name": "topic_detail",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "button_name": "attention",
        #     "referrer": "my_favor_topic",
        #     "referrer_id": ""
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", page_name="topic_detail", button_name="attention",
                            referrer="my_favor_topic")
        AssertLen.maidiannumber(result)



    def test_06_posts_detailpage(self):
        '分享按钮点击'
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.share)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "page_name": "topic_detail",
        #     "business_id": "21495002",
        #     "referrer": "my_favor_topic",
        #     "referrer_tab_name": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "",
        #     "url": "https:\/\/m.igengmei.com\/topic\/21495002"
        # },
        # "type": "page_click_share",
        result = mitm_query(action="page_click_share", page_name="topic_detail", referrer="my_favor_topic")
        AssertLen.maidiannumber(result)


    def test_07_posts_detailpage(self):
        '评论框点击'
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.Comment_box)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "button_name": "comments",
        #     "page_name": "topic_detail",
        #     "referrer": "my_favor_topic",
        #     "business_id": "21495002",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "",
        #     "referrer_tab_name": ""
        # },
        # "type": "on_click_comment",
        result = mitm_query(action="on_click_comment", button_name="comments", page_name="topic_detail")
        AssertLen.maidiannumber(result)



    def test_08_posts_detailpage(self):
        '点赞按钮点击'
        self.driver.tap([[778,2250]])
        backtoapp.backapp(self.driver,2)
        self.driver.tap([[778, 2250]])
        # "params": {
        #     "motion": "vote",
        #     "referrer": "my_favor_topic",
        #     "referrer_link": [
        #         "personal_home",
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "page_name": "topic_detail",
        #     "business_id": "21495002",
        #     "referrer_id": ""
        # },
        # "type": "on_click_vote",
        result = mitm_query(action="on_click_vote",motion="vote", referrer="my_favor_topic",page_name="topic_detail")
        AssertLen.maidiannumber(result)



    def test_09_posts_detailpage(self):
        '评论按钮点击'
        self.driver.tap([[1078, 2250]])
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "page_name": "topic_detail",
        #     "business_id": "21495002",
        #     "referrer": "my_favor_topic",
        #     "motion": "comments",
        #     "button_name": "comments",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "",
        #     "referrer_tab_name": ""
        # },
        # "type": "on_click_comment",
        result = mitm_query(action="on_click_comment", page_name="topic_detail", referrer="my_favor_topic", motion="comments")
        AssertLen.maidiannumber(result)



    def test_10_posts_detailpage(self):
        '评论区弹窗popupview'
        self.driver.tap([[1078, 2250]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "business_id": "",
        #     "referrer_id": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "referrer": "",
        #     "page_name": "answer_comment",
        #     "popup_name": "answer_comment"
        # },
        # "type": "popup_view",
        result = mitm_query(action="popup_view", page_name="answer_comment", popup_name="answer_comment")
        AssertLen.maidiannumber(result)


    def test_11_posts_detailpage(self):
        '关注按钮点击埋点'
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.attention)
        ele.click()
        time.sleep(2)
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.attention)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "page_name": "topic_detail",
        #     "business_id": "21495002",
        #     "referrer": "my_favor_topic",
        #     "action": "do",
        #     "attention_type": "user",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "referrer_id": ""
        # },
        # "type": "attention_click",
        result = mitm_query(action="attention_click", page_name="topic_detail", referrer="my_favor_topic", attention_type="user")
        AssertLen.maidiannumber(result)




    def test_12_posts_detailpage(self):
        '取消关注按钮点击埋点'
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.attention)
        ele.click()
        time.sleep(2)
        ele = find_element.element(self.driver, diaryposts_detailpage_Page.attention)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "page_name": "topic_detail",
        #     "business_id": "21495002",
        #     "referrer": "my_favor_topic",
        #     "action": "undo",
        #     "attention_type": "user",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_topic"
        #     ],
        #     "referrer_id": ""
        # },
        # "type": "attention_click",
        result = mitm_query(action="attention_click", page_name="topic_detail", referrer="my_favor_topic")
        AssertLen.maidiannumber(result)








































