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

1.anyproxy

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


注意:测试完不要忘记取消代理设置
```shell
unset HTTP_PROXY
```

  • 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.浏览器查看捕捉的请求

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)


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

## 4.3 传入控件信息,返回ELEMENT的值,在随后的操作中会用到
URL: http://127.0.0.1:4723/wd/hub/session/${SessionId}/element
body传入控件信息:com.xueqiu.android:id/user_profile_icon

## 4.4 针对元素进行操作
URL: http://127.0.0.1:4723/wd/hub/session/${SessionId}/element/${Element}/click
```#python
#对应脚本
driver.find_element_by_id("com.xueqiu.android:id/user_profile_icon").click()
```

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

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

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()

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

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()

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

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

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")

5.11 结束

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

使用postman模拟appium的http请求的更多相关文章

  1. Postman模拟Request Payload发送请求

    Postman模拟Request Payload发送请求,如下图所示:

  2. postMan模拟get和post请求,支持局域网和外网

    chrome应用postMan,可以安装一下,非常方便. 可以FQ下载安装. post参数要在body中设置 get参数直接在url中

  3. 模拟POST、Get 请求的工具----APIpost(中文版POSTMAN)

    模拟POST.Get 请求的工具----APIpost(中文版POSTMAN) 快速生成.一键导出api文档 在线模拟调试,结果实时返回 模拟登录后请求API 支持团队协作 官网:https://ww ...

  4. 使用Postman模拟HTTP请求

    使用Postman模拟HTTP请求 Postman是一款强大的前端调试工具,不管是开发人员还是测试人员都会需要调试接口程序,如RestAPI,此时可以通过向服务器发送不同的HTTP请求来判断接口返回结 ...

  5. 『政善治』Postman工具 — 4、HTTP请求基础组成部分介绍

    目录 1.Method 2.URL 3.Headers 4.body 一般来说,所有的HTTP Request都有最基础的4个部分组成:URL. Method. Headers和body. 1.Met ...

  6. 模拟ajax的 script请求

    /** * 模拟ajax的 script请求 * @param {[type]} options [description] * @return {[type]} [description] */ f ...

  7. .net后台模拟浏览器get/post请求

    #region 后台模拟浏览器get/post请求 /// <summary> /// 发送请求方式 /// </summary> /// <param name=&qu ...

  8. postman(二):使用postman发送get or post请求

    总结一下如何使用postman发送get或post请求 请求 一.GET请求 通常用于请求服务器发送某个资源,请求的数据会附在URL之后,以?分割URL和传输数据,多个参数用&连接 1.请求方 ...

  9. php中模拟post,get请求和接受请求详细讲解

    在php中我们经常用到curl拓展来进行模拟post.get请求,下面就来具体说说怎么模拟: 一.首先模拟post请求: function http_post_data($url, $query_da ...

随机推荐

  1. 用MyEclipse JPA创建项目(二)

    MyEclipse 3.15 Style——在线购买低至75折!火爆开抢>> [MyEclipse最新版下载] 本教程介绍了MyEclipse中的一些基于PA的功能. 阅读本教程时,了解J ...

  2. 关于plantera

    在Plantera,您可以建立属于您自己的花园,并且看着新的植物,灌木,树木和动物一起生长. 当您进行游戏,扩张您的花园时,您会吸引圆滚滚的蓝色生物小助手们,它们将帮助您捡果子,收获您的植物 有时候会 ...

  3. anu - proptypes

    //为了兼容yo var check = function () { return check; }; check.isRequired = check; export var PropTypes = ...

  4. kbmMW CopyRawRecords 用法

    复制一个ClientQuery数据集到另外一个ClientQuery,我们应该怎么做?并注意什么呢? kbmMW为我们提供了好几个方法,有LoadFromDataSet,CopyRawRecords, ...

  5. ubuntu16 intellij idea install lombok plugin

    项目中用到lombok,idea会出现类似编译报错的红色,但并不影响运行.所以为了没有类似警告,就在idea上安装lombok插件.file-settings 安装完成之后,按照提示重启idea,问题 ...

  6. MySQLzip压缩文件格式安装教程

    MySQL是一个小巧玲珑但功能强大的数据库,目前十分流行.但是官网给出的安装包有两种格式,一个是msi格式,一个是zip格式的.很多人下了zip格式的解压发现没有setup.exe,面对一堆文件一头雾 ...

  7. Python装饰器的通俗理解

    转载:http://blog.csdn.net/u013471155 在学习Python的过程中,我相信有很多人和我一样,对Python的装饰器一直觉得很困惑,我也是困惑了好久,并通过思考和查阅才能略 ...

  8. I.MX6 Ar8031 device register hacking

    /***************************************************************************** * I.MX6 Ar8031 device ...

  9. FZU OJ 1075 :分解素因子

    Problem 1075 分解素因子 Accept: 2161    Submit: 4126Time Limit: 1000 mSec    Memory Limit : 32768 KB  Pro ...

  10. jquery中not的用法[.not(selector)]

    描述: 从匹配的元素集合中移除指定的元素. 如果提供的jQuery对象代表了一组DOM元素,.not()方法构建一个新的匹配元素的jQuery对象,用于存放筛选后的元素.所提供的选择器是对每个元素进行 ...