-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VBLOCKS-3535] feat: proof of concept appium testing #438
Open
mhuynh5757
wants to merge
1
commit into
feature/appium
Choose a base branch
from
task/appium-poc
base: feature/appium
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
|
||
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> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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.