Пример #1
0
def get_elem(login_elem_data, elem_name):
    elems_info = PubMethod.read_yaml(login_elem_data)
    print(elems_info)
    for item in elems_info["parameters"]:
        if item["elem_name"] == elem_name:
            elem_locator = ("By.{}".format(item["data"]["method"]),
                            item["data"]["value"])
            method = item["data"]["method"]
            value = item["data"]["value"]
            logging.info("元素定位方式为:{},元素对象值为:{}".format(method, value))
            if method == "ID" and value is not None:
                return elem_locator
            elif method == "XPATH" and value is not None:
                return elem_locator
            elif method == "LINK_TEXT" and value is not None:
                return elem_locator
            elif method == "PARTIAL_LINK_TEXT" and value is not None:
                return elem_locator
            elif method == "NAME" and value is not None:
                return elem_locator
            elif method == "TAG_NAME" and value is not None:
                return elem_locator
            elif method == "CLASS_NAME" and value is not None:
                return elem_locator
            elif method == "CSS_SELECTOR" and value is not None:
                return elem_locator
            else:
                logging.error("该定位方式异常,定位元素值异常,请检查!!!")
Пример #2
0
    def get_login_url_from_config(self):
        """

        @return: 配置文件URL
        """
        config_info = PubMethod.read_yaml(conf_path)
        print("config_info地址:{}".format(config_info))
        return config_info["test_info"]["test_URL"]
Пример #3
0
# @File    : conftest.py
# @Software: PyCharm
import os
import pytest
import logging
from selenium import webdriver
from selenium.webdriver import Remote
from Common.publicMethod import PubMethod
from selenium.webdriver.chrome.options import Options as CO
from selenium.webdriver.firefox.options import Options as FO
from selenium.webdriver.ie.options import Options as IEO
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile as FP

# 读取selenium分布式配置文件
selenium_config_path = os.path.join(os.path.dirname(__file__), "Conf", "selenium_config.yaml")
selenium_config = PubMethod.read_yaml(selenium_config_path)


def pytest_addoption(parser):
    """
    定义钩子函数hook进行命令行定义浏览器传参,默认chrome,定义浏览器启动方式传参,默认启动
    @param parser:
    @return:
    """
    # 浏览器选项
    parser.addoption("--browser", action="store", default="chrome", help="browser option: firefox or chrome or ie")
    # 是否开启浏览器界面选项
    parser.addoption("--browser_opt", action="store", default="open", help="browser GUI open or close")
    # driver选项,本地还是远程模式
    parser.addoption("--type_driver", action="store", default="local", help="type of driver: local or remote")
Пример #4
0
@Time    : 2020/4/2 14:00
@Auth    : wrc
@Email   : [email protected]
@File    : Log.py
@IDE     : PyCharm
------------------------------------
"""
import logging
import logging.config
from os import path

from Common.publicMethod import PubMethod as pub_api

logger_config_path = path.dirname(__file__)
logging.config.dictConfig(
    pub_api.read_yaml(path.join(logger_config_path, 'logging.config.yml')))


class MyLog:
    def __init__(self):
        self.logger = logging.getLogger('mylogger')

    def __console(self, level, message):
        level = level.upper()
        if level == 'INFO':
            self.logger.info(message)
        elif level == 'DEBUG':
            self.logger.debug(message)
        elif level == 'WARNING':
            self.logger.warning(message)
        elif level == 'ERROR':
Пример #5
0
# !/user/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/5/12 21:11
# @Author  : chineseluo
# @Email   : [email protected]
# @File    : run.py
# @Software: PyCharm
import os
import sys
import json
import logging
import pytest
from Common.publicMethod import PubMethod

root_dir = os.path.dirname(__file__)
config_yaml = PubMethod.read_yaml("./Conf/config.yaml")


def modify_report_environment_file(report_widgets_dir):
    """
    向environment.json文件添加测试环境配置,展现在allure测试报告中
    @return:
    """
    environment_info = [{
        "name": '测试地址',
        "values": [config_yaml['allure_environment']['URL']]
    }, {
        "name":
        '测试版本号',
        "values": [config_yaml['allure_environment']["version"]]
    }, {
Пример #6
0
        @param locator: 定位器
        @return: 返回placeholder属性值
        """
        elem = self.find_element(locator)
        try:
            elem_placeholder_text = elem.get_attribute("placeholder")
            logging.info("该元素对象获取placeholder成功,placeholder值为:{}".format(
                elem_placeholder_text))
        except Exception as e:
            logging.error("该元素对象获取placeholder失败,错误信息为:{}".format(e))
        return elem_placeholder_text

    def check_select_is_existence(self, locator):
        """

        @param locator: 定位器
        @return: 返回TRUE、FALSE
        """
        try:
            elem = self.find_element(locator)
            return True
        except Exception as e:
            return False


if __name__ == "__main__":
    print(conf_path)
    config_info = PubMethod.read_yaml(conf_path)
    print(config_info["test_info"])
Пример #7
0
# -*- coding: utf-8 -*-
# @Time    : 2020/5/27 9:15
# @Author  : luozhongwen
# @Email   : [email protected]
# @File    : conftest.py
# @Software: PyCharm
import os
import pytest
import logging
from appium import webdriver
from Common.publicMethod import PubMethod

appium_config_path = os.path.join(os.path.dirname(__file__), "Conf", "appium_config.yaml")
appium_config = PubMethod.read_yaml(appium_config_path)["appium_config"]


# 定义钩子函数hook进行测试用例name和_nodeid输出
def pytest_collection_modifyitems(items):
    for item in items:
        item.name = item.name.encode("utf-8").decode("unicode_escape")
        print(item)
        logging.info(item.name)
        item._nodeid = item._nodeid.encode("utf-8").decode("unicode_escape")
        logging.info(item._nodeid)


# 定义钩子函数hook实现ios和android系统测试切换
def pytest_addoption(parser):
    parser.addoption("--mobile_system", action="store", default="android", help="choose system version, android or ios")

Пример #8
0
import imaplib
import json
import time
import sys
import re
import os
import email
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.parser import Parser
from Common.publicMethod import PubMethod
from imapclient import IMAPClient

config_path = os.path.join(os.path.dirname(__file__).split("Common")[0], "Conf/config.yaml")
config_yaml = PubMethod.read_yaml(config_path)
email_info = config_yaml["mail_info"]


class Mail:

    def rec_email(self, sender, pattern):
        """
        根据正则表达式匹配邮件中想要的内容,车载项目在注册确认链接正则(r'<a href="(.*?)"')返回列表中
        第二个元素, 不存在的返回None, 只接收最新的一封邮件
        :param sender: 查找从哪个发件人发送的当天邮件
        :param pattern: 正则表达式
        :return: 返回符合正则表达式的列表
        """
        today_s = str(time.strftime("%d-%b-%Y"))
        server = IMAPClient(host=email_info["imap_server"], ssl=True)