Skip to content

Commit

Permalink
replace appium button click steps
Browse files Browse the repository at this point in the history
  • Loading branch information
yousif-bugsnag committed Sep 16, 2024
1 parent 8a46d4f commit 9a6e2b9
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { View, Text, Button } from 'react-native'
import { createStackNavigator } from '@react-navigation/stack'
import { NavigationContainer } from '@react-navigation/native'

const delay = ms => new Promise(resolve => setTimeout(resolve, ms))

export class ReactNavigationBreadcrumbsDisabledScenario extends Scenario {
constructor (configuration, jsConfig) {
super()
Expand Down Expand Up @@ -37,40 +39,33 @@ export class ReactNavigationBreadcrumbsDisabledScenario extends Scenario {
}

function HomeScreen ({ navigation }) {
React.useEffect(() => {
(async () => {
Bugsnag.notify(new Error('HomeNavigationError'))
await delay(250)
navigation.navigate('Details')
})()
},[])

return (
<View style={ { flex: 1, alignItems: 'center', justifyContent: 'center' } }>
<Text>Home Screen</Text>
<Button title='Navigate'
accessibilityLabel='navigate'
onPress={ () => navigation.navigate('Details') }/>
<Button title='Notify handled error'
accessibilityLabel='sendHandled'
onPress={ () => Bugsnag.notify(new Error('HomeNavigationError')) }/>
<Button title='Set context'
accessibilityLabel='setContext'
onPress={ () => Bugsnag.setContext('homeSetContext') }/>
</View>
)
}

function DetailsScreen ({ navigation }) {
React.useEffect(() => {
(async () => {
Bugsnag.notify(new Error('DetailsNavigationError'))
await delay(250)
throw new Error('DetailsNavigationUnhandledError')
})()
},[])

return (
<View style={ { flex: 1, alignItems: 'center', justifyContent: 'center' } }>
<Text>Details Screen</Text>
<Button title='Navigate'
accessibilityLabel='navigate'
onPress={ () => navigation.navigate('Home') }/>
<Button title='Notify handled error'
accessibilityLabel='sendHandled'
onPress={ () => Bugsnag.notify(new Error('DetailsNavigationError')) }/>
<Button title='Notify unhandled error'
accessibilityLabel='sendUnhandled'
onPress={ () => {
throw new Error('DetailsNavigationUnhandledError')
} }/>
<Button title='Set context'
accessibilityLabel='setContext'
onPress={ () => Bugsnag.setContext('detailsSetContext') }/>
</View>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { View, Text, Button } from 'react-native'
import { createStackNavigator } from '@react-navigation/stack'
import { NavigationContainer } from '@react-navigation/native'

const delay = ms => new Promise(resolve => setTimeout(resolve, ms))

export class ReactNavigationBreadcrumbsEnabledScenario extends Scenario {
constructor (_configuration, jsConfig) {
super()
Expand Down Expand Up @@ -36,40 +38,33 @@ export class ReactNavigationBreadcrumbsEnabledScenario extends Scenario {
}

function HomeScreen ({ navigation }) {
React.useEffect(() => {
(async () => {
Bugsnag.notify(new Error('HomeNavigationError'))
await delay(250)
navigation.navigate('Details')
})()
},[])

return (
<View style={ { flex: 1, alignItems: 'center', justifyContent: 'center' } }>
<Text>Home Screen</Text>
<Button title='Navigate'
accessibilityLabel='navigate'
onPress={ () => navigation.navigate('Details') }/>
<Button title='Notify handled error'
accessibilityLabel='sendHandled'
onPress={ () => Bugsnag.notify(new Error('HomeNavigationError')) }/>
<Button title='Set context'
accessibilityLabel='setContext'
onPress={ () => Bugsnag.setContext('homeSetContext') }/>
</View>
)
}

function DetailsScreen ({ navigation }) {
React.useEffect(() => {
(async () => {
Bugsnag.notify(new Error('DetailsNavigationError'))
await delay(250)
throw new Error('DetailsNavigationUnhandledError')
})()
},[])

return (
<View style={ { flex: 1, alignItems: 'center', justifyContent: 'center' } }>
<Text>Details Screen</Text>
<Button title='Navigate'
accessibilityLabel='navigate'
onPress={ () => navigation.navigate('Home') }/>
<Button title='Notify handled error'
accessibilityLabel='sendHandled'
onPress={ () => Bugsnag.notify(new Error('DetailsNavigationError')) }/>
<Button title='Notify unhandled error'
accessibilityLabel='sendUnhandled'
onPress={ () => {
throw new Error('DetailsNavigationUnhandledError')
} }/>
<Button title='Set context'
accessibilityLabel='setContext'
onPress={ () => Bugsnag.setContext('detailsSetContext') }/>
</View>
)
}
58 changes: 39 additions & 19 deletions test/react-native/features/navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,42 @@ Feature: Navigation plugin features

Scenario: Navigating screens causes breadcrumbs and context to be updated
When I run "ReactNavigationBreadcrumbsEnabledScenario"
And I trigger a handled error
And I wait to receive an error
And I wait for 5 seconds
And I relaunch the app after a crash
And I configure Bugsnag for "ReactNavigationBreadcrumbsEnabledScenario"

And I wait to receive 3 errors
# Then the received errors match:
# | exceptions.0.message | unhandled | context |
# | HomeNavigationError | false | Home |
# | DetailsNavigationError | false | Details |
# | DetailsNavigationUnhandledError | true | Details |



# And I trigger a handled error
# And I wait to receive an error

Then the exception "message" equals "HomeNavigationError"
And the event "context" equals "Home"
And the event contains a breadcrumb matching the JSON fixture in "features/fixtures/expected_breadcrumbs/HomeReadyNavigation.json"
And I discard the oldest error

When I navigate to a different screen
And I trigger a handled error
And I wait to receive an error
# When I navigate to a different screen
# And I trigger a handled error
# And I wait to receive an error
Then the exception "message" equals "DetailsNavigationError"
And the event "context" equals "Details"
And the event contains a breadcrumb matching the JSON fixture in "features/fixtures/expected_breadcrumbs/HomeReadyNavigation.json"
And the event contains a breadcrumb matching the JSON fixture in "features/fixtures/expected_breadcrumbs/HomeToDetailsNavigation.json"
And I discard the oldest error

When I trigger an unhandled error
And I wait for 5 seconds
And I relaunch the app after a crash
And I configure Bugsnag for "ReactNavigationBreadcrumbsEnabledScenario"
And I wait to receive an error
# When I trigger an unhandled error
# And I wait for 5 seconds
# And I relaunch the app after a crash
# And I configure Bugsnag for "ReactNavigationBreadcrumbsEnabledScenario"
# And I wait to receive an error

Then the exception "message" equals "DetailsNavigationUnhandledError"
And the event "unhandled" is true
And the event "context" equals "Details"
Expand All @@ -32,25 +47,30 @@ Scenario: Navigating screens causes breadcrumbs and context to be updated

Scenario: Navigating when navigation breadcrumbs are disabled only updates context
When I run "ReactNavigationBreadcrumbsDisabledScenario"
And I trigger a handled error
And I wait to receive an error

And I wait for 5 seconds
And I relaunch the app after a crash
And I configure Bugsnag for "ReactNavigationBreadcrumbsDisabledScenario"

# And I trigger a handled error
# And I wait to receive an error
Then the exception "message" equals "HomeNavigationError"
And the event "context" equals "Home"
And the event does not have a "navigation" breadcrumb
And I discard the oldest error

When I navigate to a different screen
And I trigger a handled error
And I wait to receive an error
# When I navigate to a different screen
# And I trigger a handled error
# And I wait to receive an error
Then the exception "message" equals "DetailsNavigationError"
And the event "context" equals "Details"
And the event does not have a "navigation" breadcrumb
And I discard the oldest error

When I trigger an unhandled error
And I relaunch the app after a crash
And I configure Bugsnag for "ReactNavigationBreadcrumbsDisabledScenario"
And I wait to receive an error
# When I trigger an unhandled error
# And I relaunch the app after a crash
# And I configure Bugsnag for "ReactNavigationBreadcrumbsDisabledScenario"
# And I wait to receive an error
Then the exception "message" equals "DetailsNavigationUnhandledError"
And the event "unhandled" is true
And the event "context" equals "Details"
Expand Down

0 comments on commit 9a6e2b9

Please sign in to comment.