import pytest import time from util.command import Command from util.Base import Base from config.setting import Setting #文件路径类 from util.log import logger, insert_log #https://coding.net/u/tsbc/p/PySelenium_PO import sys set = Setting() cmd = Command() log = logger("TestIndexWeb") class TestIndexWeb(Base): #大量用到所以用继承 """ pageobject 首个页面 """ flag = 3 #状态机 base_url = "https://www.ctrip.com/" def setup_class(self): if not self.excel_close(): log.info("Excel数据未关闭") raise Exception("Excel数据未关闭") try: self.driver = cmd.start_brower(self.base_url) except Exception as err: print(format(err)) def teardown_class(self):
from selenium import webdriver import os, time, unittest, configparser from util import Err from util import log _logger = log.logger('LoginTesterHome') currentPath = os.path.abspath(os.path.dirname(__file__)) # 当前文件夹目录 ProjectPath = os.path.split(currentPath)[0] # 取下标 toolsPath = ProjectPath.replace("\\", "/") + "/driver/chromedriver" def path_ini(): pathobj = os.path.abspath(os.path.join( os.path.dirname(__file__), "..")) + "\\Conf\\config.ini" # + "../config" + "/config.ini" return pathobj def get_ini_date(sections, item): """关键字驱动 :param sections: ini类型文件.sections :param item: get.item =>value :return: str """ try: iniconf = path_ini() # 读取全局变量拼装文件 conf = configparser.ConfigParser() conf.read(iniconf, encoding="utf-8") return conf.get(sections, item) except Exception as error:
# coding:utf-8 import json import os from util import log from util.analysis_tracefile import TraceDump, sortInclThreadCost logger = log.logger() class TraceHandler(object): def __init__(self, trace_path, mapping_path=None, convert_jar=None, mode="exclusive"): """traceview解析的工具类 :params convert_jar: convert_jar文件 :params trace_path: traceview文件 :params trace_root: traceview文件所在路径 :params trace_name: traceview文件的名字 :params mapping_path: mapping文件路径 :params out_path: traceview反混淆文件输出的路径 """ self.trace_dump = TraceDump() self.convert_jar = convert_jar self.trace_path = trace_path self.trace_root, self.trace_name = os.path.split(trace_path) self.mapping_path = mapping_path self.mode = mode self.analysis_results = None
try: from util.ClientSelenium import ClientSelenium from util.ParserConfig import ParserConfig from Conf.setting import * from Conf1.setting import * #导入的是Conf模块文件夹下面的setting里面所有内容,setting.py的内容可以直接使用 except ImportError as error: print(error) commond = ClientSelenium() pc = ParserConfig("D:\selenium_uses\Conf\config.ini") from util import log _logger = log.logger('Baidu_Api') class Baidu_Api(unittest.TestCase): @classmethod def setUpClass(cls): cls.driver = commond.get_driver("chrome", "https://www.baidu.com") log._logger.info("启动浏览器") commond.time_sleep(3) @classmethod def tearDownClass(cls): log._logger.info("执行,关闭浏览器") commond.quit() #条件满足则不会跳过 #@unittest.skipIf(exe_or_not['assert_title'],'判断assert_title:%s'%exe_or_not['assert_title']) def test_a_Tittle(self):
from selenium import webdriver import os, time, unittest, configparser from selenium.webdriver.common.action_chains import ActionChains from util import log _log = log.logger('Testerhome') # from util.ClientSelenium import * # client = ClientSelenium() class LoginDouban(unittest.TestCase): @classmethod def setUpClass(cls): # 每轮执行case的开始 # client.get_driver("f", "https://www.douban.com") cls.driver = webdriver.Firefox() cls.driver.get("https://www.douban.com") cls.driver.implicitly_wait(5) # 隐式等待5s cls.driver.get_screenshot_as_file( r"D:\sdk\tools\web_Auto\pic\browser.png") _log.info("成功打开浏览器!") @classmethod def tearDownClass(cls): # 每轮执行case的结束 print("this is the end!") _log.info("关闭浏览器!") cls.driver.quit() # 保护代码 def test_login(self): time.sleep(4)
from selenium import webdriver from time import sleep from selenium.webdriver.common.keys import Keys import unittest #添加断言 from util import log _log = log.logger("WebTest") class LoginBaidu(unittest.TestCase): def test_login(self): self.driver = webdriver.Chrome() self.driver.get("https://www.baidu.com") self.driver.maximize_window() _log.info("open!") self.driver.find_element_by_css_selector("#u1 > a.lb").click() sleep(2) #添加等待时间,等待弹窗展示 # # a = self.driver.find_element_by_class_name("pass-form-logo").text #登录弹窗展示,不能获取文本信息 # self.assertEqual("扫码登录",a,msg="当前弹窗应为{},实际为{}".format("扫码登录",a)) # sleep(1) # self.driver.find_element_by_id( "TANGRAM__PSP_10__footerULoginBtn").click() #用户名密码登录 self.driver.find_element_by_id("TANGRAM__PSP_10__userName").clear()
# coding:utf-8 import collections import csv import os from util.log import logger logger = logger() class Template(object): def __init__(self, base_dic, cmp_dic, base_cost, cmp_cost, base_call_times, cmp_call_times, base_method_thread, cmp_method_thread, base_theads_pid, cmp_theads_pid): self.base = base_dic # base_sorted_dic, cmp_sorted_dic, base_cost, cmp_cost,base_call_times,cmp_call_times self.cmp = cmp_dic self.base_cost = base_cost self.cmp_cost = cmp_cost self.base_call_times = base_call_times self.cmp_call_times = cmp_call_times self.order_base_dic = collections.OrderedDict() self.order_cmp_dic = collections.OrderedDict() self.order_base_keys, self.order_base_values = self.initObjDatas( self.base, self.order_base_dic) self.order_cmp_keys, self.order_cmp_values = self.initObjDatas( self.cmp, self.order_cmp_dic) self.base_method_thread = base_method_thread self.cmp_method_thread = cmp_method_thread self.base_theads_pid = base_theads_pid self.cmp_theads_pid = cmp_theads_pid
# -*- coding: utf-8 -*- 'a practice of ...' import time,os from selenium.common.exceptions import NoSuchElementException from selenium import webdriver import unittest import configparser from util.ClientSelenium import ClientSelenium from util import log _logger = log.logger('TiamMaoMethods') def path_ini(): path_ini = os.path.abspath(os.path.dirname(__file__)) + "/../Conf" + "/config.ini" return path_ini def get_ini_date(sections, item): """关键字驱动 :param sections: ini类型文件.sections :param item: get.item =>value :return: str """ try: iniconf = path_ini() # 读取全局变量拼装文件 conf = configparser.ConfigParser() conf.read(iniconf, encoding="utf-8") except NoSuchElementException as error: raise (error) return conf.get(sections.lower(), item.lower()) # ini那头全部写成小写,加这句配置大小写填错也无所谓