zoukankan      html  css  js  c++  java
  • 使用postman模拟appium的http请求

    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()
    
  • 相关阅读:
    POJ3709 K-Anonymous Sequence 斜率优化DP
    POJ3233 Matrix Power Series
    第六周 Leetcode 446. Arithmetic Slices II
    POJ1743 Musical Theme 最长重复子串 利用后缀数组
    Ural 1517. Freedom of Choice 后缀数组
    iOS跳转到另一个程序
    上传源码到github
    NSTimer用法,暂停,继续,初始化
    iOS中多线程原理与runloop介绍
    NSRunLoop 概述和原理
  • 原文地址:https://www.cnblogs.com/csj2018/p/9739143.html
Copyright © 2011-2022 走看看