gpt4 book ai didi

python - Appium Python WebDriverWait wait.until(expected_conditions.alert_is_present()) 随机失败

转载 作者:太空宇宙 更新时间:2023-11-03 14:00:01 27 4
gpt4 key购买 nike

我有一个 Appium 测试类来测试 iOS 应用程序,其中有两个几乎相同的测试:

def test_fail(self):
self.log_in('invalid_user_1')
self.wait.until(expected_conditions.alert_is_present())
alert = self.driver.switch_to.alert
assert "Your mobile number is not registered with us" in alert.text
alert.accept()

def test_normal(self):
self.log_in('empty')
self.wait.until(expected_conditions.alert_is_present())
alert = self.driver.switch_to.alert
assert 'Please enter mobile number' in alert.text
alert.accept()

当我运行测试时,test_fail(它在test_normal之前先运行),它总是无法捕获带有错误的警告对话框:

WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: An attempt was made to operate on a modal dialog when one was not open.

*test_normal 可以工作。我尝试注释掉 test_normaltest_fail 将失败并显示相同的消息。

然后我尝试注释掉 test_fail,但这次 test_normal 可以工作。因此,由于某些奇怪的原因,test_fail无法与self.wait.until(expected_conditions.alert_is_present())

一起使用

但是,如果我替换 test_fail 测试 wait.until 行:

self.wait.until(expected_conditions.alert_is_present())

与:

self.wait_for('OK')

然后一切都会正常。

self.wait 在 def setUp(self) 中声明 self.wait = WebDriverWait(self.driver, 120)

我在 Mac OS X 上运行 Appium 1.7.2 (Appium GUI 1.4.0)。测试 iOS 在操作系统 11.2 的 iPhone 7 模拟器上运行。

错误堆栈跟踪:

Error
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 331, in run
testMethod()
File "/Users/steve/Desktop/Temp/Appium/Ding_ios_aws/ios_aws/tests/test_invalid_login.py", line 16, in test_invalid_user_login
self.wait.until(expected_conditions.alert_is_present())
File "/Users/steve/venv/Appium/lib/python2.7/site-packages/selenium/webdriver/support/wait.py", line 71, in until
value = method(self._driver)
File "/Users/steve/venv/Appium/lib/python2.7/site-packages/selenium/webdriver/support/expected_conditions.py", line 387, in __call__
alert = driver.switch_to.alert
File "/Users/steve/venv/Appium/lib/python2.7/site-packages/selenium/webdriver/remote/switch_to.py", line 55, in alert
alert.text
File "/Users/steve/venv/Appium/lib/python2.7/site-packages/selenium/webdriver/common/alert.py", line 69, in text
return self.driver.execute(Command.GET_ALERT_TEXT)["value"]
File "/Users/steve/venv/Appium/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/Users/steve/venv/Appium/lib/python2.7/site-packages/appium/webdriver/errorhandler.py", line 29, in check_response
raise wde
WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: An attempt was made to operate on a modal dialog when one was not open.

谁能帮我弄清楚发生了什么事吗?

test_normal对话框屏幕图像 image of the dialog of test_normal

test_fail 对话框屏幕图像 image of the dialog of test_fail

最佳答案

您很可能遇到了错误 https://github.com/appium/appium/issues/10286 .

错误:在警报本身的第一次 ping/检查中,如果警报不存在,Appium 将抛出异常而不等待给定时间。

此错误是最近记录的(15 天前)。尝试最新版本。我认为它在最新版本测试版中已修复。

另请参阅https://github.com/facebook/WebDriverAgent/issues/857 ,它说这是 Appium 问题,而不是 WebDriver。

临时解决方案:添加 1-3 秒的 sleep 时间,以确保在检查明确条件之前存在警报。

关于python - Appium Python WebDriverWait wait.until(expected_conditions.alert_is_present()) 随机失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49322696/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com