selenium常用方法的封装
flask 封装selenium常用方法:
代码如下:
1 from flask import Flask,jsonify, request ,abort,Blueprint 2 from driverbase import bases 3 from selenium import webdriver 4 from selenium.webdriver.common.action_chains import ActionChains 5 from selenium.webdriver.common.by import By 6 from time import sleep 7 8 9 10 app = Flask(__name__) 11 12 # responer = { 13 # abort #flask默认的状态返回码,使用必须和http状态码一致,如abort(400) abort(405) 等 14 # "code":"", #值为0和1. 0表示成功,1表示失败 15 # "msg":"success", 16 # "data": 返回各请求数据 17 # } 18 19 20 #1 21 @app.route('/firmum/v1/base/openbrowser',methods=["get"]) #get 22 def openbrowser(): 23 """open browser 24 25 open browser 26 @@@ 27 #### args 28 | args | option | value | 29 |browsertype| true| Chrome 、Firefox、IE| 30 #### return 31 -##### json 32 > {"code":0,"msg":"success"} 33 @@@ 34 """ 35 global driver 36 try: 37 #if request.methods.lower() != "get": 38 # return jsonify(abort(405),msg="The method in the client request is forbidden") 39 browsertype = request.args.get('browsertype') 40 if not all ([browsertype]): 41 #return jsonify(code = 1,msg=" Missing parameters") 42 return abort(400) 43 else: 44 driver = getattr(webdriver, browsertype)() 45 return jsonify(code = 0, msg="{}Driver setup success".format(request.args.get('browsertype'))) 46 #return jsonify({'base':'openbrowser'}) 47 # except Exception as e: 48 # return jsonify(code = 1, msg="{}".format(e)) 49 except: 50 return abort(400) 51 52 53 #2 54 @app.route('/firmum/v1/base/input_url',methods=["get"]) #get 55 def input_url(): 56 try: 57 if request.method.lower() == 'get': 58 url = request.args.get('url') 59 driver.get(url) 60 sleep(3) 61 return jsonify(code = 0, msg="success") 62 except: 63 return abort(400) 64 65 66 def locator(type ,loc): 67 global element 68 locator_dict = { 69 "id":By.ID, 70 "xpath":By.XPATH, 71 "link":By.LINK_TEXT, 72 "partial_link":By.PARTIAL_LINK_TEXT, 73 "name":By.NAME, 74 "tag":By.TAG_NAME, 75 "class":By.CLASS_NAME, 76 "css":By.CSS_SELECTOR, 77 } 78 79 if type in [key for key in locator_dict.keys()]: 80 element = driver.find_element(locator_dict[type],loc) 81 return element 82 else: 83 raise NameError("wrong locator!'id','name','class','tag','link','plink','xpath','css'") 84 85 86 87 88 89 ### Api_demo 90 91 # @app.route('/firmum/v1/inputurl',methods=["get","post"]) 92 # def inputurl(): 93 # method = request.method 94 # if method.lower() == 'get': 95 # browser = request.args.get('browser') 96 # url = request.args.get('url') 97 # bases = driverbase.bases(browser) 98 # return bases.visit(url) 99 # elif method.lower() == 'post': 100 # if not request.json or 'browser' not in request.json or 'url' not in request.json: 101 # abort(400) 102 # else: 103 # browser = request.json['browser'] 104 # url = request.json['url'] 105 # bases = driverbase.bases(browser) 106 # bases.visit(url) 107 # return "访问成功" 108 # 109 # else: 110 # abort(400) 111 112 113 #3 114 @app.route('/firmum/v1/base/windows_max', methods=['get']) #get 115 def windows_max(): 116 #窗口最大化 117 try: 118 if request.method.lower() == 'get': 119 driver.maximize_window() 120 return jsonify(code = 0, msg="success") 121 except: 122 return abort(400) 123 124 125 126 127 #前进 128 @app.route('/firmum/v1/base/forward',methods=['get']) 129 def forward(): 130 try: 131 driver.forward() 132 return jsonify(code = 0, msg = "success") 133 except: 134 return abort(400) 135 136 #后退 137 @app.route('/firmum/v1/base/back',methods=['get']) 138 def back(): 139 try: 140 driver.back() 141 return jsonify(code = 0, msg = "success!!!") 142 except: 143 return abort(400) 144 145 #刷新 146 @app.route('/firmum/v1/base/refresh',methods=['get']) 147 def refresh(): 148 try: 149 driver.refresh() 150 sleep(2) 151 return jsonify(code = 0, msg = "success!!!") 152 except: 153 return abort(400) 154 155 156 @app.route('/firmum/v1/base/close',methods=['get']) 157 def close(): 158 try: 159 driver.close() 160 sleep(2) 161 return jsonify(code = 0, msg = "success") 162 except: 163 return abort(400) 164 165 #位置参数 166 # type:元素定位8大类型(id,name,xpath,css,tag, class, link,partial_link) 167 # value:元素定位的值 168 # @app.route('/firmum/v1/base/locator',methods=['post']) #post 169 # def locator(type ,value): 170 # types =["id","name","css","xpath","tag","class","link","partial_link"] 171 # try: 172 # if request.json['type'] not in types: 173 # return jsonify(code = 1, msg ="parameters error") 174 # else: 175 # type = request.json['type'] 176 # value = request.json['value'] 177 # driver.find_element(type,value) 178 # return jsonify(code= 0, msg = "Element is positioned") 179 # except Exception as e: 180 # return jsonify(code = 1, msg = '{}'.format(e)) 181 182 183 184 185 186 187 188 189 190 191 #4 192 #输入 193 #位置参数 type:元素定位8大类型(id,name,xpath,css,tag, class, link,partial_link) 194 @app.route('/firmum/v1/base/input',methods=['post']) #post 195 def input(): 196 try: 197 if request.method.lower() == 'post': 198 type = request.json['type'] 199 value = request.json['value'] 200 text = request.json['text'] 201 #driver.find_element(type, value).send_keys(text) 202 locator(type,value).send_keys(text) 203 return jsonify(code = 0, msg='success') 204 except: 205 return abort(400) 206 207 208 209 210 #5 211 @app.route('/firmum/v1/base/click',methods=['post']) 212 def click(): 213 try: 214 type = request.json['type'] 215 value = request.json['value'] 216 locator(type,value).click() 217 return jsonify(code = 0, msg = "success") 218 except: 219 return abort(400) 220 221 222 223 224 225 226 227 228 229 #6 230 @app.route('/firmum/v1/base/quit',methods=['get']) 231 def quit(): 232 try: 233 driver.quit() 234 return jsonify(code = 0, msg="success") 235 except: 236 return abort(400) 237 238 239 240 241 #button 242 #7 243 @app.route('/firmum/v1/button/getElementExistance',methods=['post']) 244 def getElementExistance(): 245 element_existance = True 246 try: 247 # 尝试寻找元素,如若没有找到则会抛出异常 248 type = request.json['type'] 249 value = request.json['value'] 250 #driver.find_element(type, value) 251 locator(type, value) 252 data = { 253 "eleexist": element_existance 254 } 255 return jsonify(code = 0, msg = "success", data = data) 256 except: 257 element_existance = False 258 data ={ 259 "eleexist": element_existance 260 } 261 return jsonify(code = 1, msg="error",data=data) 262 263 264 #8 265 # 判断该元素是否能够点击 266 @app.route('/firmum/v1/button/getElementClickable',methods=['post']) 267 def getElementClickable(): 268 clickable = True 269 try: 270 # 尝试点击元素,如果元素不能点击,则会抛出异常 271 type = request.json['type'] 272 value = request.json['value'] 273 #driver.find_element(type,value).click() 274 data = { 275 "eleclick":clickable 276 } 277 locator(type, value).click() 278 return jsonify(code = 0, msg = "success", data=data) 279 except: 280 clickable = False 281 data = { 282 "eleclick": clickable 283 } 284 return jsonify(code = 1, msg = "error", data=data) 285 286 #9 287 # 返回元素属性 288 @app.route('/firmum/v1/button/getElementProperty',methods=['post']) 289 def getElementProperty(): 290 try: 291 type = request.json['type'] 292 value = request.json['value'] 293 #element = driver.find_element(type, value) 294 data = { 295 "id":locator(type, value).id, 296 "location":locator(type, value).location, 297 "size":locator(type, value).size, 298 "tag_name":locator(type, value).tag_name, 299 "text":locator(type, value).text, 300 "value":locator(type, value).get_attribute('value'), 301 "css":{ 302 "color": locator(type, value).value_of_css_property("color"), 303 "background-color":locator(type, value).value_of_css_property("background-color"), 304 "font": locator(type, value).value_of_css_property("font"), 305 "height":locator(type, value).value_of_css_property("height"), 306 "width":locator(type, value).value_of_css_property("width") 307 } 308 } 309 return jsonify(code = 0, msg = "success",data=data) 310 except: 311 return abort(400) 312 313 314 ##鼠标事件 315 316 #10 317 # 悬停 318 @app.route('/firmum/v1/mouse/move_to_element',methods=['post']) 319 def move_to_element(): 320 try: 321 type = request.json['type'] 322 value = request.json['value'] 323 #element = driver.find_element(type,value) 324 ActionChains(driver).move_to_element(locator(type,value)).perform() 325 return jsonify(code = 0,msg="success") 326 except : 327 return abort(400) 328 329 330 #11 331 # 右击 332 @app.route('/firmum/v1/mouse/right_click',methods=['post']) 333 def right_click(): 334 try: 335 type = request.json['type'] 336 value = request.json['value'] 337 #element = driver.find_element(type, value) 338 ActionChains(driver).context_click(locator(type,value)).perform() 339 return jsonify(code = 0 ,msg = "success") 340 except: 341 return abort(400) 342 #12 343 #双击 344 @app.route('/firmum/v1/mouse/double_click',methods=['post']) 345 def double_click(): 346 try: 347 type = request.json['type'] 348 value = request.json['value'] 349 #element = driver.find_element(type,value) 350 ActionChains(driver).double_click(locator(type,value)).perform() 351 return jsonify(code= 0, msg="success") 352 except: 353 return abort(400) 354 355 #13 356 #元素截图 357 @app.route('/firmum/v1/button/screenshot',methods=['post']) 358 def screenshot(): 359 try: 360 type = request.json['type'] 361 value = request.json['value'] 362 imgname = request.json['imgname'] 363 #element = driver.find_element(type, value) 364 locator(type,value).screenshot(r'%s.png' % imgname) 365 return jsonify(code =0 , msg = "success") 366 except: 367 return abort(400) 368 369 370 #14 371 #input 372 #获取文本内容及字符个数 373 @app.route('/firmum/v1/base/get_input_text',methods=['post']) 374 def get_input_text(): 375 try: 376 type = request.json['type'] 377 value = request.json['value'] 378 #text = driver.find_element(type, value).get_attribute('value') # get_attribute('value')获取输入框的值 379 text = locator(type,value).get_attribute('value') 380 data = { 381 "text":text, 382 "textnum":len(text) 383 } 384 return jsonify(code = 0,msg = "success",data=data) 385 except: 386 return abort(400) 387 388 389 390 391 392 393 394 395 #15 396 #清除 397 @app.route('/firmum/v1/base/clear',methods=['post']) 398 def myclear(): 399 try: 400 type = request.json['type'] 401 value = request.json['value'] 402 #driver.find_element(type, value).clear() 403 locator(type,value).clear() 404 return jsonify(code = 0,msg = "success") 405 except: 406 return abort(400) 407 408 409 #table 410 #返回表格行数和行的内容 411 @app.route('/firmum/v1/table/get_tablerows',methods=['post']) 412 def get_tablerows(): # i代表行号 413 try: 414 type = request.json['type'] 415 value = request.json['value'] 416 row = request.json['row'] 417 rows = locator(type,value).find_elements_by_tag_name('tr') 418 data = { 419 "len":len(rows), 420 "text":rows[row].text 421 } 422 return jsonify(code = 0, msg = 'success', data=data) 423 except: 424 return abort(400) 425 426 427 # 返回表格某行某列的内容 428 @app.route('/firmum/v1/table/get_tablecells',methods=['post']) 429 def get_tablecells(): # row代表行号,col代表列号 430 try: 431 type = request.json['type'] 432 value = request.json['value'] 433 row = request.json['row'] 434 col = request.json['col'] 435 rows = locator(type,value).find_elements_by_tag_name('tr') 436 if row == 0: 437 cells = rows[row].find_elements_by_tag_name('th') 438 else: 439 cells = rows[row].find_elements_by_tag_name('td') 440 data = { 441 "text":cells[col-1].text 442 } 443 return jsonify(code = 0, msg="success",data = data) 444 except: 445 return abort(400) 446 447 448 449 450 #新增 451 #获取url 452 @app.route('/firmum/v1/base/get_current_url',methods=['get']) 453 def get_current_url(): 454 try: 455 url = driver.current_url 456 data = { 457 'url':url 458 } 459 return jsonify (code = 0, msg = 'success', data = data) 460 except: 461 return abort(400) 462 463 464 465 #将句柄转换到最新的窗口 466 @app.route('/firmum/v1/base/skip_window_handle',methods=['get']) 467 def skip_window_handle(): 468 try: 469 driver.switch_to.window(driver.window_handles[-1]) 470 data = { 471 "url":driver.current_url, 472 "title":driver.title 473 } 474 return jsonify(code = 0 ,msg ='success',data = data) 475 except: 476 return abort(400) 477 478 #获取title 479 @app.route('/firmum/v1/base/get_title') 480 def get_title(): 481 try: 482 title = driver.title 483 data = { 484 'title':title 485 } 486 return jsonify(code = 0, msg = "success", data = data) 487 except: 488 return abort(400) 489 490 #获取浏览器信息 491 @app.route('/firmum/v1/base/get_capabilities',methods=['get']) 492 def get_capabilities(): 493 try: 494 # data = { 495 # "browserinfo":driver.capabilities 496 # } 497 return jsonify(code = 0 ,msg = "success",data = driver.capabilities) 498 except: 499 return abort(400) 500 501 502 503 504 505 #接口未保存 506 #跳转到frame/iframe中 507 @app.route('/firmum/v1/base/skip_to_frame',methods=['post']) 508 def skip_to_frame(): 509 try: 510 value = request.json['value'] 511 driver.switch_to.frame(value) 512 return jsonify(code = 0, msg = 'success') 513 except: 514 return abort(400) 515 516 517 #跳出frame 518 @app.route('/firmum/v1/base/skip_frame_handle',methods=['get']) 519 def frame_from_skip(): 520 try: 521 driver.switch_to_default_content() 522 return jsonify(code = 0 ,msg = "success") 523 except: 524 return abort(400) 525 526 527 @app.errorhandler(400) 528 def innererror(e): 529 return jsonify(code = 1,msg = "Bad request") 530 531 532 if __name__ == '__main__': 533 app.run(debug=True) 534 535 #f = request.json['f'] 536 #e = url_for("fun1",a=r,b=f)
接口文档如下:
UI自动化测试平台Firmum API V1.0
接口说明文档(草稿)
本文为firmum自动化平台的接口说明文档,firmum主要用于web UI自动化测试,提供常见的ui测试流程。以下接口使用python语言、基于flask框架、在selenium(3.141.0)常用方法的基础上进行修改封装 。
运行环境:
1、Python3及以上
2、Flask
3、Selenium3及以上
4、Selenium支持的各浏览器及浏览器对应版本驱动
注意术语:
Request部分:
浏览器类型:
浏览器类型为驱动常用浏览器,其取值范围有:Chrome 、Firefox、Ie等
定位类型:
定位类型为selenium中常见的八种定位类型,其可传入参数及对应selenium中定位方法如下表:
定位类型 |
对应的selenium中定位方法 |
id |
id |
css |
css_selector |
xpath |
xpath |
name |
name |
class |
class_name |
tag |
tag_name |
link |
link_text |
partial_link |
partial_link_text |
Response字段:
1、 Code:可取值为0和1。0代表请求成功,1代表请求失败。
2、 其余特殊字段在对应的接口返回中给与说明。
接口说明
一、Base部分:
接口地址:http://127.0.0.1:5000//firmum/v1/base
1. Openbrowser
功能:打开浏览器
Request:
URL |
/input |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/openbrowser?browsertype=Chrome |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
browsertype |
浏览器类型 |
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "ChromeDriver setup success" } |
2. input_url
功能:输入网址
Request:
URL |
/input |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/input_url?url=http://www.baidu.com |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
url |
网址 |
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "success" } |
3. input
功能:文本框输入
Request:
URL |
/input |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/base/input
{ "type":"css", "value":"input#kw", "text":"666" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
text |
要输入的文本内容 |
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "success" } |
4. get-input_text
功能:获取文本框文本内容及字符个数
Request:
URL |
/click |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/base/get_input_text { "type":"id", "value":"kw" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
|
|
Response:
Content_Type |
application/json |
Return 返回字段含义: data{ text:文本框中的文本内容 textnum:字符长度 } |
{ "code": 0, "data": { "text": "666", "textnum": 3 }, "msg": "success" } |
5. click
功能:鼠标单击
Request:
URL |
/click |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/base/click { "type":"id", "value":"su" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "success" } |
6. windows_max
功能:浏览器窗口最大化
Request:
URL |
/click |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/windows_max |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
|
|
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "success" } |
7. clear
功能:清除文本框输入
Request:
URL |
/clear |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/base/clear { "type":"xpath", "value":"//*[@id='kw']" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "success" } |
8. refresh
功能:刷新浏览器网页
Request:
URL |
/click |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/clear |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "success" } |
9. forward
功能:浏览器页面前进
Request:
URL |
/forward |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/forward |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
|
|
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "success" } |
10.back
功能:浏览器页面回退
Request:
URL |
/back |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/back |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
|
|
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "success" } |
11.close
功能:关闭浏览器页面
Request:
URL |
/close |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/close |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
|
|
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "success" } |
12.quit
功能:退出浏览器
Request:
URL |
/quit |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/quit |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
|
|
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "msg": "success" } |
13.get_current_url
功能:获取url
Request:
URL |
/get_current_url |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/get_current_url |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
|
|
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "data": { "title": "百度一下,你就知道" }, "msg": "success" } |
14.get_title
功能:获取页面标题
Request:
URL |
/get_title |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/get_title |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
|
|
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "data": { "title": "百度一下,你就知道" }, "msg": "success" } |
15.skip_window_handle
功能:将页面句柄跳转到新打开的页面
Request:
URL |
/skip_window_handle |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/skip_window_handle |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
|
|
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "data": { "title": "百度新闻——海量中文资讯平台", "url": "http://news.baidu.com/" }, "msg": "success" } |
16.get_capabilities
功能:获取浏览器及浏览器驱动信息
Request:
URL |
/get_capabilities |
示例 |
Method |
get |
http://127.0.0.1:5000/firmum/v1/base/get_capabilities |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
|
|
|
|
|
|
|
|
Response:
Content_Type |
application/json |
return |
{ "code": 0, "data": { "acceptInsecureCerts": false, "browserName": "chrome", "browserVersion": "86.0.4240.75", "chrome": { "chromedriverVersion": "86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378})", "userDataDir": "C:\\Users\\wei\\AppData\\Local\\Temp\\scoped_dir29892_1673112883" }, "goog:chromeOptions": { "debuggerAddress": "localhost:59304" }, "networkConnectionEnabled": false, "pageLoadStrategy": "normal", "platformName": "windows", "proxy": {}, "setWindowRect": true, "strictFileInteractability": false, "timeouts": { "implicit": 0, "pageLoad": 300000, "script": 30000 }, "unhandledPromptBehavior": "dismiss and notify", "webauthn:virtualAuthenticators": true }, "msg": "success" }
|
二、button部分
接口地址:http://127.0.0.1:5000/firmum/v1/button
1. getElementExistance
功能:判断元素是否存在
Request:
URL |
/getElementExistance |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/button/getElementExistance { "type":"id", "value":"kw" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
|
|
Response:
Content_Type |
application/json |
Return Data包含字段含义: eleexist:判断元素存在,取值范围:True(存在)、Flase(不存在,不存在时code=1,message = error) |
{ "code": 0, "data": { "eleexist": true }, "msg": "success" } |
2. getElementClickable
功能:判断元素是否可点击
Request:
URL |
/getElementClickable |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/button/getElementClickable { "type":"id", "value":"kw" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
|
|
Response:
Content_Type |
application/json |
Return Data包含字段含义: eleclick:判断元素可点击,取值范围:True(可点击)、Flase(不可点击,不可点击时code=1,message = error) |
{ "code": 0, "data": { "eleclick": true }, "msg": "success" } |
3. getElementProperty
功能:获取元素各属性
Request:
URL |
/getElementProperty |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/button/getElementProperty { "type":"id", "value":"kw" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
Response:
Content_Type |
application/json |
Return Data字段含义: |
{ "code": 0, "data": { "css": { "background-color": "rgba(78, 110, 242, 1)", "color": "rgba(255, 255, 255, 1)", "font": "17px / 45px \"PingFang SC\", Arial, \"Microsoft YaHei\", sans-serif", "height": "44px", "width": "108px" }, "id": "ce361ac6-978f-4629-9ece-f6e6d8efa947", "location": { "x": 844, "y": 209 }, "size": { "height": 44, "width": 108 }, "tag_name": "input", "text": "", "value": "百度一下" }, "msg": "success" }
|
4. Screenshot
功能:对元素进行截图
Request:
URL |
/screenshot |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/button/screenshot { "type":"id", "value":"kw", "imgname":".//image/test" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
imgname |
截图存放路径及名称 |
Response:
Content_Type |
application/json |
Return |
{ "code": 0, "msg": "success" }
|
三、 Mouse部分
接口地址:http://127.0.0.1:5000/firmum/v1/mouse
1、move_to_element
功能:鼠标悬停
Request:
URL |
/move_to_element |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/mouse/move_to_element { "type":"id", "value":"kw" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
|
|
Response:
Content_Type |
application/json |
Return |
{ "code": 0, "msg": "success" } |
2、right_click
功能:鼠标右击
Request:
URL |
/right_click |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/mouse/right_click { "type":"id", "value":"su" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
|
|
Response:
Content_Type |
application/json |
Return |
{ "code": 0, "msg": "success" } |
3、double_click
功能:鼠标双击
Request:
URL |
/double_click |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/mouse/double_click { "type":"id", "value":"su" } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
|
|
Response:
Content_Type |
application/json |
Return |
{ "code": 0, "msg": "success" } |
四、Table部分
接口网址:http://127.0.0.1:5000/firmum/v1/table
1、get_tablerows
功能:获取表格行数和行内容
Request:
URL |
/get_tablerows |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/table/get_tablerows { "type":"class", "value":"reference", "row":1 } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
row |
第几行 |
Response:
Content_Type |
application/json |
Return |
{ "code": 0, "data": { "len": 5, "text": "HTML 3.2 1997 年 1 月 14 日" }, "msg": "success" } |
2、get_tablecells
功能:获取对应表格中的内容
Request:
URL |
/get_tablecells |
示例 |
Method |
post |
http://127.0.0.1:5000/firmum/v1/table/get_tablecells { "type":"class", "value":"reference", "row":2, "col":2 } |
Content_Type |
application/json |
|
Args说明 |
||
Args字段 |
传入字段说明 |
|
type |
定位类型 |
|
value |
定位值 |
|
row |
第几行 |
|
col |
第几列 |
Response:
Content_Type |
application/json |
Return data字段含义: text:对应表格中的内容 |
{ "code": 0, "data": { "text": "1998 年 5 月 24 日" }, "msg": "success" } |