使用postman模拟appium的http请求

Appium是Server,接收http请求,使用Postman模拟请求

1.anyproxy

  • 1.1、安装和运行
    #安装
    npm i -g anyproxy
    # 运行anyproxy,端口默认8002
    anyproxy

1418970-20181002210507165-113686064.png
注意:测试完不要忘记取消代理设置

unset HTTP_PROXY

1418970-20181022181416395-1680361000.png

  • 1.2、浏览器打开localhost:8002
  • 1.3、设置环境变量和代理
    Mac:export HTTP_PROXY=127.0.0.1:8001
    Windows:set HTTP_PROXY 127.0.0.1:8001

    2.终端执行脚本,捕捉请求

    test.py
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver
from time import sleep
caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "domo"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["newCommandTimeout"] = 1200
caps["automationName"] = "UiAutomator2"

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
driver.implicitly_wait(20)
sleep(20)
print(driver.session_id)

driver.find_element_by_id("com.xueqiu.android:id/user_profile_icon").click()
sleep(1)
driver.find_element_by_id("com.xueqiu.android:id/tv_login").click()
sleep(1)
driver.find_element_by_id("com.xueqiu.android:id/tv_login_by_phone_or_others").click()
sleep(1)
driver.find_element_by_id("com.xueqiu.android:id/register_phone_number").send_keys("123456789")
sleep(3)
print(driver.session_id)

driver.quit()

3.浏览器查看捕捉的请求

1418970-20181003155544247-1964833718.png

4.Postman模拟脚本发起HTTP请求

4.1 传入配置,返回SessionId

URL:http://127.0.0.1:4723/wd/hub/session 
{"capabilities": {"firstMatch": [{}], "alwaysMatch": {"platformName": "android"}}, "desiredCapabilities": {"platformName": "android", "deviceName": "domo", "appPackage": "com.xueqiu.android", "appActivity": ".view.WelcomeActivityAlias", "newCommandTimeout": 200}}
#对应代码
from appium import webdriver
from time import sleep
caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "domo"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["newCommandTimeout"] = 1200
caps["automationName"] = "UiAutomator2"

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

1418970-20181003171410980-733984927.jpg

4.2 等待20秒

URL:http://127.0.0.1:4723/wd/hub/session/${SessionId}/timeouts/implicit_wait 
#对应代码
sleep(20)

1418970-20181003171418957-1359106916.jpg

4.3 传入控件信息,返回ELEMENT的值,在随后的操作中会用到

URL: http://127.0.0.1:4723/wd/hub/session/${SessionId}/element 
body传入控件信息:com.xueqiu.android:id/user_profile_icon

1418970-20181003171427198-30833381.jpg

4.4 针对元素进行操作

URL: http://127.0.0.1:4723/wd/hub/session/${SessionId}/element/${Element}/click 
#对应脚本
driver.find_element_by_id("com.xueqiu.android:id/user_profile_icon").click()

1418970-20181003171433789-1788245120.jpg

4.5 传入控件信息,返回Element的值

URL: http://127.0.0.1:4723/wd/hub/session/${SessionID}/element 
body传入控件信息:com.xueqiu.android:id/tv_login

1418970-20181003171437947-545176159.jpg

4.6 针对元素进行操作

URL: http://127.0.0.1:4723/wd/hub/session/${SessionId}/element/${ELEMENT}/click 
#对应脚本
driver.find_element_by_id("com.xueqiu.android:id/tv_login").click()

1418970-20181003171452469-580706626.jpg

4.7 传入控件信息,返回ELEMENT的值

URL: http://127.0.0.1:4723/wd/hub/session/${SessionId}/element 
body传入控件信息: com.xueqiu.android:id/tv_login_by_phone_or_others

1418970-20181003171459333-2017933644.jpg

4.8 针对元素进行操作

URL:http://127.0.0.1:4723/wd/hub/session/${SessionId}/element/${ELEMENT}/click 
#对应脚本
driver.find_element_by_id("com.xueqiu.android:id/tv_login_by_phone_or_others").click()

1418970-20181003171509704-16705909.jpg

4.9 传入控件信息,返回ELEMENT的值

URL: http://127.0.0.1:4723/wd/hub/session/${SessionId}/element 
body传入控件信息: com.xueqiu.android:id/register_phone_number

1418970-20181003171516919-135451851.jpg

5.10 针对元素进行操作

URL: http://127.0.0.1:4723/wd/hub/session/${SessionId}/element/${ELEMENT}/value 
#对应脚本
driver.find_element_by_id("com.xueqiu.android:id/register_phone_number").send_keys("123456789")

1418970-20181003171525410-1917699103.jpg

5.11 结束

URL:http://127.0.0.1:4723/wd/hub/session/${SessionId}
#对应脚本
driver.quit()

1418970-20181003171534919-441863507.jpg

转载于:https://www.cnblogs.com/csj2018/p/9739143.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值