The most detailed document on building Appium environment under Mac in the whole network

The version of appium server is divided into command line version and desktop version . There are some differences between the two, and both must be installed.

01 appium ios automation environment construction

First of all, you must have a mac computer. Search for xcode in the app store and install it. After the installation is complete, remember to open it once. Some tools of xcode will be automatically installed.

The following steps are all executed under the mac computer terminal

  • install brew

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

  • install libimobiledevice

brew install libimobiledevice --HEAD

There may be an error SSL certificate problem: certificate has expired, then execute the following command and then execute the above command again

git config --global http.sslVerify false

  • install node

brew install node

  • install npm

brew install npm

  • install carthage

brew install carthage

  • Install ios-deploy

npm install ios-deploy

  • install appium

npm install appium

  • Install appium-doctor

npm install appium-doctor

  • check appium ios environment

app-doctor --ios

There is no error in the execution result

  • start appium

application

picture

02 appium desktop version installation

download link:

https://github.com/appium/appium-desktop/releases/tag/v1.21.0

picture

03 compile webdriveragent

If it is an ios simulator, then webdriveragent does not need to handle

  • Compile webdriveragent under real machine

    The webdriveragent source code path of the appium command line version

    /usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent

    Enter the above directory, double-click the WebDriverAgent.xcodeproj file

    Connect to the real device first

    1. Xcode selects the real device

    The two places in the red box in the figure must be selected

    picture

    2. Modify the bundleid of the project

    The bundleid must be unique , otherwise an error will be reported when signing

    The TARGETS in the red frame in the figure must be modified

    picture

    Take the TARGETS of WebDriverAgentRunner as an example, modify the bundleid

    picture

    Do the same for other TARGETS

    3. Signature TARGETS

    Sign for each TARGETS in the box in step 2, take the TARGETS of WebDriverAgentRunner as an example

    picture

    4. Execute project testing

    Executing the webdriveragent test will install a WebDriverAgentRunner app on the real machine, start it, and start an 8100-based http service on the mobile phone , which is a prerequisite for appium to operate

    First select the test file and execute the test

    picture

    The first execution may report the following error

    picture

    Then enter the phone settings --> general --> device management , trust your applie id, then re-execute the test, and open the log to view

    picture

    There is no error reported in the log, and the address in the red box in the picture appears, indicating that the WebDriverAgentRunner app has been installed on the phone and the service has been started

    Then stop the test, click stop in xcode, so far, the wda app has been installed on the phone to be tested

0 4 ios element information viewing

1. Take the Douban app as an example, so install the Douban app on the real device first

Since the parameters need to use the relevant information of the mobile phone and the bundle_id of the Douban app, we first obtain these information and execute the following command in the terminal

# Get information about the currently connected device

ios-deploy -c

picture

Where 00008101-001038A23AC0001E is the udid of the device

# Get the bundle_id of all the apps installed on the current mobile phone, of course, you can also ask your company's development questions

ios-deploy --id 00008101-001038A23AC0001E --list_bundle_id

Then find the bundle_id of Douban app in the result com.douban.frodo

2. The element information viewing of ios app must depend on the appium desktop version, so you must first follow the third step to compile for the webdriveragent under the appium desktop version, the path is as follows:

/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent

After the compilation is complete and the wda app is installed on the real device, open appium desktop, start the server, add the following parameters in the inspect interface and save

  • platformName: ios

  • deviceName: iphone 12

    The value is the device name you saw when checking the phone information in the first step

  • platformVersion: 14.1

    The value is the ios system version of the device seen when checking the phone information in the first step

  • udid: 00008101-001038A23AC0001E

    The value is the udid of the device seen when checking the phone information in the first step

  • bundleId: com.douban.frodo

    The value is the bundle_id of the Douban app obtained in the first step

  • automationName: XCuiTest

  • usePrebuildWDA: true

After setting, click start session

picture

Wait for a while, the inspect debugging interface will appear

picture

05 How appium works on ios

picture

06  appium ios service parameters

  • android and ios public parameters

Capability

Description

Values

automationName

The automation engine used

1. The default is Appium (uiautomator2 under Android, uiautomation under ios)

2. You can also specify uiautomator1 under Android, and XCUITest under ios (only this one)

platformName

mobile operating system used

iOS, Android, or FirefoxOS

platformVersion

The version of the mobile operating system

eg, 7.1, 4.4

deviceName

The name of the mobile device or the name of the emulator (although it is a required item, you can write anything for this value on the Android platform, and it will not affect the script)

iPhone Simulator, iPad Simulator, iPhone Retina 4-inch, Android Emulator, Galaxy S4, etc.... On iOS, use Instruments' instruments -s devices command to return a list of valid devices

app

The path where the App (.ipa/.apk) installation file is located, a local path or a remote path, or a .zip file containing the app installation file. Appium will first try to install the application on the device. Note that if you specify the appPackage and appActivity of the application on Android, then the app parameter is not necessary. This parameter conflicts with browserName

/abs/path/to/my.apk orhttp://myapp.com/app.ipa

browserName

The name of the mobile web automation browser (Chrome browser is used under android). If it is an app automation, the value of this parameter is empty (but in fact, this parameter can not be written directly)

'Safari' for iOS and 'Chrome', 'Chromium', or 'Browser' for Android

newCommandTimeout

等待新命令超时时间(Session超时时间),单位是秒,默认是60秒。当appium服务在指定的超时时间内未接收到任何来自客户端的指令,appium服务端与客户端会主动断开链接

e.g. 60

language

设置模拟器语言

e.g. fr

locale

设置模拟器的区域位置

e.g. fr_CA

udid

链接物理指定设备的唯一标识

e.g. 1ae203187fc012g1. 安卓上就是通过adb devices看到的设备名称2. ios上可以用个idevice_id -l去查看设备的udid

orientation

设置模拟器的方向

LANDSCAPE(横屏)or PORTRAIT(竖屏)

autoWebview

自动转换到 WebView默认是false

true, false

noReset

在当前session开始之前不重置应用的状态(不重置应用数据的意思)。默认是false,表示会重置

true, false

fullReset

(iOS) 删除整个虚拟目录来重置应用数据。(Android) 通过卸载app来的方式重置应用数据(在当前session断开之后)。默认是false

true, false

enablePerformanceLogging

只支持web和webview在android和ios的safari上,性能日志,默认是false

true, false

printPageSourceOnFindFailure

查找元素失败时打印当前界面的page source默认是false

true, false

clearSystemFiles

测试结束后删除所有生成的文件默认是fasle

true, false

  • ios特有参数

Capability

Description

Values

calendarFormat

(Sim-only) 为iOS的模拟器设置日历格式

e.g. gregorian(公历)

bundleId

被测应用的 bundle ID 。用于在真实设备中启动测试,也用于使用其他需要 bundle ID 的关键字启动测试。在使用 bundle ID 在真实设备上执行测试时,你可以不提供 app关键字,但你必须提供 udid 。

e.g. io.appium.TestApp

launchTimeout

以毫秒为单位,在 Appium 运行失败之前设置一个等待 instruments 的时间

e.g. 20000

locationServicesEnabled

(Sim-only) 强制打开或关闭定位服务。默认值是保持当前模拟器的设定

true or false

locationServicesAuthorized

(Sim-only) 通过修改 plist 文件设定是否允许应用使用定位服务,从而避免定位服务的警告出现。默认值是保持当前模拟器的设定。请注意在使用这个关键字时,必须是bundleId同时使用

true or false

autoAcceptAlerts

所有ios的提醒框 (如 位置、联系人、相册) 出现时,自动选择接受( Accept )。默认值 false

true or false

autoDismissAlerts

所有ios的提醒框 (如 位置、联系人、相册) 出现时,自动选择拒绝( Dismiss )。默认值 false

true or false

nativeInstrumentsLib

使用原生 intruments 库 (即关闭 instruments-without-delay )

true or false

nativeWebTap

(Sim-only) 在Safari中允许"真实的",非基于 javascript 的 web 点击 (tap) 。默认值:false。注意:取决于 viewport 大小/比例, 点击操作不一定能精确地点中对应的元素。

true or false

safariInitialUrl

(Sim-only) (>= 8.1) 初始化 safari 的时使用的地址。默认是一个本地的欢迎页面

e.g.https://www.github.com

safariAllowPopups

(Sim-only) 允许 javascript 在 Safari 中创建新窗口。默认保持模拟器当前设置。

true or false

safariIgnoreFraudWarning

(Sim-only) 阻止 Safari 显示此网站可能存在风险的警告。默认保持浏览器当前设置。

true or false

safariOpenLinksInBackground

(Sim-only) Safari 是否允许链接在新窗口打开。默认保持浏览器当前设置。

true or false

keepKeyChains

(Sim-only) 当 Appium 会话开始/结束时是否保留存放密码存放记录 (keychains) (库(Library)/钥匙串(Keychains))

true or false

localizableStringsDir

从哪里查找本地化字符串。默认值 en.lproj

en.lproj

processArguments

通过 instruments 传递到 AUT 的参数

e.g., -myflag

interKeyDelay

以毫秒为单位,按下每一个按键之间的延迟时间

e.g., 100

showIOSLog

是否在 Appium 的日志中显示设备的日志。默认值 false

true or false

sendKeyStrategy

输入文字到文字框的策略。模拟器默认值:oneByOne (一个接着一个) 。真实设备默认值:grouped (分组输入)

oneByOne, grouped orsetValue

screenshotWaitTimeout

以秒为单位,生成屏幕截图的最长等待时间。默认值:10

e.g., 5

waitForAppScript

用于判断 "应用是否被启动” 的 iOS 自动化脚本代码。默认情况下系统等待直到页面内容非空。结果必须是布尔类型。

e.g. true;,target.elements().length > 0;, $.delay(5000); true;

appName

在测试时显示应用的名字.在ios 9+下自动化的时候

e.g., UICatalog

customSSLCert

(Sim/Emu-only) 添加一个SSL证书给模拟器

e.g. -----BEGIN CERTIFICATE-----MIIFWjCCBEKg...-----END CERTIFICATE-----

  • WDA参数

Capability

Description

Values

noReset

测试后不要销毁或关闭模拟器。开始测试运行在任何模拟器运行,或设备。默认false

true, false

processArguments

进程参数和环境发送到WebDriverAgent服务器的环境。

{ args: ["a", "b", "c"] , env: { "a": "b", "c": "d" } } 要么'{"args": ["a", "b", "c"], "env": { "a": "b", "c": "d" }}'

wdaLocalPort

用来转发mac电脑上到设备上与wda通信的端口。默认值与WDA在设备上使用的端口号相同。

例如, 8100

showXcodeLog

是否显示用于运行测试的Xcode命令的输出日志。如果是true,在启动时会有很多额外的日志记录。默认为false

例如, true

iosInstallPause

在安装应用程序和在设备上启动WebDriverAgent之间暂停的时间(以毫秒为单位)。特别用于较大的应用程序时。默认为0

例如, 8000

xcodeOrgId

Apple开发者团队标识符字符串 必须配合使用xcodeSigningId才能生效。

例如, JWL241K123

xcodeSigningId

表示签名证书的字符串。必须与xcodeOrgId一起使用。这通常只是iPhone Developer,所以默认(如果不包括)是iPhone Developer

例如, iPhone Developer

xcodeConfigFile

一个可选的Xcode配置文件的完整路径,指定在真实设备上运行WebDriverAgent的代码签名身份和团队。

例如,/path/to/myconfig.xcconfig

updatedWDABundleId

在真实设备上构建和启动之前,必须将bundleID更新到WDA。该bundleID必须是有效的。

例如,io.appium.WebDriverAgentRunner

keychainPath

从系统钥匙串导出的私人开发密钥的完整路径。与keychainPassword在真实设备上测试时一起使用。

例如,/path/to/MyPrivateKey.p12

keychainPassword

解锁钥匙串的密码keychainPath。

例如, super awesome password

scaleFactor

模拟器比例。如果模拟设备的默认分辨率大于实际的显示分辨率,这很有用。所以你可以缩放模拟器来查看整个设备的屏幕而不用滚动。

运行Xcode SDK 8和更旧版本的模拟器的可接受值是:'1.0', '0.75', '0.5', '0.33' and '0.25',其中'1.0'表示100%的比例。对于运行Xcode SDK 9和更高版本的模拟器,该值可以是任何有效的正浮点数。该参数必须是字符串类型。

usePrebuiltWDA

跳过运行WDA应用程序的构建阶段。只适用于Xcode 8+。默认为false。

例如, true

preventWDAAttachments

将只读权限设置为Xcode DerivedData中WebDriverAgent根的附件子文件夹。这是防止XCTest框架创建大量不必要的屏幕截图和日志所必需的,在使用Apple提供的编程接口的XCTest @ Xcode9之前,这是不可能关闭的。

将参数设置为true将文件夹的POSIX权限设置为555,false并将其重置为755。false默认情况下,如果Xcode SDK是在版本9或更高版本,否则true

webDriverAgentUrl

如果提供,Appium将连接到此URL上的现有WebDriverAgent实例,而不是启动一个新的实例。

例如, http://localhost:8100

useNewWDA

如果true强制卸载设备上任何现有的WebDriverAgent应用程序。如果要为每个会话应用WebDriverAgent的不同启动选项,请将其设置为true。虽然,只保证在模拟器上工作稳定。真正的设备需要WebDriverAgent客户端运行尽可能长的时间,而不需要重新安装/重新启动,以避免像https://github.com/facebook/WebDriverAgent/issues/507这样的问题。该false值(驱动程序版本2.35.0以后的默认行为)将尝试检测当前正在运行的WDA侦听器,并在可能的情况下重用它,强烈建议用于真实设备测试并加快多个套件一般的测试。将在默认URL(http:// localhost:8100)上触发新的WDA会话)如果WDA不在监听并且webDriverAgentUrl功能没有设置。功能的负/未设值useNewWDA在xcuitest驱动程序版本2.35.0之前不起作用。

例如, true

wdaLaunchTimeout

时间,以毫秒为单位,等待WebDriverAgent是可以ping通的。默认为60000ms。

例如, 30000

wdaConnectionTimeout

超时,以毫秒为单位,等待WebDriverAgent的响应。默认为240000ms。

例如, 1000

resetOnSessionStartOnly

是否在测试会话结束(false)或不(true)时执行重置。保持此变量设置为true并且Simulator运行(自版本1.6.4起的默认行为)可能会显着缩短测试会话初始化的持续时间。

true或false。默认为true

commandTimeouts

WDA后端命令执行的自定义超时(以毫秒为单位)。如果WDA后端意外冻结或需要太多时间来失败并阻止自动化测试执行,这可能会很有用。该值预期为字符串类型,并且可以包含最大毫秒数,以便在强制终止会话之前等待每个WDA命令的执行或有效的JSON字符串,其中键是内部的Appium命令名称(可以在日志中找到这些命令,查找“执行命令'command_name'”记录),值是以毫秒为单位的超时值。您还可以设置“默认”键,为未明确枚举为JSON密钥的所有其他命令分配超时值。

'120000', '{"findElement": 40000, "findElements": 40000, "setValue": 20000, "default": 120000}'

wdaStartupRetries

尝试构建WebDriverAgent到设备上的次数。默认为2。

例如, 4

wdaStartupRetryInterval

时间,以毫秒为单位,尝试构建和启动WebDriverAgent。默认为10000ms。

例如, 20000

connectHardwareKeyboard

将此选项设置为true在Simulator中启用硬件键盘。它被设置为false默认,因为这有助于解决一些XCTest错误。

true 要么 false

maxTypingFrequency

用于键入和清除的点击最大频率。如果您的测试由于输入错误而失败,您可能需要调整。默认为每分钟60次击键。

例如, 30

simpleIsVisibleCheck

使用本地方法来确定元素的可见性。在某些情况下,这需要很长时间。设置此功能false将使系统使用元素的位置和大小,以确保它们在屏幕上可见。但是,这可能会在某些情况下导致错误结果。默认为false,除了默认的iOS 9.3是 true。

例如true,false

useCarthageSsl

使用SSL下载WebDriverAgent的依赖关系。默认为false

例如, true

shouldUseSingletonTestManager

在WebDriverAgent中使用默认代理进行测试管理。设置此false有时帮助套接字挂断问题。默认为true。

例如, false

startIWDP

如果您想要自动启动ios_webkit_debug代理服务器来访问iOS上的webview,请将其设置为true。参数只适用于真实设备的设备自动化。默认为false。

例如, true

calendarAccessAuthorized

将其设置为true,如果要启用给定bundleId在IOS模拟器日历访问。设置为false,如果你想禁用IOS模拟器的日历访问与给定的bundleId。如果未设置,日历授权状态将不会被设置。

例如, true

isHeadless

如果在模拟器上运行自动化测试,并且不需要显示设备显示,则将此功能设置为true。这只是Xcode9以后的效果,只能用于模拟器。所有正在运行的模拟器用户界面的实例将自动终止,如果无头测试开始。false是默认值。

例如, true

webkitDebugProxyPort

用于与ios-webkit-debug-proxy进行通信的本地端口号。只与真实设备有关。默认值等于27753。

例如 20000

useXctestrunFile

使用Xctestrun文件启动WDA。它会搜索这样的文件bootstrapPath。文件的预期名称是WebDriverAgentRunner_iphoneos-arm64.xctestrun真实的设备和WebDriverAgentRunner_iphonesimulator-x86_64.xctestrun模拟器。我们可以做build-for-testing的WebDriverAgent项目模拟器和真正的设备,然后你会看到类似这样的产品文件夹,你需要在复制该文件夹的内容bootstrapPath位置。因为,这个功能期望你已经建立了WDA项目,它既不检查你是否有必要的依赖建立,WDA也不是试图建立项目。默认为false

例如, true

absoluteWebLocations

这个功能将指导Get Element Location在webviews中使用的命令返回相对于页面原点的坐标,而不是相对于当前的滚动偏移量。这个功能在webview之外没有任何效果。默认false。

例如, true

simulatorWindowCenter

允许显式设置Xcode9 + SDK的Simulator窗口中心的坐标。此功能只有在Simulator窗口尚未在当前会话中打开时才起作用。

例如,{-100.0,100.0}或者{500,500},不允许有空格

useJSONSource

从WDA获取JSON源并在Appium服务器上解析XML。这可以更快,特别是在大型设备上。默认为false。

例如, true

07 元素定位

定位方式

原生app界面对应属性

H5界面对应属性

By.ID

x

id

By.XPATH

//XCUIElementTypeButton

//div

By.NAME

×

name

MobileBy.MobileBy.IOS_PREDICATE

label == "登录" AND name == "登录" AND type == "XCUIElementTypeButton"

×

MobileBy.IOS_CLASS_CHAIN

picture

x

MobileBy.ACCESSIBILITY_ID

name

×

By.TAG_NAME

×

标签名

By.LINK_TEXT

×

a标签的文字

By.PARTIAL_LINK_TEXT

×

a标签的文字

By.CSS_SELECTOR

×

css表达式

By.CLASS_NAME

type

class

MobileBy.MobileBy.IOS_PREDICATE 定位补充:

MobileBy.MobileBy.IOS_PREDICATE 定位方式主要是以元素属性进行定位,可以多个可以模糊匹配等等

属性等于=:

driver.find_element(MobileBy.IOS_PREDICATE,'name = "书影音"')

属性模糊匹配LIKE:

driver.find_element(MobileBy.IOS_PREDICATE,'name LIKE "*书影音"')

属性包含CONTAINS:

driver.find_element(MobileBy.IOS_PREDICATE,'name CONTAINS "影"')

属性值开头匹配BEGINSWITH:

driver.find_element(MobileBy.IOS_PREDICATE,'name BEGINSWITH "书影"')

属性值结尾匹配ENDSWITH:

driver.find_element(MobileBy.IOS_PREDICATE,'name ENDSWITH "音"').click()

多属性同时匹配AND:

driver.find_element(MobileBy.IOS_PREDICATE,'name = "书影音" AND label="书影音"')

多属性或者匹配OR:

driver.find_element(MobileBy.IOS_PREDICATE,'name = "书影音" OR label="书影音"')

比较运算符>、<、==、>=、<=、!=:

driver.find_element(MobileBy.IOS_PREDICATE,'value>100')

driver.find_element(MobileBy.IOS_PREDICATE,'value<100')

driver.find_element(MobileBy.IOS_PREDICATE,'value!=100')

正则匹配MATCHES:

driver.find_element(MobileBy.IOS_PREDICATE,'name MATCHES "正则表达式"')

MobileBy.IOS_CLASS_CHAIN 定位补充:

MobileBy.IOS_CLASS_CHAIN定位方式和xpath极其相似,也是按照元素层级和元素属性进行定位的

#查找type属性为XCUIElementTypeSecureTextField并且value为请输入密码的元素

driver.find_element(MobileBy.IOS_CLASS_CHAIN,'**/XCUIElementTypeSecureTextField[`value== "请输入密码"`]')

#查找type属性为XCUIElementTypeSecureTextField的第一个

driver.find_element(MobileBy.IOS_CLASS_CHAIN,'**/XCUIElementTypeSecureTextField[1]')

08 driver常用相关api

  • 获取屏幕分辨率

driver.get_window_size()['width'] #获取屏幕的宽

driver.get_window_size()['height'] #获取屏幕的高
  • 整屏滑动

# 起始点坐标200,700   结束点坐标200,100  持续时间500毫秒

driver.swipe(200,700,200,100,500)
  • 启动激活第三方app

# 启动已安装的某个应用,参数第一个是应用的

bundleiddriver.activate_app('com.tencent.xin')
  • 设备横竖屏相关操作

#获取设备横竖屏方向,PORTRAIT表示竖屏,LANDSCAPE表示横屏

driver.orientation

#设置设备为横屏

driver.orientation = 'landscape'

# 设置设备为竖屏

driver.orientation = 'portrait'
  • app安装卸载相关

#判断app是否安装,参数是app的包名称

driver.is_app_installed('com.tencent.xin')

#安装app,参数是安装包路径

driver.install_app('C:\\Users\\lixio\\Desktop\\douban.ipa')

#卸载app,参数是包名称

driver.remove_app('com.tencent.xin')
  • 重启当前待测app

#重新启动

appdriver.reset()
  • 重新运行app,注意该方法会重建session

driver.launch_app()
  • 关闭app,只针对当前测试的app

driver.close_app()
  • 获取设备时间

driver.device_time
  • context相关操作,主要用于混合app操作webview界面时

#获取当前context

driver.current_context

#获取当前所有context

driver.contexts

#切换到混合webview界面的context

driver.switch_to.context('WEBVIEW_XXX')

#切换到原生切换的context

driver.switch_to.context('NATIVE_APP')
  • 设备屏幕相关操作

#判断设备是否锁屏

driver.is_locked()

#解锁屏幕,让屏幕亮起来

driver.unlock()

#锁定屏幕,可以传参锁几秒

driver.lock()
  • 键盘隐藏,不是很管用

driver.hide_keyboard(key_name='NEXT')

#点键盘上的NEXT键隐藏

driver.hide_keyboard(key_name='DONE')

#点键盘上的DONE键隐藏

driver.hide_keyboard()

09 元素特有相关api

  • 获取元素属性

element.get_attribute('enabled')

element.get_attribute('index')

element.get_attribute('label')

element.get_attribute('name')

element.get_attribute('selected')

element.get_attribute('type')

element.get_attribute('value')

element.get_attribute('wdRect')
  • 获取元素相关坐标

element.location.get('x') #获取元素起始点

xelement.location.get('y') #获取元素起始点

yelement.size.get('width') #获取元素的宽

element.size.get('height') #获取元素的高

010 手势相关api

  • 多点移动

action = TouchAction(driver=driver)

# 多个坐标点移动

action.press(x=320,y=200).move_to(x=320,y=400).move_to(x=400,y=500).release().perform()

#多个元素移动

action.press(element=element).move_to(element=element1).move_to(element=element2).release().perform()
  • 拖拽

action = TouchAction(driver=driver)

# 拖拽坐标点

action.press(x=320,y=400).wait(3000).move_to(x=320,y=800).release().perform()

#拖拽元素

action.press(element=element).wait(3000).move_to(element=element1).release().perform()
  • 长按

action = TouchAction(driver=driver)

# 长按某个坐标点

action.long_press(x=320,y=400).release().perform()

# 长按某个元素

action.long_press(element=element).release().perform()
  • 单击tap

action = TouchAction(driver=driver)

# 单击某个坐标点

action.tap(x=320,y=400).perform().release()

# 单击某个元素

action.tap(element=element).perform().release()

011 混合app处理

  • 开启电脑safari开发者选项

    打开电脑的safari浏览器,按照下述步骤操作

    picture

    picture

    设置完成后在顶部菜单可以看到【开发】菜单

  • 设置手机safari浏览器

    Settings-->Safari-->Advanced-->Web Inspector (open)

  • View element information

    Open the webview page of the app to be tested on the mobile phone, and then do the following operations on the computer

    picture

    After clicking, the developer tools are opened, which is the same as the positioning on the web side

    picture

  • code processing

    When testing the webview interface, you need to switch the driver to the context of the webview before you can locate the element

    The switching code is as follows:

# 为什么要做个循环,是因为在获取webview的context时不稳定

# 循环10次获取,每次间隔一秒

count = 10

while count>0: 

     time.sleep(1) 

    # 获取当前所有的context 

     contexts = driver.contexts 

     for context in contexts:     

          if 'WEBVIEW' in context:

                 driver.switch_to.context(context)         

                 count = 0 

count -= 1

After the driver is switched, you can operate according to the positioning operation method on the web side

012 H5 page processing

The H5 page on the mobile phone can be understood as an app page opened by a browser, which is actually a web page. The viewing method of H5 elements opened by the safari browser on an ios mobile phone is the same as step 10. The difference lies in the difference in the initialization parameters of the driver .

desired_caps = {   

         "platformName": "ios",   

         "deviceName": "iPhone12",   

         "automationName": "XCuiTest",   

         "platformVersion": "14.1",   

         "udid": "00008101-001038A23AC0001E",   

         "usePrebuiltWDA": True,   

         "noReset": False,   

         "wdaLocalPort": 8101,   

         "showXcodeLog": True,   

         "autoAcceptAlerts": True,   

         "newCommandTimeout":600,   

         "browserName":"Safari" #指定浏览器

}

The basic operation method is the same as that on the web side

Finally: The complete software testing video tutorial below has been sorted out and uploaded, and friends who need it can get it by themselves [Guaranteed 100% free]

Software Testing Interview Documentation

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.

Guess you like

Origin blog.csdn.net/AI_Green/article/details/132482614