
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from appium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
def element(driver, Element):

    for by, value, times in Element:

        try:
            # 添加显示等待
            wait = WebDriverWait(driver, times, 0.5)
            ele = wait.until(EC.presence_of_element_located((by, value)), message="元素未能找到")

        except:
            continue
        else:
            return ele
    else:
        raise NoSuchElementException('元素未能找到！')



def ElementNotAssert(driver, Element):

    for by, value, times in Element:

        try:
            # 添加显示等待
            wait = WebDriverWait(driver, times, 0.5)
            ele = wait.until(EC.presence_of_element_located((by, value)), message="元素未能找到")
            ele.click()
            break
        except:
            pass

def notnull(key):
    for i in key:
        print("局部参数值：%s"%i)
        if i in ["", None]:
            raise Exception(i, "局部参数值存在为空")
        else:

            print("局部参数值正常: %s" %i)


def AssertExpect(expect, actual):
    assert expect == actual, "该埋点上报与预期不符 %s != %s" %(expect, actual)


def AssertParameter(Parameter1, Parameter2):
    if Parameter1 in Parameter2:
        pass
    else:
        raise Exception("%s 参数有问题" % Parameter1)

