Skip to content

Commit

Permalink
Merge pull request #87 from tsbxmw/dev-2.3.0
Browse files Browse the repository at this point in the history
release 2.4.3
  • Loading branch information
tsbxmw authored Feb 18, 2019
2 parents 72eae54 + c59d502 commit 5d82856
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 27 deletions.
5 changes: 4 additions & 1 deletion haf/apphelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(self):
self.operation = ""
self.path = ""
self.show_try = True
self.time_sleep = 5
self.info = {}

def constructor(self, input: dict={}):
Expand All @@ -88,6 +89,7 @@ def constructor(self, input: dict={}):
self.path = input.get("path")
self.show_try = input.get("try")
self.info = input.get("info")
self.time_sleep = input.get("sleep")

def deserialize(self):
return {
Expand All @@ -96,7 +98,8 @@ def deserialize(self):
"operation": self.operation,
"path": self.path,
"show_try": self.show_try,
"info": self.info
"info": self.info,
"time_sleep": self.time_sleep
}


Expand Down
8 changes: 6 additions & 2 deletions haf/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def _init_all(self):
self.bench_name = ""
self.stages = {}
self.log_key = ""
self.wait_activity = ""
self.desired_caps = DesiredCaps()
self.error = None
self.sqlinfo = SqlInfo()
Expand All @@ -192,11 +193,12 @@ def constructor(self, *args, **kwargs):
else:
args_init = kwargs
self.ids.constructor(args_init)
self.time_sleep = args_init.get("sleep") or 5
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 = Stage()
stage.constructor(s)
Expand All @@ -218,5 +220,7 @@ def deserialize(self):
"stage": [stage.deserialize() for stage in self.stages.values()],
"type": self.type,
"desired_caps": self.desired_caps.deserialize(),
"pngs": self.pngs
"pngs": self.pngs,
"sleep": self.time_sleep,
"wait_activity": self.wait_activity
}
2 changes: 1 addition & 1 deletion haf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
LOG_PATH_DEFAULT = "D:\workspace\mine\python\haf\data"

MAIN_VERSION = 2
SUB_VERSION = 3
SUB_VERSION = 4
FIX_VERSION = 3
VERSION_TYPE = "dev"
PLATFORM_VERSION = f"{VERSION_TYPE}-{MAIN_VERSION}.{SUB_VERSION}.{FIX_VERSION}"
Expand Down
20 changes: 10 additions & 10 deletions haf/ext/resource/report/base_app.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@
{% for stage in case.case.stages.values()%}
<li onclick="showElement('{{id}}.stage.{{stage.id}}')"><a>{{stage.id}}-{{stage.name}}</a></li>
<div id="{{id}}.stage.{{stage.id}}" style="display:none">
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="150" height="300"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="150" height="300"/>
</div>
{% endfor %}
</td>
Expand Down Expand Up @@ -321,8 +321,8 @@
{% for stage in case.case.stages.values()%}
<li onclick="showElement('{{id}}.stage.{{stage.id}}')"><a>{{stage.id}}-{{stage.name}}</a></li>
<div id="{{id}}.stage.{{stage.id}}" style="display:none">
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="150" height="300"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="150" height="300"/>
</div>
{% endfor %}
</td>
Expand Down Expand Up @@ -420,8 +420,8 @@
{% for stage in case.case.stages.values()%}
<li onclick="showElement('{{id}}.stage.{{stage.id}}')"><a>{{stage.id}}-{{stage.name}}</a></li>
<div id="{{id}}.stage.{{stage.id}}" style="display:none">
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="150" height="300"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="150" height="300"/>
</div>
{% endfor %}
</td>
Expand Down Expand Up @@ -517,8 +517,8 @@
{% for stage in case.case.stages.values()%}
<li onclick="showElement('{{id}}.stage.{{stage.id}}')"><a>{{stage.id}}-{{stage.name}}</a></li>
<div id="{{id}}.stage.{{stage.id}}" style="display:none">
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="150" height="300"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="150" height="300"/>
</div>
{% endfor %}
</td>
Expand Down Expand Up @@ -650,8 +650,8 @@
{% for stage in case.case.stages.values()%}
<li onclick="showElement('{{id}}.stage.{{stage.id}}')"><a>{{stage.id}}-{{stage.name}}</a></li>
<div id="{{id}}.stage.{{stage.id}}" style="display:none">
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="150" height="300"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="150" height="300"/>
</div>
{% endfor %}
</td>
Expand Down
20 changes: 10 additions & 10 deletions haf/ext/resource/report/base_online_app.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@
{% for stage in case.case.stages.values()%}
<li onclick="showElement('{{id}}.stage.{{stage.id}}')"><a>{{stage.id}}-{{stage.name}}</a></li>
<div id="{{id}}.stage.{{stage.id}}" style="display:none">
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="150" height="300"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="150" height="300"/>
</div>
{% endfor %}
</td>
Expand Down Expand Up @@ -321,8 +321,8 @@
{% for stage in case.case.stages.values()%}
<li onclick="showElement('{{id}}.stage.{{stage.id}}')"><a>{{stage.id}}-{{stage.name}}</a></li>
<div id="{{id}}.stage.{{stage.id}}" style="display:none">
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="150" height="300"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="150" height="300"/>
</div>
{% endfor %}
</td>
Expand Down Expand Up @@ -420,8 +420,8 @@
{% for stage in case.case.stages.values()%}
<li onclick="showElement('{{id}}.stage.{{stage.id}}')"><a>{{stage.id}}-{{stage.name}}</a></li>
<div id="{{id}}.stage.{{stage.id}}" style="display:none">
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="150" height="300"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="150" height="300"/>
</div>
{% endfor %}
</td>
Expand Down Expand Up @@ -517,8 +517,8 @@
{% for stage in case.case.stages.values()%}
<li onclick="showElement('{{id}}.stage.{{stage.id}}')"><a>{{stage.id}}-{{stage.name}}</a></li>
<div id="{{id}}.stage.{{stage.id}}" style="display:none">
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="150" height="300"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="150" height="300"/>
</div>
{% endfor %}
</td>
Expand Down Expand Up @@ -650,8 +650,8 @@
{% for stage in case.case.stages.values()%}
<li onclick="showElement('{{id}}.stage.{{stage.id}}')"><a>{{stage.id}}-{{stage.name}}</a></li>
<div id="{{id}}.stage.{{stage.id}}" style="display:none">
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="100" height="200"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("before")}}" width="150" height="300"/>
<img src="{{case.case.pngs.get(stage.id, {"before": "", "after": ""}).get("after")}}" width="150" height="300"/>
</div>
{% endfor %}
</td>
Expand Down
31 changes: 28 additions & 3 deletions haf/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,27 @@ def __init__(self, bench:AppBench, log_dir):
self.key = ""
self.log_dir = log_dir

def wait_activity(self, activity, timeout, driver):
"""Wait for an activity: block until target activity presents
or time out.
This is an Android-only method.
:Agrs:
- activity - target activity
- timeout - max wait time, in seconds
- interval - sleep interval between retries, in seconds
"""
try:
i = 0
while i<timeout:
logger.info(f"{case.log_key}: current activity is {driver.current_activity}")
if driver.current_activity == activity:
return
time.sleep(1)
i += 1
except Exception as e:
logger.error(f"{case.log_key}: {e}")
return

def run(self, case: AppCase):
'''
run the AppCase
Expand All @@ -367,7 +388,11 @@ def run(self, case: AppCase):
from appium import webdriver
driver = webdriver.Remote(APP_DRIVER_PATH, case.desired_caps.deserialize())
logger.info(f"{case.log_key} : wait app start ...")
time.sleep(10)
if case.wait_activity:
time.sleep(5)
self.wait_activity(case.wait_activity, case.time_sleep, driver)
else:
time.sleep(case.time_sleep)
logger.info(f"{case.log_key} : driver is {driver}")
page = BasePage(driver)
for key in range(1, len(case.stages.keys())+1):
Expand All @@ -377,7 +402,7 @@ def run(self, case: AppCase):
png_before = save_screen_shot(driver, png_dir, f"{png_name}-before")
self.run_stage(case, page, case.stages.get(key), result)
png_after = save_screen_shot(driver, png_dir, f"{png_name}-after")
case.pngs[key] = {"before": png_before, "after": png_after}
case.pngs[key] = {"before": f"./png/{png_name}-before.png", "after": f"./png/{png_name}-after.png"}
result.case = case
result.result = RESULT_PASS
except Exception as e:
Expand All @@ -398,7 +423,7 @@ def run_stage(self, case, page, stage: Stage=Stage(), result: AppResult=AppResul
page.send_keys(paths, stage.info.get("keys"))
elif operation == OPERATION_APP_SWIPE:
page.swipe(stage.info.get("direction"))
time.sleep(case.time_sleep)
time.sleep(stage.time_sleep)
except Exception as e:
logger.error(e)
result.run_error = e
Expand Down

0 comments on commit 5d82856

Please sign in to comment.