6-3-2绕过appium的iOS测试

1.WDA自带的inspector

  • 1.1.启动WDA
    + Xcode启动:product-test,适合个人调试
    + 命令行启动:适合持续集成
UDID=$(idevice_id -l)
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=$UDID" test-without-building
  • 1.2.iproxy 8100 8100
    不启动iproxy,inspector不能访问
  • 1.3.查看WDA自带的inspector
    浏览器输入127.0.0.1:8100/status,查看连接状态,inspector查找元素。
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=${UDID}" test-without-building
注意:WDA自带的inspect没有xpath

2使用wdaproxy获取页面

  • 2.1停止iproxy,使用wdaproxy
  • 2.2安装:brew install openatx/tap/wdaproxy
  • 2.3启动:wdaproxy -p 8100
  • 浏览器输入127.0.0.1:8100/,会发现有4个选项,inspector\status\packages\remote。package可以查看安装的应用和包名,remote可以直接操作手机,sessionid,udid
## 3.启动appium的inspector ### 1. 使用bundleId启动 ### 2.使用bundleId+sessionId启动 ## 4.代码 ### 4.1测试脚本1 ```#python from appium import webdriver import time,selenium

caps = {}
caps["bundleId"] = "com.example.apple-samplecode.UICatalogcsj815379479"

driver = webdriver.Remote("http://127.0.0.1:8100/wd/hub", caps)
def wait_element(xpath,timeout=30):
deadline=time.time()+timeout
while time.time() < deadline:
try:
el=driver.find_element_by_xpath(xpath)
return el
except selenium.common.exceptions.NoSuchElementException:
time.sleep(.2)
raise RuntimeError("NoSuchElementException in wait_element")
wait_element("//[@name="Action Sheets"]").click()
wait_element("//
[@name="Okay / Cancel"]").click()
el3 = wait_element("//XCUIElementTypeButton[@name="OK"]")
try:
assert el3.text=='OK',"button is not OK"
except AssertError as e:
print(e)
driver.quit()


###    4.2测试脚本2

python

from appium import webdriver

import time,selenium
driver = webdriver.Remote("http://127.0.0.1:8100/wd/hub",{"bundleId":"com.taobaobj.moneyshield"})

driver.implicitly_wait(30)没有实现这个接口,可以使用函数来代替

def wait_element(elem,timeout=30):
deadline = time.time() + timeout
while time.time() < deadline:
try:
el_xpath = driver.find_element_by_xpath(elem)
return el_xpath
except selenium.common.exceptions.NoSuchElemention:
time.sleep(0.2)
raise RuntimeError("Element not found " + el_xpath)

print(driver.session_id)
time.sleep(3)
driver.find_element_by_accessibility_id("工具箱").click()
driver.find_element_by_accessibility_id("诈骗举报").click()
driver.find_element_by_xpath("//XCUIElementTypeStaticText[@name="电话诈骗举报"]").click()
driver.find_element_by_xpath("//XCUIElementTypeScrollView/XCUIElementTypeOther/XCUIElementTypeOther[1]").send_keys("13693347586")
driver.find_element_by_xpath("(//XCUIElementTypeImage[@name="radiobox_normal"])[3]").click()
driver.find_element_by_accessibility_id("请简要描述一下诈骗来电的内容,比如来电时间,对方特征,被骗方式等").send_keys("骗子,大骗子")
driver.find_element_by_accessibility_id("诈骗内容").click()
driver.find_element_by_accessibility_id("提交举报").click()



##    5使用anyproxy抓包和调试
安装:npm i -g anyproxy
posted on 2018-09-18 18:29  singleSpace  阅读(954)  评论(0编辑  收藏  举报