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,answerdetail_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]])
        # 点击回答tab
        ele = find_element.element(self.driver,me_page.answertab_click)
        ele.click()
        # 点击回答列表跳转详情页
        ele = find_element.element(self.driver,me_page.answerlist_click)
        ele.click()
        find_element.ElementNotAssert(self.driver, diaryposts_detailpage_Page.highlight_word)
        time.sleep(1)




    def test_01_answerdetailpage(self):
        '回答详情页pv事件'
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "message_id": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "in": "1629877445",
        #     "out_time_millis": "1629877454948",
        #     "referrer": "my_favor_answer",
        #     "fake": 0,
        #     "page_name": "answer_detail",
        #     "referrer_id": "",
        #     "business_id": "711257",
        #     "out": "1629877454",
        #     "referrer_tab_name": "",
        #     "in_time_millis": "1629877445051",
        #     "extra_param": "{\n  \"page_owner\" : \"others_answer\"\n}",
        #     "is_first": 1,
        #     "is_push": 0
        # "type": "page_view",
        result = mitm_query(action="page_view", page_name="answer_detail")
        AssertLen.maidiannumber(result)





    def test_02_answerdetailpage(self):
        '返回按钮点击'
        ele = find_element.element(self.driver,answerdetail_Page.cannel)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer_link": [
        #         "home",
        #         "personal_home"
        #     ],
        #     "button_name": "return",
        #     "page_name": "answer_detail"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", button_name="return", page_name="answer_detail")
        AssertLen.maidiannumber(result)



    def test_03_answerdetailpage(self):
        '点击搜索按钮'
        ele = find_element.element(self.driver,answerdetail_Page.search)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "page_name": "answer_detail",
        #     "tab": "",
        #     "referrer": "my_favor_answer",
        #     "input_type": "详情页默认词",
        #     "business_id": "711257",
        #     "query": "美白针",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "referrer_id": ""
        # },
        # "type": "do_search",
        result = mitm_query(action="do_search",page_name="answer_detail", referrer="my_favor_answer", input_type="详情页默认词")
        AssertLen.maidiannumber(result)



    def test_04_answerdetailpage(self):
        '收藏按钮点击'
        ele = find_element.element(self.driver,answerdetail_Page.collection)
        ele.click()
        time.sleep(2)
        ele = find_element.element(self.driver, answerdetail_Page.collection)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "business_id": "711257",
        #     "page_name": "answer_detail",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "button_name": "attention",
        #     "referrer": "my_favor_answer",
        #     "referrer_id": ""
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", page_name="answer_detail", button_name="attention",referrer="my_favor_answer")
        AssertLen.maidiannumber(result)



    def test_05_answerdetailpage(self):
        '取消收藏按钮点击'
        ele = find_element.element(self.driver,answerdetail_Page.collection)
        ele.click()
        time.sleep(2)
        ele = find_element.element(self.driver, answerdetail_Page.collection)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "business_id": "711257",
        #     "page_name": "answer_detail",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "button_name": "no_attention",
        #     "referrer": "my_favor_answer",
        #     "referrer_id": ""
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", page_name="answer_detail", button_name="no_attention",referrer="my_favor_answer")
        AssertLen.maidiannumber(result)



    def test_06_answerdetailpage(self):
        '分享按钮点击'
        ele = find_element.element(self.driver,answerdetail_Page.share)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "page_name": "answer_detail",
        #     "business_id": "711257",
        #     "referrer": "my_favor_answer",
        #     "referrer_tab_name": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "referrer_id": "",
        #     "tab_name": "",
        #     "url": "https:\/\/m.igengmei.com\/answer\/711257?is_share=1"
        # },
        # "type": "page_click_share",
        result = mitm_query(action="page_click_share", page_name="answer_detail", referrer="my_favor_answer")
        AssertLen.maidiannumber(result)




    def test_07_answerdetailpage(self):
        '写回答按钮点击'
        self.driver.tap([[958,441]])
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "business_id": "711257",
        #     "button_name": "写回答",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "referrer": "my_favor_answer",
        #     "page_name": "answer_detail",
        #     "referrer_id": ""
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", button_name="写回答", referrer="my_favor_answer", page_name="answer_detail")
        AssertLen.maidiannumber(result)



    def test_08_answerdetailpage(self):
        '查看全部回答按钮点击'
        self.driver.tap([[352, 441]])
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "business_id": "711257",
        #     "button_name": "查看全部NUM个回答",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "referrer": "my_favor_answer",
        #     "page_name": "answer_detail",
        #     "referrer_id": ""
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", button_name="查看全部NUM个回答", referrer="my_favor_answer", page_name="answer_detail")
        AssertLen.maidiannumber(result)



    def test_09_answerdetailpage(self):
        '关注按钮点击'
        self.driver.tap([[953, 634]])
        time.sleep(2)
        self.driver.tap([[953, 634]])
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "business_id": "711257",
        #     "button_name": "关注",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "referrer": "my_favor_answer",
        #     "page_name": "answer_detail",
        #     "referrer_id": ""
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button",button_name="关注", referrer="my_favor_answer", page_name="answer_detail")
        AssertLen.maidiannumber(result)



    def test_10_answerdetailpage(self):
        '关注按钮点击'
        self.driver.tap([[953, 634]])
        time.sleep(2)
        self.driver.tap([[953, 634]])
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "business_id": "711257",
        #     "button_name": "取消关注",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "referrer": "my_favor_answer",
        #     "page_name": "answer_detail",
        #     "referrer_id": ""
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", button_name="取消关注", referrer="my_favor_answer", page_name="answer_detail")
        AssertLen.maidiannumber(result)


    def test_11_answerdetailpage(self):
        '评论框按钮点击'
        ele = find_element.element(self.driver,answerdetail_Page.content)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "button_name": "bottom_comment_area",
        #     "referrer_id": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "referrer": "my_favor_answer",
        #     "business_id": "711257",
        #     "page_name": "answer_detail"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", button_name="bottom_comment_area", referrer="my_favor_answer", page_name="answer_detail")
        AssertLen.maidiannumber(result)


    def test_12_answerdetailpage(self):
        '评论点击popupview'
        ele = find_element.element(self.driver, answerdetail_Page.content)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "page_name": "answer_detail",
        #     "business_id": "711257",
        #     "popup_name": "all_comment"
        # },
        # "type": "popup_view",
        result = mitm_query(action="popup_view", page_name="answer_detail", popup_name="all_comment")
        AssertLen.maidiannumber(result)


    def test_13_answerdetailpage(self):
        '点赞按钮点击'
        self.driver.tap([[822, 2216]])
        time.sleep(2)
        self.driver.tap([[822, 2216]])
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "button_name": "like",
        #     "referrer_id": "",
        #     "referrer_link": [
        #         "home",
        #         "personal_home",
        #         "my_favor_answer"
        #     ],
        #     "referrer": "my_favor_answer",
        #     "business_id": "711257",
        #     "page_name": "answer_detail"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", button_name="like", page_name="answer_detail")
        AssertLen.maidiannumber(result)

























