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 login_Page, home_Page
import time
from Charles.mitm import mitm_query
from Charles import AssertLen
from appiumConfigure import backtoapp

class Case(appiumConfig):


    def setUp(self):
        super().setUp()
        # 点击首页关闭弹窗
        find_element.ElementNotAssert(self.driver, home_Page.dialog_home_img_cancel)
        # 点击 我 按钮
        ele = find_element.element(self.driver, home_Page.me)
        ele.click()


    def test_01_aalogin_Page(self):
        '微博按钮点击'
        time.sleep(1)
        # 点击微博登录按钮
        ele = find_element.element(self.driver,login_Page.weibo)
        ele.click()

        backtoapp.backapp(self.driver, 2)
        '''
        "params": {
            "button_name": "microblog",
            "page_name": "login_phone",
            "is_first_start": "0",
            "referrer_link": [
                ""
            ]
        },
        "type": "on_click_button",
        '''
        result = mitm_query(action="on_click_button",button_name="microblog", page_name="one_click_login",is_first_start="0")
        AssertLen.maidiannumber(result)


    def test_02_aalogin_Page(self):
        '微信按钮点击'
        # 点击微信登录按钮
        ele = find_element.element(self.driver, login_Page.weixin)
        ele.click()
        time.sleep(1)
        backtoapp.backapp(self.driver,2)
        '''
         "params":{
            "button_name":"wechat",
            "page_name":"login_phone",
            "is_first_start":"0",
            "referrer_link":[
                ""
            ]
        },
        "type":"on_click_button",
        '''
        result = mitm_query(action="on_click_button", button_name="wechat", page_name="one_click_login")
        AssertLen.maidiannumber(result)



    def test_03_aalogin_Page(self):
        'qq按钮点击'
        time.sleep(1)

        # 点击微信登录按钮
        ele = find_element.element(self.driver, login_Page.qq)
        ele.click()
        backtoapp.backapp(self.driver,2)
        '''
          "params":{
            "button_name":"qq",
            "page_name":"login_phone",
            "is_first_start":"0",
            "referrer_link":[
                ""
            ]
        },
        "type":"on_click_button",
        '''
        result = mitm_query(action="on_click_button", button_name="qq", page_name="one_click_login")
        AssertLen.maidiannumber(result)


    def test_04_aalogin_Page(self):
        '账号密码登录按钮点击'

        # 点击其他账号登录
        ele = find_element.element(self.driver, login_Page.another_login)
        ele.click()
        # 账号密码按钮点击
        ele = find_element.element(self.driver,login_Page.password_login)
        ele.click()
        # "params": {
        #     "button_name": "账号密码登录",
        #     "page_name": "login_phone",
        #     "is_first_start": "0",
        #     "referrer_link": [
        #         ""
        #     ]
        # },
        # "type": "on_click_button"
        result = mitm_query(action="on_click_button", button_name="账号密码登录", page_name="login_phone")
        AssertLen.maidiannumber(result)



    def test_05_aalogin_Page(self):
        '忘记密码按钮点击'

        # 点击其他账号登录
        ele = find_element.element(self.driver, login_Page.another_login)
        ele.click()
        # 点击账号密码登录按钮
        ele = find_element.element(self.driver, login_Page.password_login)
        ele.click()

        #点击忘记密码按钮
        ele = find_element.element(self.driver,login_Page.Forget_password)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer_link": [
        #         ""
        #     ]
        # },
        # "type": "login_click_find_password",
        result= mitm_query(action="login_click_find_password")
        AssertLen.maidiannumber(result)


    def test_06_aalogin_Page(self):
        '忘记密码详情页pv'

        # 点击其他账号登录
        ele = find_element.element(self.driver, login_Page.another_login)
        ele.click()
        # 点击账号密码登录
        ele = find_element.element(self.driver, login_Page.password_login)
        ele.click()
        #点击忘记密码按钮
        ele = find_element.element(self.driver,login_Page.Forget_password)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer_tab_name": "",
        #     "referrer_id": "",
        #     "in": "1627033983",
        #     "is_first": "0",
        #     "referrer_link": [
        #         ""
        #     ],
        #     "in_time_millis": 1627033983847,
        #     "out": "1627033995",
        #     "referrer": "",
        #     "is_push": 0,
        #     "page_name": "register",
        #     "out_time_millis": 1627033995123,
        #     "fake": 0,
        #     "business_id": "",
        #     "extra_param": "{\"is_first_start\":\"0\"}"
        # },
        # "type": "page_view",
        result= mitm_query(action="page_view", page_name="register")
        AssertLen.maidiannumber(result)


    def test_07_aalogin_Page(self):
        '登录页点击立即登录按钮'
        # 点击其他账号登录
        ele = find_element.element(self.driver, login_Page.another_login)
        ele.click()
        # 点击登录按钮
        ele = find_element.element(self.driver,login_Page.login_button)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "phone": "",
        #     "button_name": "login",
        #     "page_name": "login_phone",
        #     "is_first_start": "0",
        #     "tab_name": "手机登录",
        #     "referrer_link": [""]
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", tab_name="手机登录", page_name="login_phone", button_name="login")
        AssertLen.maidiannumber(result)




    def test_08_aalogin_Page(self):
        '先逛逛按钮点击'
        ele = find_element.element(self.driver,login_Page.guangguang)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "referrer_link": [
        #         "home"
        #     ],
        #     "is_first_start": "0",
        #     "page_name": "one_click_login",
        #     "button_name": "go_to_see"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", page_name="one_click_login", button_name="go_to_see")
        AssertLen.maidiannumber(result)


    def test_09_aalogin_Page(self):
        '先逛逛popupview'
        ele = find_element.element(self.driver, login_Page.guangguang)
        ele.click()
        backtoapp.backapp(self.driver, 2)
        # "params": {
        #     "page_name": "home",
        #     "business_id": "238",
        #     "referrer": "",
        #     "popup_name": "small_popup",
        #     "referrer_link": [
        #         "home"
        #     ],
        #     "referrer_id": "",
        #     "url": "gengmei:\/\/common_webview?url=http%3A\/\/backend.igengmei.com\/\/phantom\/visual_special\/2637%3Fusepage%3Dwk"
        # },
        # "type": "popup_view",
        result = mitm_query(action="popup_view", page_name="home", popup_name="small_popup")
        AssertLen.maidiannumber(result)



    def test_10_aalogin_Page(self):
        '其他号码登录点击埋点'
        # 点击其他账号登录
        ele = find_element.element(self.driver, login_Page.another_login)
        ele.click()
        # "params": {
        #     "referrer_link": [
        #         "home"
        #     ],
        #     "is_first_start": "0",
        #     "page_name": "one_click_login",
        #     "button_name": "change_account"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button",page_name="one_click_login", button_name="change_account")
        AssertLen.maidiannumber(result)



    def test_11_aalogin_Page(self):
        '获取验证码按钮点击'
        # 点击其他账号登录
        ele = find_element.element(self.driver, login_Page.another_login)
        ele.click()
        # 点击验证码按钮
        ele = find_element.element(self.driver,login_Page.Verification_code)
        ele.click()
        backtoapp.backapp(self.driver,2)
        # "params": {
        #     "phone": "",
        #     "referrer_link": [
        #         "home",
        #         "one_click_login"
        #     ],
        #     "page_name": "login_phone",
        #     "button_name": "get_code",
        #     "is_first_start": "0"
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", page_name="login_phone", button_name="get_code")
        AssertLen.maidiannumber(result)






    def test_12_aalogin_Page(self):
        '登录页面'

        #点击其他账号登录
        ele = find_element.element(self.driver,login_Page.another_login)
        ele.click()

        # 点击账号密码登录
        ele = find_element.element(self.driver, login_Page.password_login)
        ele.click()

        # 点击账号框
        ele = find_element.element(self.driver, login_Page.click_username)
        ele.click()

        # 输入账号
        ele = find_element.element(self.driver, login_Page.sendkeys_username)
        ele.send_keys(login_Page.username)

        # 输入密码
        ele = find_element.element(self.driver, login_Page.sendkeys_password)
        ele.send_keys(login_Page.password)

        #点击立即登录按钮
        ele = find_element.element(self.driver, login_Page.login_button)
        ele.click()

        # "params": {
        #     "phone": "17601625117",
        #     "button_name": "login",
        #     "page_name": "login_password",
        #     "is_first_start": "0",
        #     "tab_name": "手机登录",
        #     "referrer_link": [
        #         "one_click_login"
        #     ]
        # },
        # "type": "on_click_button",
        result = mitm_query(action="on_click_button", phone="17601625117", button_name="login", page_name="login_password", tab_name="手机登录")
        AssertLen.maidiannumber(result)




















