Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
buenaflor committed Oct 16, 2024
1 parent 8136019 commit 20c2d7e
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 20 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/e2e_flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ jobs:
model: "iPhone 15"
os_version: "17.5"
- name: Build App
# if: env.SENTRY_AUTH_TOKEN != null
if: env.SENTRY_AUTH_TOKEN_E2E != null
run: |
flutter build ios --debug --simulator --obfuscate --split-debug-info=./
flutter build ios --debug --simulator --obfuscate --split-debug-info=./ --dart-define=SENTRY_AUTH_TOKEN_E2E=$SENTRY_AUTH_TOKEN_E2E
xcrun simctl install Booted build/ios/iphonesimulator/Runner.app
- name: Run Maestro
env:
MAESTRO_DRIVER_STARTUP_TIMEOUT: 1500000 # 25 min, CI can be slow at times
MAX_ATTEMPTS: 3 # Maestro test suits re runs in case of flakyness
run: maestro test flow.yaml

# analyze:
Expand Down
5 changes: 4 additions & 1 deletion e2e_test/flutter/flow.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
appId: io.sentry.samples.flutter_e2e
---
- launchApp
- tapOn: "Capture exception"
- assertVisible: 'Capture exception'
- tapOn: "Capture exception"
- assertVisible: "Sending exception to Sentry..."
- waitForAnimationToEnd
- assertVisible: "Event successfully received"
120 changes: 104 additions & 16 deletions e2e_test/flutter/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import 'package:flutter/material.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:http/http.dart';
import 'dart:convert';
import 'dart:io';

const _org = 'sentry-sdks';
const _projectSlug = 'sentry-flutter';
const _exampleDsn =
'https://e85b375ffb9f43cf8bdf9787768149e0@o447951.ingest.sentry.io/5428562';
const _token =
String.fromEnvironment('SENTRY_AUTH_TOKEN_E2E', defaultValue: '');
// flutter build apk --dart-define=SENTRY_AUTH_TOKEN_E2E=$SENTRY_AUTH_TOKEN_E2E works

Future<void> main() async {
if (_token.trim().isEmpty) {
print('AUTH TOKEN is not set');
exit(1);
}
await SentryFlutter.init(
(options) {
options.dsn =
'https://e85b375ffb9f43cf8bdf9787768149e0@o447951.ingest.sentry.io/5428562';
options.dsn = _exampleDsn;
// ignore: invalid_use_of_internal_member
options.automatedTestMode = true;
},
appRunner: () => runApp(MyApp()),
appRunner: () => runApp(const MyApp()),
);
}

Expand Down Expand Up @@ -44,25 +60,97 @@ class _MyHomePageState extends State<MyHomePage> {
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: const Text(
'Capture exception',
semanticsLabel: 'Capture Exception',
),
onTap: () {
try {
throw Exception('E2E test exception');
} catch (exception, stacktrace) {
Sentry.captureException(exception, stackTrace: stacktrace);
}
})
HttpRequestExample(),
],
),
),
);
}
}

class HttpRequestExample extends StatefulWidget {
const HttpRequestExample({super.key});

@override
HttpRequestExampleState createState() => HttpRequestExampleState();
}

class HttpRequestExampleState extends State<HttpRequestExample> {
String _responseText = 'Click the button to make a request';

Future<void> _makeRequest() async {
setState(() {
_responseText = 'Sending exception to Sentry...';
});

var id = const SentryId.empty();
try {
throw Exception('E2E Test Exception');
} catch (e, stacktrace) {
id = await Sentry.captureException(e, stackTrace: stacktrace);
}

final url = _eventUri(id);
final event = await _waitForEventToShowUp(url);

if (event != null) {
setState(() {
_responseText = 'Event successfully received';
});
} else {
setState(() {
_responseText = 'Failed to receive event';
});
}
}

@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _makeRequest,
child: const Text(
'Capture Exception',
semanticsLabel: 'Capture Exception',
),
),
Text(
_responseText,
semanticsLabel: _responseText,
),
],
);
}
}

Future<Map<String, dynamic>?> _waitForEventToShowUp(Uri url) async {
final client = Client();

for (var i = 0; i < 10; i++) {
print('Try no. $i: Search for event on sentry.io');
final response = await client.get(
url,
headers: <String, String>{'Authorization': 'Bearer $_token'},
);
print('Response: ${response.statusCode}: ${response.body}');
if (response.statusCode == 200) {
// The json does not match what `SentryEvent.fromJson` expects
return jsonDecode(utf8.decode(response.bodyBytes));
}
await Future.delayed(const Duration(seconds: 15));
}
return null;
}

Uri _eventUri(SentryId id) {
// https://docs.sentry.io/api/events/retrieve-an-event-for-a-project/
return Uri.parse(
'https://sentry.io/api/0/projects/$_org/$_projectSlug/events/$id/',
);
}

0 comments on commit 20c2d7e

Please sign in to comment.