我在 Appium 和 react-native 之间的通信有问题。我在android上试过(现在)
这是我要测试的组件:
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
TouchableHighlight,
} from 'react-native';
export default class HomeScreen extends Component {
static navigationOptions = {
title: 'myAwesomeApp',
};
render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<Text onPress={() => navigate('Registration')}>
BleedRegistration
</Text>
<Text onPress={() => navigate('Log')}>
MedicationLog
</Text>
<TouchableHighlight id={'XXXX1'} accessibilityLabel={'XXXX'} onPress={() => navigate('Reporting')}>
<Text id={'XXXX2'} accessibilityLabel={'XXXX3'}>
Reports1
</Text>
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
alignItems: 'center',
justifyContent: 'space-around',
},
});
这是我的测试课:
import os
import unittest
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
class AppiumTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities={
'app': os.path.expanduser('./android/app/build/outputs/apk/app-debug.apk'),
'platformName': 'Android',
'deviceName': 'Nexus 5 API 25',
})
def tearDown(self):
self.driver.quit()
class ElementsExistTests(AppiumTest):
def test_elements(self):
textBleedRegistration = self.driver.find_elements_by_accessibility_id("BleedRegistration")
textMedicationLog = self.driver.find_elements_by_accessibility_id("MedicationLog")
textReports1 = self.driver.find_elements_by_accessibility_id("Reports1")
myTouchableHighligh = self.driver.find_elements_by_accessibility_id("XXXX1")
self.assertIsNotNone(textRegistration)
self.assertIsNotNone(textLog)
self.assertIsNotNone(textReports1)
self.assertIsNotNone(myTouchableHighligh)
class ClickTests(AppiumTest):
def test_reports(self):
myTouchableHighligh = self.driver.find_elements_by_accessibility_id("XXXX1")
#textReports1 = self.driver.find_elements_by_accessibility_id("Reports1")
action = TouchAction(self.driver)
action.press(myTouchableHighligh).perform()
self.assertIsNotNone(myTouchableHighligh)
这是appium服务器中的错误日志:
self = <test.ClickTests testMethod=test_reports>
def test_reports(self):
myTouchableHighligh = self.driver.find_elements_by_accessibility_id("XXXX1")
#textReports1 = self.driver.find_elements_by_accessibility_id("Reports1")
action = TouchAction(self.driver)
> action.press(myTouchableHighligh).perform()
test.py:43:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/local/lib/python2.7/site-packages/appium/webdriver/common/touch_action.py:53: in press
self._add_action('press', self._get_opts(el, x, y))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <appium.webdriver.common.touch_action.TouchAction object at 0x10d698c90>, element = [], x = None, y = None, duration = None
def _get_opts(self, element, x, y, duration = None):
opts = {}
if element is not None:
> opts['element'] = element.id
E AttributeError: 'list' object has no attribute 'id'
/usr/local/lib/python2.7/site-packages/appium/webdriver/common/touch_action.py:118: AttributeError
第一个测试ElementsExistTests
通过了……没关系,在第二个测试中我想点击其中一个<Text>
或<TouchableHighlight>
但我不能,因为AttributeError: 'list' object has no attribute 'id'
我尝试了简单的方法(作为一些教程)并像这样写
def test_reports(self):
myTouchableHighligh = self.driver.find_elements_by_accessibility_id("XXXX1")
myTouchableHighligh.click()
self.assertIsNotNone(myTouchableHighligh)
这会返回AttributeError: 'list' object has no attribute 'click'
相同的错误myTouchableHighligh.tap()
你能帮我看看有什么问题吗?