Skip to content

Commit

Permalink
Merge pull request #118 from hautof/dev-2.3.0
Browse files Browse the repository at this point in the history
add selenium web ui case support
  • Loading branch information
tsbxmw authored Mar 14, 2019
2 parents d32c87c + 6ce55b4 commit 05f03ef
Show file tree
Hide file tree
Showing 9 changed files with 450 additions and 16 deletions.
31 changes: 30 additions & 1 deletion haf/bench.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# encoding='utf-8'
from haf.common.database import SQLConfig
from haf.case import HttpApiCase, AppCase
from haf.case import HttpApiCase, AppCase, WebCase


class BaseBench(object):
Expand Down Expand Up @@ -66,5 +66,34 @@ def update_case(self, case: AppCase):
def get_case(self, key: str):
return self.cases.get(key, None)

def get_db(self, key: str):
return self.dbs.get(key, None)


class WebBench(BaseBench):
def __init__(self):
super().__init__()
self.name = None
self._init_all()

def _init_all(self):
self.cases = {}
self.dbs = {}

def add_case(self, case: WebCase):
key = f"{case.ids.id}.{case.ids.subid}.{case.ids.name}"
self.cases.update({key: case})

def add_db(self, db: SQLConfig):
key_db = str(db.id)
self.dbs.update({key_db: db})

def update_case(self, case: WebCase):
key = f"{case.ids.id}.{case.ids.subid}.{case.ids.name}"
self.cases.update({key: case})

def get_case(self, key: str):
return self.cases.get(key, None)

def get_db(self, key: str):
return self.dbs.get(key, None)
69 changes: 69 additions & 0 deletions haf/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from haf.apphelper import Stage, AppIds, DesiredCaps
from haf.config import *
from haf.common.log import Log
from haf.webhelper import *

logger = Log.getLogger(__name__)

Expand Down Expand Up @@ -224,3 +225,71 @@ def deserialize(self):
"sleep": self.time_sleep,
"wait_activity": self.wait_activity
}


class WebCase(BaseCase):
def __init__(self):
super().__init__()
self.mark = CASE_MARK_WEB
self.type = CASE_TYPE_WEBUI
self.message_type = MESSAGE_TYPE_CASE
self.log_key = ""
self._init_all()

def _init_all(self):
self.ids = WebIds()
self.run = CASE_RUN
self.dependent = []
self.bench_name = ""
self.stages = {}
self.log_key = ""
self.wait_activity = ""
self.desired_caps = WebDesiredCaps()
self.error = None
self.sqlinfo = SqlInfo()
self.time_sleep = 5
self.pngs = {}

def constructor(self, *args, **kwargs):
'''
:param args:
:param kwargs:
:return:
'''
args_init = {}
if len(args) > 0 and isinstance(args[0], dict):
args_init = args[0]
else:
args_init = kwargs
self.ids.constructor(args_init)
self.time_sleep = args_init.get("wait_time") or 5
self.run = CASE_RUN if args_init.get("run") is True else CASE_SKIP
self.dependent = [x for x in str(args_init.get("dependent")).split(";") if args_init.get("dependent") is not None]
self.desired_caps.constructor(args_init.get("desired_caps"))
self.stages = {}
self.wait_activity = args_init.get("wait_activity", None)
for s in args_init.get("stage"):
stage = WebStage()
stage.constructor(s)
self.stages[stage.id] = stage

def bind_bench(self, bench_name):
self.bench_name = bench_name
self.generate_log_key()

def generate_log_key(self):
self.log_key = self.key = f"{self.bench_name}$%{self.ids.id}.{self.ids.subid}.{self.ids.name}$%"

def deserialize(self):
return {
"ids": self.ids.deserialize(),
"run": self.run,
"dependent": self.dependent,
"bench_name": self.bench_name,
"stage": [stage.deserialize() for stage in self.stages.values()],
"type": self.type,
"desired_caps": self.desired_caps.deserialize(),
"pngs": self.pngs,
"sleep": self.time_sleep,
"wait_activity": self.wait_activity
}
21 changes: 20 additions & 1 deletion haf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,30 @@
OPERATION_APP_OTHER: "other"
}

OPERATION_WEB_CLICK = 80
OPERATION_WEB_SENDKEYS = 81
OPERATION_WEB_SWIPE = 82
OPERATION_WEB_OTHER = 83

OPERATION_WEB_GROUP = {
"click": OPERATION_WEB_CLICK,
"swipe": OPERATION_WEB_SWIPE,
"send_keys": OPERATION_WEB_SENDKEYS,
"other": OPERATION_WEB_OTHER
}

OPERATION_WEB_ANTI_GROUP = {
OPERATION_WEB_CLICK: "click",
OPERATION_WEB_SWIPE: "swipe",
OPERATION_WEB_SENDKEYS: "send_keys",
OPERATION_WEB_OTHER: "other"
}

LOG_PATH_DEFAULT = "D:\workspace\mine\python\haf\data"

MAIN_VERSION = 2
SUB_VERSION = 6
FIX_VERSION = 1
FIX_VERSION = 2
VERSION_TYPE = "haf"
PLATFORM_VERSION = f"{VERSION_TYPE}-{MAIN_VERSION}.{SUB_VERSION}.{FIX_VERSION}"

Expand Down
2 changes: 1 addition & 1 deletion haf/ext/jinjia2report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_template_customer(path_: str) -> None:
def get_template(key: str) -> None:
if key == "base" or key == "online":
template = "base.html"
elif key == "online-app" or key == "base_app":
elif key in ["online-app", "base_app", "online-web", "base_web"]:
template = "base_app.html"
elif key == "base_email":
template = "base_email.html"
Expand Down
6 changes: 4 additions & 2 deletions haf/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from haf.bench import HttpApiBench
from haf.busclient import BusClient
from haf.common.database import SQLConfig
from haf.case import HttpApiCase, PyCase, AppCase
from haf.case import HttpApiCase, PyCase, AppCase, WebCase
from haf.common.exception import FailLoaderException
from haf.common.log import Log
from haf.config import *
Expand Down Expand Up @@ -70,8 +70,10 @@ def run(self):
input["host_port"] = inputs.get("config")[0].get("host_port")
if "api_name" in input.keys():
case = HttpApiCase()
elif "stage" in input.keys():
elif input.get("type") == "app":
case = AppCase()
elif input.get("type") == "web":
case = WebCase()
else:
case = PyCase(module_name, module_path)
try:
Expand Down
8 changes: 4 additions & 4 deletions haf/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from multiprocessing import Process

from haf.busclient import BusClient
from haf.case import HttpApiCase, BaseCase, PyCase
from haf.case import HttpApiCase, BaseCase, PyCase, WebCase, AppCase
from haf.common.database import SQLConfig
from haf.common.exception import FailRecorderException
from haf.common.log import Log
from haf.result import HttpApiResult, EndResult, Detail, Summary, AppResult
from haf.result import HttpApiResult, EndResult, Detail, Summary, AppResult, WebResult
from haf.config import *
from haf.utils import Utils
from haf.ext.jinjia2report.report import Jinja2Report
Expand Down Expand Up @@ -62,8 +62,8 @@ def run(self):
while True:
if not self.results_handler.empty() :
result = self.results_handler.get()
if isinstance(result, HttpApiResult) or isinstance(result, AppResult):
if isinstance(result.case, HttpApiCase) or isinstance(result.case, BaseCase) or isinstance(result.case, PyCase):
if isinstance(result, (HttpApiResult, AppResult, WebResult)):
if isinstance(result.case, (HttpApiCase, BaseCase, PyCase, WebCase, AppCase)):
logger.info(f"{self.recorder_key} recorder--{result.case.bench_name}.{result.case.ids.id}.{result.case.ids.subid}.{result.case.ids.name} is {result.result}")
else:
logger.info(f"{self.recorder_key} recorder ! wrong result!")
Expand Down
40 changes: 40 additions & 0 deletions haf/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,46 @@ def deserialize(self):
}


class WebResult(BaseResult):
def __init__(self):
super().__init__()
self.message_type = MESSAGE_TYPE_RESULT
self._init_all()

def _init_all(self):
self.case = None
self.run_error = None
self.result = False
self.begin_time = None
self.end_time = None
self.log_dir = ""
self.runner = ""
self.pngs = {}

def on_case_begin(self):
self.begin_time = Utils.get_datetime_now()

def on_case_end(self):
self.end_time = Utils.get_datetime_now()
self.duration = Utils.get_date_result(self.begin_time, self.end_time)

def bind_runner(self, runner:int=0):
self.runner = runner

def deserialize(self):
return {
"case_name": f"{self.case.ids.id}.{self.case.ids.subid}.{self.case.ids.name}",
"run_error": self.run_error,
"result": RESULT_GROUP.get(str(self.result)),
"begin_time": self.begin_time,
"end_time": self.end_time,
"case": self.case.deserialize(),
"log_dir": self.log_dir,
"runner": self.runner,
"pngs": self.pngs
}


class Detail(object):
def __init__(self, suite_name):
self.suite_name = suite_name
Expand Down
Loading

0 comments on commit 05f03ef

Please sign in to comment.