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 ead3991
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import Scenario from './Scenario'
import Bugsnag from '@bugsnag/react-native'
import BugsnagPluginReactNavigation from '@bugsnag/plugin-react-navigation'
import * as React from 'react'
import { View, Text, Button } from 'react-native'
import { View, Text } 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,35 @@ export class ReactNavigationBreadcrumbsDisabledScenario extends Scenario {
}

function HomeScreen ({ navigation }) {
React.useEffect(() => {
(async () => {
await delay(100)
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 () => {
await delay(100)
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 @@ -2,10 +2,12 @@ import Scenario from './Scenario'
import Bugsnag from '@bugsnag/react-native'
import BugsnagPluginReactNavigation from '@bugsnag/plugin-react-navigation'
import * as React from 'react'
import { View, Text, Button } from 'react-native'
import { View, Text } 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,35 @@ export class ReactNavigationBreadcrumbsEnabledScenario extends Scenario {
}

function HomeScreen ({ navigation }) {
React.useEffect(() => {
(async () => {
await delay(100)
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 () => {
await delay(100)
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>
)
}
32 changes: 13 additions & 19 deletions test/react-native/features/navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@ 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 relaunch the app after a crash
And I configure Bugsnag for "ReactNavigationBreadcrumbsEnabledScenario"
And I wait to receive 3 errors

# Handled error on Home screen
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
# Handled error on Details screen
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
# Unhandled error on Details screen
Then the exception "message" equals "DetailsNavigationUnhandledError"
And the event "unhandled" is true
And the event "context" equals "Details"
Expand All @@ -32,25 +29,22 @@ 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 relaunch the app after a crash
And I configure Bugsnag for "ReactNavigationBreadcrumbsDisabledScenario"

# Handled error on Home screen
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
# Handled error on Details screen
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
# Unhandled error on Details screen
Then the exception "message" equals "DetailsNavigationUnhandledError"
And the event "unhandled" is true
And the event "context" equals "Details"
Expand Down
45 changes: 0 additions & 45 deletions test/react-native/features/steps/react-navigation-steps.rb

This file was deleted.

0 comments on commit ead3991

Please sign in to comment.