Skip to content
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

Take screenshot on failure option #534

Open
mateuszwojtczak opened this issue Oct 28, 2022 · 7 comments
Open

Take screenshot on failure option #534

mateuszwojtczak opened this issue Oct 28, 2022 · 7 comments
Labels
feature New feature request package: patrol Related to the patrol package (native automation, test bundling)

Comments

@mateuszwojtczak
Copy link
Contributor

mateuszwojtczak commented Oct 28, 2022

Let's consider an option that defaults to taking screenshots after any failures.

@bartekpacia
Copy link
Contributor

@bartekpacia
Copy link
Contributor

bartekpacia commented Nov 14, 2022

Status

Image

Screenshot on failure example (1)

Code

import 'package:example/main.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:patrol/patrol.dart';

import 'config.dart';

Future<void> main() async {
  late PatrolTester tester;

  patrolTest(
    'takes a screenshot after failed expect',
    config: patrolConfig,
    nativeAutomation: true,
    ($) async {
      tester = $;
      await $.pumpWidgetAndSettle(ExampleApp());

      expect('0', '1');
    },
  );

  tearDown(() async {
    await tester.host.takeScreenshot(name: 'after_failed_assertion');
  });
}

Screenshot

Image

Screenshot on failure example (2)

I like this better.

Code

import 'package:example/main.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:patrol/patrol.dart';

import 'config.dart';

Future<void> main() async {
  patrolTest(
    'takes a screenshot after failed expect',
    config: patrolConfig,
    nativeAutomation: true,
    ($) async {
      addTearDown(() async {
        await $.host.takeScreenshot(name: 'after_failed_assertion');
      });

      await $.pumpWidgetAndSettle(ExampleApp());
      await $('Add').tap(); // increments counter by 10

      expect($('11'), findsOneWidget);
    },
  );
}

Screenshot

Image

@bartekpacia
Copy link
Contributor

bartekpacia commented Nov 14, 2022

Update: the below is fixed, see #593

Problem

Oops, we've got a serious problem – after an hour of searching, I can't find any way to do reverse port forwarding on physical iOS devices.

I've assumed it's not gonna be a problem because we have the iproxy program, which can forward port 2000 on my mac to port 3000 on my iPhone by doing:

$ iproxy 2000 3000

but apparently, iproxy can't forward port 3000 on my iPhone to port 2000 on my mac.

This makes it impossible to use any host features (such as taking screenshots, executing scripts, etc.) from withing a test running on a physical iOS device. Android and iOS simulator work very nicely.

@bartekpacia
Copy link
Contributor

todo: check if we can take screenshot only test failed

@bartekpacia
Copy link
Contributor

I couldn't find a way to execute code only if a particular test case failed.

@bartekpacia
Copy link
Contributor

We tried to refine this today, but realized we don't know what the requirements are.

@jBorkowska jBorkowska added the feature New feature request label Jul 12, 2023
@bartekpacia bartekpacia added the package: patrol Related to the patrol package (native automation, test bundling) label Nov 17, 2023
@suside
Copy link

suside commented Sep 26, 2024

It's worth noting that there is native support for this with flutter drive --screenshot=path/to/dir ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request package: patrol Related to the patrol package (native automation, test bundling)
Projects
None yet
Development

No branches or pull requests

4 participants