【发布时间】:2020-07-21 22:31:21
【问题描述】:
我正在使用 React Native 开发应用程序,但在使用 Appium 框架进行自动化测试时遇到了困难。
我从未使用过该工具,我的第一个目标是检查主屏幕上是否存在以下元素。 PS:元素存在。
<TouchableOpacity
testID="test-login"
accessibilityLabel="test-login"
>
<Text>test login</Text>
</TouchableOpacity>
在项目中,我使用 sample.test.js 文件创建了 test 文件夹
const webdriverio = require('webdriverio');
const androidOptions = {
capabilities: {
browserName: 'Chrome',
allowInsecure: {},
denyInsecure: {},
},
desiredCapabilities: {
browserName: 'Chrome',
path: '/wd/hub',
port: 4723,
platformName: 'Android',
app:
'/Users/xxx/android/app/build/outputs/apk/debug/app-debug.apk',
deviceName: 'xxx', // adb devices
automationName: 'Appium',
appPackage: 'XXX',
launchActivity: 'XXX.MainApplication',
chromeOptions: {w3c: false},
ensureWebviewsHavePages: true,
platformVersion: '8.0.0',
},
};
describe('things', () => {
let client;
before(async () => {
client = await webdriverio.remote(androidOptions);
});
it('test', async () => {
//await client.elementByAccessibilityId('test-login');
//client.elementsByAccessibilityId('test-login');
await client.findElementsByAccessibilityId('test-login');
//let elementsOne = await client.elementsByAccessibilityId('test-login');
//let elementsTwo = await client.elements('id', 'test-login');
//await client.elementByAccessibilityId('test-login').isClickable;
});
after(async () => {
return await client.deleteSession();
});
});
并使用 node ./node_modules/.bin/mocha 运行它。
输出是
things
INFO webdriverio: Initiate new session using the devtools protocol
INFO devtools: Launch Google Chrome with flags: --disable-extensions --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-sync --metrics-recording-only --disable-default-apps --mute-audio --no-first-run --disable-hang-monitor --disable-prompt-on-repost --disable-client-side-phishing-detection --password-store=basic --use-mock-keychain --disable-component-extensions-with-background-pages --disable-breakpad --disable-dev-shm-usage --disable-ipc-flooding-protection --disable-renderer-backgrounding --enable-features=NetworkService,NetworkServiceInProcess --disable-features=site-per-process,TranslateUI,BlinkGenPropertyTrees --window-position=0,0 --window-size=1200,900
INFO devtools: Connect Puppeteer with browser on port 51345
1) test
✓ should create and destroy Android browser session
INFO devtools: COMMAND deleteSession()
INFO devtools: RESULT null
0 passing (1s)
1 failing
1) things
test:
TypeError: client.findElementsByAccessibilityId is not a function
at Context.it (test/sample.test.js:97:18)
at process.topLevelDomainCallback (domain.js:126:23)
应用程序处于调试模式的安卓手机已连接到电脑。
我已经尝试过 sn-ps 但没有成功。
你能帮我迈出第一步吗?
谢谢大家。
【问题讨论】:
标签: react-native automated-tests appium appium-android