python - 如何在 Python 中调试 iOS Selenium 测试

标签 python ios selenium debugging appium

我正在尝试在 Debug模式下运行 iOS Selenium 测试。我正在使用 Appium,一个 iOS 模拟器 (Xcode),并用 Python 编写测试。

一旦代码到达断点,我就可以看到所有变量,但几秒钟后,我没有看到它们的值,而是得到以下异常:

session 已终止或未启动

即使我可以看到模拟器仍在运行,也会发生这种情况。

我尝试在网上查找但找不到解决方案,您能帮忙吗? 谢谢!

最佳答案

您可能想要增加newCommandTimeout Desired Capability value到可以让您检查元素值的东西。将超时增加到 5 分钟的相关代码行是:

desired_caps['newCommandTimeout'] = '300' 

完整的初始化例程以防万一:

from appium import webdriver

desired_caps = {}
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '12.3'
desired_caps['automationName'] = 'xcuitest'
desired_caps['deviceName'] = 'iPhone SE'
desired_caps['newCommandTimeout'] = '300'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

这样,Appium 将等待来自客户端(您的代码)的新命令 5 分钟,然后再考虑客户端空闲并终止 session ,这应该足以启用调试,如果需要,可以随意增加更多。

您还可以考虑切换到 Appium Studio这让您在检查移动布局、管理 iOS 设备/配置文件、自动为元素生成唯一的 XPath 定位器以及拥有 extra set of Desired Capabilities 时变得更加轻松。让您更快地处理边缘情况

关于python - 如何在 Python 中调试 iOS Selenium 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56431737/

相关文章:

python - 从 python 和 MySQLdb 中的 Json 对象获取字符串

python - Tensorflow 不开始训练

Python 正则表达式 : string does not contain "jpg" and must have "-" and lowercase

ios - 为什么 UITableView cell separatorInset 默认为 15,而 View Controller 的 Root View Layout Margins 是 16?

c# - 如何在不丢失 cookie 的情况下刷新我的 Selenium ChromeDriver 实例?

java - 如何获得与通配符 css 选择器匹配的第二个元素?

python - 在 Python 中打印的列表项前面添加数字

ios - 图像选择器委托(delegate)错误 : cannot assign value of type

ios - 在 CoreData 的 fetchedObjects 中编辑多个对象

python - 如何让 Selenium 与 Scrapy 并行运行?