Skip to content

Commit

Permalink
Merge pull request #83 from tsbxmw/dev-2.3.0
Browse files Browse the repository at this point in the history
release 2.3.3
  • Loading branch information
tsbxmw authored Feb 13, 2019
2 parents 16691dd + c3815a9 commit 076977a
Show file tree
Hide file tree
Showing 16 changed files with 1,885 additions and 27 deletions.
24 changes: 24 additions & 0 deletions docs/design.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# Future Design

## appium support

- includ appium command
- android support
- ios support
- report support png show

## selenium support

- webdriver support

## pytest support

- pytest

## management

- web management
- case edit/add/delete/management
- result show/analysis/generate


# HAF Framework

![map](https://raw.githubusercontent.com/tsbxmw/haf/master/docs/png/HAF-2.0.0.png)
Expand Down
8 changes: 8 additions & 0 deletions docs/releasenote.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
> version 2.3.1
- fix bug of 2.3.0 : no suite found

> version 2.3.0
- add response info of report when case run error

> version 2.2.9
- add result publish to mysql database
Expand Down
166 changes: 166 additions & 0 deletions haf/apphelper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# -*- coding: utf-8 -*-
import time, os
from haf.config import *


class BasePage:
DEFAULT_TIMEOUT = 3

def __init__(self, driver):
self.driver = driver

def find_element(self, key, value):
if key == "id":
ele = self.driver.find_element_by_id(value)
elif key == "name":
ele = self.driver.find_element_by_name(value)
elif key == "xpath":
ele = self.driver.find_element_by_xpath(value)
else:
ele = self.driver.find_element(key, value)
return ele

def find_element_by_locator(self, locators):
for key in locators.keys():
try:
return self.find_element(key, locators.get(key))
except Exception as e:
print(e)

def click(self, name):
e = self.find_element_by_locator(name)
e.click()

def send_keys(self, name, keys):
e = self.find_element_by_locator(name)
e.clear()
e.send_keys(keys)

def ele_exists(self, name):
try:
e = self.find_element_by_locator(name)
return True
except Exception as e:
return False

def swipe(self, d):
if d == "left":
self.driver.swipe(50, 1400, 800, 1400, 1000)

if d == "right":
self.driver.swipe(800, 1400, 50, 1400, 1000)

if d == "up":
self.driver.swipe(500, 50, 500, 1400, 1000)

if d == "down":
self.driver.swipe(500, 1400, 500, 50, 1000)


class By(object):
"""
Set of supported locator strategies.
"""

ID = "id"
NAME = "name"
XPATH = "xpath"

LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
TAG_NAME = "tag name"
CLASS_NAME = "class name"


class Stage(object):
def __init__(self):
self.id = 0
self.name = ""
self.operation = ""
self.path = ""
self.show_try = True
self.info = {}

def constructor(self, input: dict={}):
self.id = input.get("id")
self.name = input.get("name")
self.operation = OPERATION_APP_GROUP[input.get("operation")]
self.path = input.get("path")
self.show_try = input.get("try")
self.info = input.get("info")

def deserialize(self):
return {
"id": self.id,
"name": self.name,
"operation": self.operation,
"path": self.path,
"show_try": self.show_try,
"info": self.info
}


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

def constructor(self, inputs:dict={}):
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 {
"id": self.id,
"subid": self.subid,
"name": self.name,
"api_name": self.app_name
}


class DesiredCaps(object):
def __init__(self):
self.automationName = ""
self.platformName = ""
self.platformVersion = ""
self.deviceName = ""
self.appPackage = ""
self.appActivity = ""
self.noReset = True

def constructor(self, inputs: dict={}):
self.automationName = inputs.get("automationName")
self.platformName = inputs.get("platformName")
self.platformVersion = inputs.get("platformVersion")
self.deviceName = inputs.get("deviceName")
self.appPackage = inputs.get("appPackage")
self.appActivity = inputs.get("appActivity")
self.noReset = inputs.get("noReset", True)

def deserialize(self):
return {
"automationName": self.automationName,
"platformName": self.platformName,
"platformVersion": self.platformVersion,
"deviceName": self.deviceName,
"appPackage": self.appPackage,
"appActivity": self.appActivity,
"noReset": self.noReset
}


def save_screen_shot(driver, path, name):
try:
path = f"{path}/png"
if not os.path.exists(path):
os.mkdir(path)
path_full = f"{path}/{name}.png"
driver.save_screenshot(path_full)
return path_full
except Exception as e:
print(e)
return e
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
from haf.case import HttpApiCase, AppCase


class BaseBench(object):
Expand Down Expand Up @@ -38,4 +38,33 @@ 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 AppBench(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: AppCase):
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: AppCase):
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)
67 changes: 66 additions & 1 deletion haf/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json

from haf.apihelper import Request, Response, Ids, Expect, SqlInfo
from haf.apphelper import Stage, AppIds, DesiredCaps
from haf.config import *
from haf.common.log import Log

Expand Down Expand Up @@ -154,4 +155,68 @@ def deserialize(self):
"expect": self.expect.deserialize(),
"sqlinfo": self.sqlinfo.deserialize(),
"type": self.type
}
}


class AppCase(BaseCase):
def __init__(self):
super().__init__()
self.mark = CASE_MARK_APP
self.type = CASE_TYPE_APP
self.message_type = MESSAGE_TYPE_CASE
self.log_key = ""
self._init_all()

def _init_all(self):
self.ids = AppIds()
self.run = CASE_RUN
self.dependent = []
self.bench_name = ""
self.stages = {}
self.log_key = ""
self.desired_caps = DesiredCaps()
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("sleep") 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 = {}
for s in args_init.get("stage"):
stage = Stage()
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
}
Loading

0 comments on commit 076977a

Please sign in to comment.