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,news_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-300), int(y-10)]])

    def test_01_news(self):
        '点击首页-消息按钮'
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer": "personal_home",
        #     "sec_tab_name": "",
        #     "tab_type": "out_tab",
        #     "referrer_id": "2892",
        #     "page_name": "message_home",
        #     "tab_name": "message",
        #     "referrer_link": [
        #         "home"
        #     ],
        #     "position": "2",
        #     "business_id": ""
        # },
        # "type": "on_click_tab",
        result = mitm_query(action="on_click_tab", referrer="home", page_name="message_home", tab_name="message")
        AssertLen.maidiannumber(result)


    def test_02_news(self):
        '点击标记已读按钮'
        ele = find_element.element(self.driver,news_Page.Read)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer_link": [
        #         "home"
        #     ]
        # },
        # "type": "message_home_click_delete",
        result = mitm_query(action="message_home_click_delete")
        AssertLen.maidiannumber(result)



    def test_03_news(self):
        '点击赞/收藏按钮'
        ele = find_element.element(self.driver,news_Page.fabulous_Collection)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "tab": "votecollect",
        #     "referrer_link": [
        #
        #     ]
        # },
        # "type": "message_home_click_tab",
        result = mitm_query(action="message_home_click_tab", tab="votecollect")
        AssertLen.maidiannumber(result)

    def test_04_news(self):
        '回复按钮点击'
        ele = find_element.element(self.driver,news_Page.reply)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "tab": "comment",
        #     "referrer_link": [
        #
        #     ]
        # },
        # "type": "message_home_click_tab",
        result = mitm_query(action="message_home_click_tab", tab="comment")
        AssertLen.maidiannumber(result)

    def test_05_news(self):
        '通知按钮点击'
        ele = find_element.element(self.driver,news_Page.notice)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "tab": "notification",
        #     "referrer_link": [
        #
        #     ]
        # },
        # "type": "message_home_click_tab",
        result = mitm_query(action="message_home_click_tab", tab="notification")
        AssertLen.maidiannumber(result)

    def test_06_news(self):
        '点击关注按钮'
        ele = find_element.element(self.driver,news_Page.follow)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "tab": "follow",
        #     "referrer_link": [
        #
        #     ]
        # },
        # "type": "message_home_click_tab",
        result = mitm_query(action="message_home_click_tab",tab="follow")
        AssertLen.maidiannumber(result)


    def test_07_new(self):
        '点击feed流信息'
        self.driver.tap([[500,720]])
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "account_id": "fb38be6e52b34b6d8efe7a30d2c93022",
        #     "referrer_link": [
        #
        #     ],
        #     "position": 1,
        #     "msg_id": 16344564
        # },
        # "type": "message_home_private_msg_click_item",
        result =mitm_query(action="message_home_private_msg_click_item")
        AssertLen.maidiannumber(result)











