@@ -24,31 +24,31 @@ set up the configuration and you are ready to describe actions and assertions of
2424## Table of Contents
2525
2626<!-- TOC -->
27- * [ Table of Contents] ( #table-of-contents )
28- * [ -- Features] ( #---features )
29- * [ -- Getting started] ( #---getting-started )
27+ * [ Table of Contents] ( #table-of-contents )
28+ * [ -- Features] ( #---features )
29+ * [ -- Getting started] ( #---getting-started )
3030 * [ 🥒 Add ` gherkin_widget_extension ` dependency] ( #-add-gherkin_widget_extension-dependency )
3131 * [ ✏️ Write a scenario] ( #%EF%B8%8F-write-a-scenario )
3232 * [ 🔗 Declare step definitions] ( #-declare-step-definitions )
3333 * [ ⚙️ Add some configuration] ( #%EF%B8%8F-add-some-configuration )
34- * [ Package distinctive features] ( #package-distinctive-features )
35- * [ ` ..hooks ` ] ( #hooks )
36- * [ ` ..reporters ` ] ( #reporters )
34+ * [ Package distinctive features] ( #package-distinctive-features )
35+ * [ ` ..hooks ` ] ( #hooks )
36+ * [ ` ..reporters ` ] ( #reporters )
3737 * [ 🧪 Set up the test runner] ( #-set-up-the-test-runner )
3838 * [ 🪄 Run your tests] ( #-run-your-tests )
3939 * [ 🎬️ Let's go!] ( #%EF%B8%8F-lets-go )
40- * [ -- Usage] ( #---usage )
40+ * [ -- Usage] ( #---usage )
4141 * [ 🌎 ` WidgetCucumberWorld ` advantages] ( #-widgetcucumberworld-advantages )
4242 * [ 🪣 Buckets for data] ( #-buckets-for-data )
4343 * [ 👁️ Don't forget the accessibility] ( #%EF%B8%8F-dont-forget-the-accessibility )
4444 * [ 🔄 Loading data for widgets with ` JsonLoader ` ] ( #-loading-data-for-widgets-with-jsonloader )
4545 * [ 📸 A Hook for screenshot and widget tree rendering] ( #-a-hook-for-screenshot-and-widget-tree-rendering )
4646 * [ 📋 Widget test reporters] ( #-widget-test-reporters )
47- * [ ` MonochromePrinter ` ] ( #monochromeprinter )
48- * [ ` WidgetStdoutReporter ` ] ( #widgetstdoutreporter )
49- * [ ` WidgetTestRunSummaryReporter ` ] ( #widgettestrunsummaryreporter )
50- * [ ` XmlReporter ` ] ( #xmlreporter )
51- * [ Add reporters in test configuration] ( #add-reporters-in-test-configuration )
47+ * [ ` MonochromePrinter ` ] ( #monochromeprinter )
48+ * [ ` WidgetStdoutReporter ` ] ( #widgetstdoutreporter )
49+ * [ ` WidgetTestRunSummaryReporter ` ] ( #widgettestrunsummaryreporter )
50+ * [ ` XmlReporter ` ] ( #xmlreporter )
51+ * [ Add reporters in test configuration] ( #add-reporters-in-test-configuration )
5252<!-- TOC -->
5353
5454***
@@ -102,8 +102,10 @@ Next step: implementation of step definitions.
102102
103103# ## 🔗 Declare step definitions
104104
105- Step definitions are like links between the gherkin sentence and the code that interacts with the widget. Usually `given`
106- steps are used to set up the test context, `when` step(s) represents the main action of the test (When the user validates
105+ Step definitions are like links between the gherkin sentence and the code that interacts with the widget.
106+ Usually `given`
107+ steps are used to set up the test context, `when` step(s) represents the main action of the test (When the user
108+ validates
107109the form, When the user applies his choice, ...) and the `then` steps assert everything assertable on the screen
108110(text, state, semantics, ...).
109111
@@ -184,7 +186,7 @@ More information [here](#-widget-test-reporters).
184186
185187# ## 🧪 Set up the test runner
186188
187- Create a new file `widget_test_runner.dart` in `test` folder and call the test runner method :
189+ Create a new file `widget_test_runner.dart` in the `test` folder and call the test runner method :
188190
189191` ` ` dart
190192void main() {
@@ -193,6 +195,16 @@ void main() {
193195}
194196` ` `
195197
198+ Create another file named `flutter_test_config.dart` in the `test` folder and declare the test executing configuration
199+ to enable font loading _(required for screenshots)_ :
200+
201+ ` ` ` dart
202+ Future<void> testExecutable(FutureOr<void> Function() testMain) async {
203+ await loadAppFonts();
204+ await testMain();
205+ }
206+ ` ` `
207+
196208# ## 🪄 Run your tests
197209
198210Open a terminal and execute the file you created before :
@@ -274,32 +286,35 @@ Keep in mind that bucket type is required to use it and access to its data (here
274286# ## 👁️ Don't forget the accessibility
275287
276288Accessibility is essential in mobile application and must be tested as well. This package provides a method to test
277- widget semantics :
289+ widget semantics :
278290
279291` ` ` dart
280292Finder widgetWithSemanticLabel(
281- Type widgetType,
282- String semanticLabel,
283- {bool skipOffstage = true,
284- Matcher? semanticMatcher}
293+ Type widgetType,
294+ String semanticLabel,
295+ {bool skipOffstage = true,
296+ Matcher? semanticMatcher}
285297)
286298` ` `
287299
288300This method allows you to find a widget by its type, its semantic label and its full semantics :
301+
289302` ` ` dart
303+
290304final widgetToFind = find.widgetWithSemanticLabel(Checkbox, "Checkbox label",
291- semanticMatcher: matchesSemantics(
292- hasEnabledState: true,
293- label: "Checkbox label",
294- hasTapAction: true,
295- isEnabled: true,
296- isFocusable: true,
297- textDirection: TextDirection.ltr,
298- hasCheckedState: true,
299- isChecked: true));
300-
301- expect(widgetToFind, findsOneWidget);
305+ semanticMatcher: matchesSemantics(
306+ hasEnabledState: true,
307+ label: "Checkbox label",
308+ hasTapAction: true,
309+ isEnabled: true,
310+ isFocusable: true,
311+ textDirection: TextDirection.ltr,
312+ hasCheckedState: true,
313+ isChecked: true));
314+
315+ expect(widgetToFind, findsOneWidget);
302316` ` `
317+
303318The `expect` raises an `AssertionError` if no corresponding widget exists.
304319
305320# ## 🔄 Loading data for widgets with `JsonLoader`
@@ -314,9 +329,14 @@ var jsonMap = await JsonLoader.loadJson("path/to/json/folder");
314329` ` `
315330` jsonMap` contains a map where keys are json filenames and values the json files content.
316331
317-
318332# ## 📸 A Hook for screenshot and widget tree rendering
319333
334+ > 📣 At least one font must be declared in the `pubspec.yml` to have nice and understandable screenshots (Squares will
335+ > replace fonts otherwise).
336+ >
337+ > 📣 The `flutter_test_config.dart` must exist at the root of `test` directory (
338+ > See [🧪 Set up the test runner](#-set-up-the-test-runner) paragraph).
339+
320340Hooks contain methods executed before or after specific milestones during a test driven by Cucumber (before/after scenario,
321341before/after steps, ...). More information about Hooks [here](https://pub.dev/packages/gherkin#hooks).
322342
@@ -328,7 +348,8 @@ TestConfiguration()
328348..hooks = [WidgetHooks(dumpFolderPath: 'widget_tests_report_folder')]
329349` ` `
330350
331- **Parameter `dumpFolderPath` is mandatory**: it represents the report folder where screenshots and widget rendering will be
351+ **Parameter `dumpFolderPath` is mandatory**: it represents the report folder where screenshots and widget rendering will
352+ be
332353stored on test failure.
333354
334355> 📣 This package provides a custom Widget called `MaterialTestWidget`. This widget must encapsulate the widget to pump
@@ -347,6 +368,7 @@ to print your message in the log console without any decorations/emojis/whatever
347368# ### `WidgetStdoutReporter`
348369
349370This reporter is in charge of :
371+
350372* printing the name of the running scenario with its file location,
351373* printing each step with its status and time duration
352374 * `√` if step succeeded
@@ -396,14 +418,15 @@ On failure, a link to the screenshot is also provided.
396418> Report [here](https://docs.gitlab.com/ee/ci/testing/unit_test_reports.html).
397419
398420# ### Add reporters in test configuration
421+
399422To benefit from supplied reporters, they need to be added on the `TestConfiguration` :
400423` ` ` dart
401424TestConfiguration()
402- ..reporters = [
403- WidgetStdoutReporter(),
404- WidgetTestRunSummaryReporter(),
405- XmlReporter(dirRoot: Directory.current.path)
406- ]
425+ ..reporters = [
426+ WidgetStdoutReporter(),
427+ WidgetTestRunSummaryReporter(),
428+ XmlReporter(dirRoot: Directory.current.path)
429+ ]
407430` ` `
408431
409432<!--
0 commit comments