我已成功使用本演练https://www.appcoda.com/automated-ui-testing-appium/了解了appium的工作原理。我现在想使用此过程来测试自己的个人应用程序,但是在Python脚本上运行appium时,我从命令行收到以下错误消息。我正在尝试检查我的应用程序用户界面中是否存在usernameTextField。
错误消息:
> usernameTextField = self.driver.find_element_by_accessibility_id('usernameTextField')
response = {'status': 404, 'value': '{"value":{"error":"no such element","message":"An element could not be located on the page u....doNativeFind (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/find.js:130:13)"}}'}
> raise wde
E NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
我的Python脚本:
import unittest
import os
from random import randint
from appium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys
class LoginTests(unittest.TestCase):
def setUp(self):
app = ('/Users/ross/Desktop/gameApp/build/Release-iphonesimulator/GameApp.app')
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities={
'app': app,
'platformName': 'iOS',
'platformVersion': '12.1',
'deviceName': 'iPhone XR',
'bundleId':'com.brian.gameApp'
}
)
def tearDown(self):
self.driver.quit()
def testInstitutionField(self):
sleep(3)
usernameTextField = self.driver.find_element_by_accessibility_id('usernameTextField')
institutionField.send_keys('Name')
institutionField.send_keys(Keys.RETURN)
sleep(1)
self.assertEqual(usernameTextField.get_attribute("value"), 'Name')
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(LoginTests)
unittest.TextTestRunner(verbosity=2).run(suite)
我如何在obj C中设置元素
self.usernameTextField.isAccessibilityElement = YES;
self.usernameTextField.accessibilityIdentifier = @"usernameTextField";
我已经按照演练尝试在代码和情节提要中都设置了accessibilityIdentifier,但是似乎都没有用。
模拟器当前已打开并运行,但是找不到场景/测试中列出的元素。