浣跨敤Jmeter杩涜鎺ュ彛娴嬭瘯
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浣跨敤Jmeter杩涜鎺ュ彛娴嬭瘯相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e4%bc%a0%e5%80%bc' title='浼犲€?>浼犲€?/a> 鍙栧嚭 鏂瑰紡 鏌ョ湅 鍘嬬缉 绫诲瀷 code 鍥剧墖
鏁版嵁椹卞姩
- 鍩轰簬鏁版嵁娴佸畬鎴愭祦绋嬭皟搴︼紝鏁版嵁鏉ユ簮浜庡閮紝鍙互浠巈xecl,yaml,鏁版嵁搴撲腑鑾峰彇
- 浣跨敤yaml, json绛夎鍙栨暟鎹?/li>
- 娴佺▼锛?璇诲彇澶栭儴鏂囦欢 -> 鍔ㄦ€佸垱寤烘祴璇曠敤渚?/li>
yaml
- pip install pyyaml
- yaml鏂囦欢鎿嶄綔https://github.com/yaml/pyyaml?spm=a2c6h.12873639.0.0.70ab3ab4BvVbOE
- 绠€鍗曠殑姝ラ椹卞姩渚嬪瓙
- yaml鏂囦欢锛?ch2/case.yaml
# 绠€鍗曠殑case_yaml妯℃澘
- Descripton: 杩涘叆鎼滅储椤甸潰
Methods: id
Value: ivSearch
Action: click
- Descripton: 鎼滅储娴嬭瘯鏁版嵁
Methods: id
Value: etSearch
Action: send_keys
data: 娴嬭瘯
- Descripton: 鑾峰彇鎼滅储鍊? Methods: id
Value: tvSearchResult
Action: text
- 娴嬭瘯姝ラ椹卞姩 ch2/test_yaml.py
- 璇诲彇yaml鏂囦欢骞朵笖浠ict鏍煎紡杈撳嚭
- 瀹氫箟drver: WebDriver 锛堢瓑鍚屼簬鎶婁箣鍓嶇殑self.driver浼犵粰鏁版嵁椹卞姩鏂规硶锛?/li>
- 寰幆姣忎釜瀛楀吀锛屾墽琛屼笉鍚岀殑娴嬭瘯姝ラ
- method鍑芥暟锛?瀹氫綅鏈変笉鍚屾柟寮忥紝杩欒竟鍗曠嫭灏佽锛屼富瑕佹秹鍙婄殑鏈塱d,xpath,accessibility_id
- 娴嬭瘯椹卞姩锛岀洿鎺ヨ皟鐢╯elf.method鍑芥暟
class TestCaseTemplate:
def __init__(self, path):
with open(path, 鈥榬鈥? encoding="utf-8") as file:
self.steps = yaml.safe_load(file)
def method(self, driver: WebDriver, method, value):
ele = None
if method == 鈥榠d鈥?
ele = driver.find_element_by_id(value)
elif method ==鈥榵path鈥?
ele = driver.find_element_by_xpath(value)
elif method == 鈥榓ccessibility鈥?
ele = driver.find_element_by_accessibility_id(value)
else:
return 鈥楴o element鈥? return ele
def run(self, driver: WebDriver):
for step in self.steps:
elemet = None
if isinstance(step, dict):
if 鈥楳ethods鈥?in step.keys() and 鈥榁alue鈥?in step.keys():
elemet = self.method(driver, step[鈥楳ethods鈥榏, step[鈥榁alue鈥榏)
else:
print(step.keys())
if 鈥楢ction鈥?in step.keys():
if 鈥榗lick鈥?in step[鈥楢ction鈥榏:
elemet.click()
elif 鈥榮end_keys鈥?in step[鈥楢ction鈥榏:
if 鈥榙ata鈥?in step.keys():
elemet.send_keys(step[鈥榙ata鈥榏)
else:
print(鈥樻病鏈夎緭鍏ョ殑娴嬭瘯鏁版嵁鈥?
elif 鈥榯ext鈥?in step[鈥楢ction鈥榏:
data = elemet.text
print(data)
github
https://github.com/wangxiao9/appium_demo.git
以上是关于浣跨敤Jmeter杩涜鎺ュ彛娴嬭瘯的主要内容,如果未能解决你的问题,请参考以下文章