Skip to content

Commit

Permalink
Merge pull request #157 from hautof/dev-3.0.0
Browse files Browse the repository at this point in the history
add docs to haf, fix some bugs of -nout -llog -debug, make haf running…
  • Loading branch information
tsbxmw authored Apr 17, 2019
2 parents b06f087 + cd475a3 commit 11c874f
Show file tree
Hide file tree
Showing 31 changed files with 1,155 additions and 156 deletions.
7 changes: 7 additions & 0 deletions haf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import pluggy

'''
file name : __init__
description : the haf init
others :
define the hookimpl by pluggy
'''


hookimpl = pluggy.HookimplMarker("haf")
71 changes: 70 additions & 1 deletion haf/apihelper.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# encoding='utf-8'

'''
file name : apihelper
description : the api case helper
others:
include request, response ...
'''
import json
from haf.common.database import SQLConfig
from haf.config import *


class Request(object):
'''
Request object of api request
'''
def __init__(self):
self.header = {}
self.data = {}
Expand All @@ -16,6 +24,11 @@ def __init__(self):
self.url_part = ""

def constructor(self, inputs: dict={}):
'''
constructor the Request by dict type
:param inputs:
:return:
'''
header = inputs.get("request_header")
self.header = json.loads(header) if isinstance(header, str) else header
data = inputs.get("request_data")
Expand All @@ -33,6 +46,10 @@ def constructor(self, inputs: dict={}):
self.url = f"{self.protocol}://{self.host_port}{self.url_part}"

def deserialize(self):
'''
return the dict type
:return:
'''
flag = False
try:
data = json.dumps(self.data, indent=4)
Expand All @@ -51,17 +68,29 @@ def deserialize(self):


class Response(object):
'''
Response
'''
def __init__(self):
self.header = {}
self.body = {}
self.code = ""

def constructor(self, inputs:dict={}):
'''
:param inputs:
:return:
'''
self.header = inputs.get("header", {})
self.body = inputs.get("body", {})
self.code = inputs.get("code", {})

def deserialize(self):
'''
:return:
'''
flag = False
try:
body = json.dumps(self.body, indent=4)
Expand All @@ -81,19 +110,31 @@ def deserialize(self):


class Ids(object):
'''
api ids
'''
def __init__(self):
self.id = ""
self.subid = ""
self.name = ""
self.api_name = ""

def constructor(self, inputs:dict={}):
'''
:param inputs:
:return:
'''
self.id = inputs.get("id")
self.subid = inputs.get("subid")
self.name = inputs.get("name")
self.api_name = inputs.get("api_name")

def deserialize(self):
'''
:return:
'''
return {
"id": self.id,
"subid": self.subid,
Expand All @@ -103,6 +144,9 @@ def deserialize(self):


class SqlInfo(object):
'''
sql info of api
'''
def __init__(self):
self.scripts = {}
self.config = None
Expand All @@ -111,6 +155,11 @@ def __init__(self):
self.check_list = {}

def constructor(self, inputs:dict={}):
'''
:param inputs:
:return:
'''
sql_response = inputs.get("sql_response")
if ";" in sql_response:
self.scripts["sql_response"] = sql_response.split(";")
Expand All @@ -128,9 +177,17 @@ def constructor(self, inputs:dict={}):
self.config_id = str(inputs.get("sql_config")) if inputs.get("sql_config") is not None else ""

def bind_config(self, config:SQLConfig):
'''
bind sql config
:param config:
:return:
'''
self.config = config

def deserialize(self):
'''
:return:
'''
return {
"scripts": self.scripts,
"config": self.config.deserialize() if self.config is not None else None,
Expand All @@ -140,12 +197,20 @@ def deserialize(self):


class Expect(object):
'''
expect of api
'''
def __init__(self):
self.response = Response()
self.sql_check_func = ""
self.sql_response_result = {}

def constructor(self, inputs:dict={}):
'''
:param inputs:
:return:
'''
body = inputs.get("expect_response")
self.response.body = json.loads(body) if isinstance(body, str) else body
sql_check_func = inputs.get("expect_sql")
Expand All @@ -155,6 +220,10 @@ def constructor(self, inputs:dict={}):
self.sql_check_func = sql_check_func.rsplit('.', 2)

def deserialize(self):
'''
:return:
'''
return {
"response": self.response.deserialize(),
"sql_check_func": str(self.sql_check_func),
Expand Down
52 changes: 52 additions & 0 deletions haf/apphelper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# -*- coding: utf-8 -*-
'''
file name : apphelper
description : the app case helper
others:
include BasePage
'''
import time, os
from haf.config import *


class BasePage:
'''
the base page of app pages, can be implement by cases
'''
DEFAULT_TIMEOUT = 3

def __init__(self, driver):
Expand Down Expand Up @@ -73,6 +82,9 @@ class By(object):


class Stage(object):
'''
stage of app test
'''
def __init__(self):
self.id = 0
self.name = ""
Expand All @@ -85,6 +97,11 @@ def __init__(self):
self.run_count = 0

def constructor(self, input: dict={}):
'''
:param input:
:return:
'''
self.id = input.get("id")
self.name = input.get("name")
self.operation = OPERATION_APP_GROUP[input.get("operation")]
Expand All @@ -95,6 +112,10 @@ def constructor(self, input: dict={}):
self.run_count = input.get("run_count")

def deserialize(self):
'''
:return:
'''
return {
"id": self.id,
"name": self.name,
Expand All @@ -109,19 +130,31 @@ def deserialize(self):


class AppIds(object):
'''
ids of app
'''
def __init__(self):
self.id = ""
self.subid = ""
self.name = ""
self.app_name = ""

def constructor(self, inputs:dict={}):
'''
:param inputs:
:return:
'''
self.id = inputs.get("id")
self.subid = inputs.get("subid")
self.name = inputs.get("name")
self.app_name = inputs.get("app_name")

def deserialize(self):
'''
:return:
'''
return {
"id": self.id,
"subid": self.subid,
Expand All @@ -131,6 +164,9 @@ def deserialize(self):


class DesiredCaps(object):
'''
desired caps needed by appium
'''
def __init__(self):
self.automationName = ""
self.platformName = ""
Expand All @@ -141,6 +177,11 @@ def __init__(self):
self.noReset = True

def constructor(self, inputs: dict={}):
'''
:param inputs:
:return:
'''
self.automationName = inputs.get("automationName")
self.platformName = inputs.get("platformName")
self.platformVersion = inputs.get("platformVersion")
Expand All @@ -150,6 +191,10 @@ def constructor(self, inputs: dict={}):
self.noReset = inputs.get("noReset", True)

def deserialize(self):
'''
:return:
'''
return {
"automationName": self.automationName,
"platformName": self.platformName,
Expand All @@ -162,6 +207,13 @@ def deserialize(self):


def save_screen_shot(driver, path, name):
'''
save the screen shot to the path of the name
:param driver:
:param path:
:param name:
:return:
'''
try:
path = f"{path}/png"
if not os.path.exists(path):
Expand Down
10 changes: 10 additions & 0 deletions haf/asserthelper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# encoding='utf-8'
'''
file name : asserthelper
description : rewrite assert
others:
include AssertHelper
now not use this
'''
from datetime import datetime

from assertpy import assert_that
Expand All @@ -8,6 +15,9 @@
logger = Log.getLogger(__name__)


#TODO: here need extend


class AssertHelper(object):
@staticmethod
def assert_that(real, expect, **kwargs):
Expand Down
Loading

0 comments on commit 11c874f

Please sign in to comment.