我有一个 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:消息:处理命令时发生未知的服务器端错误。原始错误:尝试在未打开的模式对话框上进行操作。
*test_normal 虽然有效。我试图注释掉test_normal,test_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 在 OS 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.
谁能帮我弄清楚发生了什么?