Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/app/appium/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const capabilities = {
'platformName': 'Android',
'appium:automationName': 'UiAutomator2',
'appium:deviceName': 'Android',
'appium:appPackage': 'com.example.twiliovoicereactnative',
'appium:appActivity': '.MainActivity',
'appium:autoGrantPermissions': 'true',
};

const webdriverioOptions = {
hostname: process.env.APPIUM_HOST || 'localhost',
port: parseInt(process.env.APPIUM_PORT, 10) || 4723,
logLevel: 'info',
capabilities,
};

module.exports = {
capabilities,
webdriverioOptions,
};
18 changes: 18 additions & 0 deletions test/app/appium/outgoingCall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { remote } = require('webdriverio');
const { webdriverioOptions } = require('./config');

async function runTest() {
const driver = await remote(webdriverioOptions);

try {
await driver.pause(5000);
const runTestButton = driver.$('~runTest');
await runTestButton.click();
await driver.pause(10000);
} finally {
await driver.pause(1000);
await driver.deleteSession();
}
}

runTest().catch(console.error);
4 changes: 2 additions & 2 deletions test/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { AppRegistry } from 'react-native';
import App from './src/App';
import OutgoingCallTest from './src/e2e/OutgoingCall';
import { name as appName } from './app.json';

AppRegistry.registerComponent(appName, () => App);
AppRegistry.registerComponent(appName, () => OutgoingCallTest);
3 changes: 2 additions & 1 deletion test/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"metro-react-native-babel-preset": "0.76.8",
"prettier": "^2.4.1",
"react-test-renderer": "18.2.0",
"typescript": "4.8.4"
"typescript": "4.8.4",
"webdriverio": "^9.2.1"
},
"engines": {
"node": ">=16"
Expand Down
85 changes: 85 additions & 0 deletions test/app/src/e2e/OutgoingCall.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as React from 'react';
import { Button, Text, View } from 'react-native';
import { Call, Voice } from '@twilio/voice-react-native-sdk';
import { generateAccessToken } from '../tokenUtility';

type TestStatus = 'not-started' | 'running' | 'success' | 'failed';

type TestHook = () => { status: TestStatus; run: () => Promise<void> };

async function settlePromise<T>(
p: Promise<T>
): Promise<{ result: 'ok' | 'err'; value: T }> {
return p
.then((value) => ({ result: 'ok' as const, value }))
.catch((value) => ({ result: 'err' as const, value }));
}

const useOutgoingCallTest: TestHook = () => {
const testId = React.useMemo(() => Date.now(), []);
const voice = React.useMemo(() => new Voice(), []);
const accessToken = React.useMemo(() => generateAccessToken(), []);

const [status, setStatus] = React.useState<TestStatus>(() => 'not-started');

const run = React.useCallback(async () => {
setStatus('running');

const call = await voice.connect(accessToken);

const connectedPromise = new Promise<'connected'>((resolve) => {
call.on(Call.Event.Connected, () => {
console.log(testId, 'call event connected');
resolve('connected');
});
});

const connectFailurePromise = new Promise<'connectFailure'>((resolve) => {
call.on(Call.Event.ConnectFailure, (error) => {
console.log(testId, 'call event connectFailure', error);
resolve('connectFailure');
});
});

const callStatus = await Promise.any([
connectedPromise,
connectFailurePromise,
]);

if (callStatus === 'connectFailure') {
setStatus('failed');
return;
}

await new Promise((resolve) => {
setTimeout(resolve, 5000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the manual wait time still necessary? appium doesn't have a way to .wait?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So appium does have a way to wait, but the way I set up the test such that each test is it's own UI and each hook is it's own test run time means that appium isn't in control here. At this point, it's app code, and the appium wait is more similar to how jest waits for tests to finish since appium is the test runner.

});

const disconnectResult = await settlePromise(call.disconnect());
if (disconnectResult.result === 'err') {
setStatus('failed');
console.log(testId, 'disconnect promise failed', disconnectResult.value);
return;
}

setStatus('success');
}, [accessToken, testId, voice]);

return { run, status };
};

export default function OutgoingCallTest() {
const { run, status } = useOutgoingCallTest();

return (
<View>
<Text accessible={true} accessibilityLabel="testName">
outgoingCallTest
</Text>
<Button accessibilityLabel="runTest" title="Run Test" onPress={run} />
<Text accessible={true} accessibilityLabel="testStatus">
{status}
</Text>
</View>
);
}
Loading