Esempio n. 1
0
 def open_browser(self, browser):
     log1.info('读取浏览器配置')
     url = Config.config_read('test', 'url')
     log1.info('读取url:%s' % url)
     try:
         if browser == 0:
             abspath = os.path.abspath(r"F:\m2\chromedriver.exe")
             self.driver = webdriver.Chrome(abspath)
             log1.info('打开的浏览器为chrome')
         elif browser == 1:
             # abspath = os.path.abspath(r"F:\m2\chromedriver.exe")
             self.driver = webdriver.Firefox()
             log1.info('打开的浏览器为Firefox')
         elif browser == 2:
             # abspath = os.path.abspath(r"F:\m2\chromedriver.exe")
             self.driver = webdriver.ie()
             log1.info('打开的浏览器为ie')
         self.driver.get(url)
         self.driver.maximize_window()
         log1.info('浏览器最大化')
         self.driver.implicitly_wait(10)
         log1.info('设置静态等待时间10秒')
         return self.driver
     except BaseException:
         log1.error('浏览器打开报错')
Esempio n. 2
0
 def test_weather(self):
     '''查询天气'''
     case_name = '查询天气'
     log1.info("执行测试用例:%s" % case_name)
     try:
         weather = test_requests()  # 初始化测试基类的实例
         url = Config.config_read('weathere', 'url')  # 获取配置文件中的url
         city = Config.config_read('weathere', 'city')  # 获取配置文件中的crty
         status_code, response_json, reurl = weather.get(
             url + city)  # 调用封装的get方法,接收状态码和相应内容
         message = weather.getdict(response_json,
                                   'message')  # 调用迭代字典方法,获得message字段的值
         test1 = self.assertEqual(status_code, 200)  # 断言状态码等于200
         print(test1)
         test2 = self.assertEqual(message,
                                  'Success !')  # 断言message字段的值等于'Success !'
         print(test2)
         if test1 == None and test2 == None:  # 如果两个断言结果都等于None
             log1.info("测试通过")
     except BaseException as f:
         log1.error("测试用例执行出错: %s" % case_name, exc_info=1)
         raise
Esempio n. 3
0
 def __init__(self):
     platformName=Config.config_read('appium', 'platformName')
     deviceName=Config.config_read('appium', 'deviceName')
     platformVersion=Config.config_read('appium', 'platformVersion')
     apkpath = Config.config_read('appium', 'app')
     appPackage = Config.config_read('appium', 'appPackage')
     appActivity = Config.config_read('appium', 'appActivity')
     path = getcwd.get_cwd()
     apk_path = os.path.join(path, apkpath)
     desired_caps = {
         'platformName': platformName,
         'deviceName': deviceName,  # 手机设备名称,通过adb devices查看
         'platformVersion': platformVersion,  # android系统的版本号
         'app': apk_path,
         'appPackage': appPackage,  # apk包名
         'appActivity': appActivity,  # apk的launcherActivity
         'noRset':'true',
         'automationNname':'uiautomator2'
     }
     self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
     self.driver.implicitly_wait(3)
Esempio n. 4
0
# -*- coding: UTF-8 -*-
from Config.config import Config

#可以写入初始化数据以及浏览器引擎
section = 'selenium'
username = '******'
password = '******'

a = Config.config_read('DB', 'dbhost')

print(a)
Esempio n. 5
0
#!/usr/bin/python3
import os
import time
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
from email.mime.multipart import MIMEMultipart

import getcwd
from Config.config import Config
from Logs.log import log1

config = Config()

rq = time.strftime('%Y%m%d', time.localtime(time.time()))  # 获取本地时间 转换成日期
email = config.config_read('sender', 'email')  # 发件人邮箱账号
password = config.config_read('sender', 'password')  # 发件人邮箱密码
usernmae = config.config_read('sender', 'username')  # 发件人姓名
users = config.config_options('addressed')  # 收件人
addressed_eamils = config.get_addkey(users)  # 收件人邮箱

path = getcwd.get_cwd()
file = os.path.join(path, 'report/兰州电网PC端部分功能自动化测试报告.html')


def sent_mail():
    try:
        # 创建一个带附件的实例
        message = MIMEMultipart()
        message['From'] = formataddr([usernmae,
                                      email])  # 括号里的对应发件人邮箱昵称、发件人邮箱账号
Esempio n. 6
0
from Config.config import Config

section = 'selenium'
username = '******'
password = '******'

test = Config()

test.config_write(section)
test.config_write(section, 'username', username)
test.config_write(section, 'password', password)

get_username = test.config_read(section, 'username')
get_password = test.config_read(section, 'password')

test.config_delete(
    section,
    'usrename',
)
test.config_delete(section, 'password')
test.config_delete(section)